Fix subG
parent
0dc65f09b2
commit
e369ccbf19
|
@ -42,7 +42,7 @@ def stoer_wagner(adj):
|
|||
take[best] = True
|
||||
return best_cut_weight, best_cut
|
||||
|
||||
def stoer_wagner_nx(graph, weight = 'weight', heap = None):
|
||||
def stoer_wagner_nx(graph, weight = 'weight'):
|
||||
nodes = graph.nodes()
|
||||
d = {}
|
||||
for i in range(len(nodes)):
|
||||
|
|
|
@ -37,8 +37,7 @@ def subG(G, x, extToEdge):
|
|||
subG = nx.Graph()
|
||||
for (d, a) in G.edges():
|
||||
if(x[ extToEdge[(d, a)] ] != 0):
|
||||
subG.add_edge(d, a, weight = G[d][a]['weight'] * x[ extToEdge[(d, a)] ])
|
||||
|
||||
subG.add_edge(d, a, weight = max(0.,x[ extToEdge[(d, a)] ]))
|
||||
return subG
|
||||
|
||||
def addSubTour(A_ub, b_ub, G, cut, extToEdge):
|
||||
|
@ -105,7 +104,7 @@ def separation(Adj):
|
|||
else:
|
||||
cutV, cut = stoer_wagner_nx(sG)
|
||||
print(cutV, cut)
|
||||
if(cutV >= 2):
|
||||
if(cutV >= 2-eps):
|
||||
break
|
||||
addSubTour(A_ub, b_ub, G, cut, extToEdge)
|
||||
|
||||
|
@ -114,5 +113,4 @@ def separation(Adj):
|
|||
|
||||
n += 1
|
||||
|
||||
|
||||
return x, res.fun
|
||||
|
|
|
@ -35,7 +35,7 @@ def subG(G, x, extToEdge):
|
|||
for (d, a) in G.edges():
|
||||
if (d,a) in extToEdge:
|
||||
if(x[ extToEdge[(d, a)] ] != 0):
|
||||
subG.add_edge(d, a, weight = G[d][a]['weight'] * x[ extToEdge[(d, a)] ])
|
||||
subG.add_edge(d, a, weight = x[ extToEdge[(d, a)] ])
|
||||
|
||||
return subG
|
||||
|
||||
|
@ -206,7 +206,7 @@ class LinearDualTSP(object):
|
|||
else:
|
||||
cutV, cut = stoer_wagner_nx(sG)
|
||||
print(cutV, cut)
|
||||
if(cutV >= 2):
|
||||
if(cutV >= 2-eps):
|
||||
break
|
||||
self.add_cut(cut)
|
||||
n += 1
|
||||
|
|
Loading…
Reference in New Issue