def run_test(G, expect):
N = G.shape[0]
clofunc = partial(clo.epclosuress, G, retpaths=True)
o, p = zip(*map(clofunc, xrange(N)))
o = np.round(o, 2)
# check capacities match
assert np.allclose(o, expect)
# check paths match with computed capacities
for s, t in np.ndindex(G.shape):
if (s == t) or G[s, t] > 0 or (o[s, t] == 0):
# path must be empty
assert len(p[s][t]) == 0
else:
# minimum on path must correspond to computed capacity
path = p[s][t]
weights = np.ravel(G[path[:-1], path[1:]])[:-1]
weights = np.round(weights, 2)
assert o[s, t] == np.min(weights)
评论列表
文章目录