MCPcopy Create free account
hub / github.com/ActiveState/code / min_cut_phase

Function min_cut_phase

recipes/Python/576907_Minimum_Cut_Solver/recipe-576907.py:129–142  ·  view source on GitHub ↗
(g, a)

Source from the content-addressed store, hash-verified

127 return sum(w for v, w in g.adjacents(y) if v in A)
128
129def min_cut_phase(g, a):
130 A = set([a])
131 V = set(g.vertices)
132 order = [a]
133 while A != V:
134 w_candidates = [(w(g, A, v), v) for v in V-A] #: candidates for most tightly connected
135 _, x = max(w_candidates)
136 A.add(x)
137 order.append(x)
138 t, s = order[-1], order[-2]
139
140 min_cut = sum(w for v, w in g.adjacents(t))
141 g.merge(t, s)
142 return min_cut
143
144def minimum_cut(g, a):
145 min_cut = sum(w for v, w in g.adjacents(a))

Callers 1

minimum_cutFunction · 0.85

Calls 8

wFunction · 0.85
setFunction · 0.50
maxFunction · 0.50
sumFunction · 0.50
addMethod · 0.45
appendMethod · 0.45
adjacentsMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected