Skip to content

Commit

Permalink
Add test for two-phase shortest augmenting path maxflow algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
ysitu committed Apr 7, 2014
1 parent 42a6beb commit 6f01f08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion networkx/algorithms/flow/shortest_augmenting_path.py
Expand Up @@ -89,7 +89,7 @@ def relabel(u):
path = [s]
u = s
d = n if not two_phase else int(min(m ** 0.5, 2 * n ** (2. / 3)))
done = R.node[s]['height'] < d
done = R.node[s]['height'] >= d
while not done:
height = R.node[u]['height']
curr_edge = R.node[u]['curr_edge']
Expand Down
13 changes: 13 additions & 0 deletions networkx/algorithms/flow/tests/test_maxflow.py
Expand Up @@ -322,3 +322,16 @@ def test_preflow_push_global_relabel_freq(self):
assert_equal(nx.preflow_push(G, 1, 2, global_relabel_freq=None)[0], 1)
assert_raises(nx.NetworkXError, nx.preflow_push_value, G, 1, 2,
global_relabel_freq=-1)

def test_shortest_augmenting_path_two_phase(self):
k = 5
p = 1000
G = nx.DiGraph()
for i in range(k):
G.add_edge('s', (i, 0), capacity=1)
G.add_path(((i, j) for j in range(p)), capacity=1)
G.add_edge((i, p - 1), 't', capacity=1)
assert_equal(nx.shortest_augmenting_path_value(
G, 's', 't', two_phase=True), k)
assert_equal(nx.shortest_augmenting_path_value(
G, 's', 't', two_phase=False), k)

0 comments on commit 6f01f08

Please sign in to comment.