Skip to content

Commit ad25ce0

Browse files
atomassiAndrea Tomassilli
authored andcommitted
updated cut value computation
1 parent 7175814 commit ad25ce0

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

networkx/algorithms/approximation/kcutsets.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ def minimum_multiway_cut(G, terminals, weight=None):
106106

107107
# discard the heaviest cut and take the union of the rest
108108
cutset = set()
109+
cut_value = 0
109110
for u, v in itertools.chain.from_iterable(
110111
el[0] for el in sorted(all_cuts, key=lambda x: x[1])[:-1]
111112
):
112113
if (u, v) not in cutset and (v, u) not in cutset:
114+
# add to the cutset
113115
cutset.add((u, v))
114-
115-
# compute the cut value
116-
cut_value = sum(G2.edges[u, v]["capacity"] for u, v in cutset)
116+
# add the weight to the cut cost
117+
cut_value += G2.edges[u, v]["capacity"]
117118

118119
return cut_value, cutset
119120

@@ -221,10 +222,12 @@ def minimum_k_cut(G, k, weight=None):
221222

222223
# consider edges only in a direction
223224
cutset = set()
225+
cut_value = 0
224226
for u, v in all_edges_cut:
225227
if (u, v) not in cutset and (v, u) not in cutset:
228+
# add to the cutset
226229
cutset.add((u, v))
227-
# compute the cut_value
228-
cut_value = sum(G2.edges[u, v]["capacity"] for u, v in cutset)
230+
# add the weight to the cut cost
231+
cut_value += G2.edges[u, v]["capacity"]
229232

230233
return cut_value, cutset

0 commit comments

Comments
 (0)