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