コード例 #1
0
 def test_complete_graph(self):
     N = 50
     G = nx.complete_graph(N)
     for (u, v) in G.edges():
         G[u][v]['capacity'] = 5
     assert_equal(nx.ford_fulkerson(G, 1, 2)[0], 5 * (N - 1))
     assert_equal(nx.preflow_push(G, 1, 2)[0], 5 * (N - 1))
コード例 #2
0
ファイル: test_maxflow.py プロジェクト: alis0nc/networkx
def test_preflow_push_global_relabel_freq():
    G = nx.DiGraph()
    G.add_edge(1, 2, capacity=1)
    R = nx.preflow_push(G, 1, 2, global_relabel_freq=None)
    assert_equal(R.graph['flow_value'], 1)
    assert_raises(nx.NetworkXError, preflow_push, G, 1, 2,
                  global_relabel_freq=-1)
コード例 #3
0
 def _test_graph(self, G, s, t, soln, pred=assert_equal):
     validate = partial(validate_flows, G, s, t, soln, pred=pred)
     #validate(*nx.ford_fulkerson(G, s, t))
     validate(*nx.edmonds_karp(G, s, t))
     validate(*nx.preflow_push(G, s, t))
     validate(*nx.shortest_augmenting_path(G, s, t, two_phase=False))
     validate(*nx.shortest_augmenting_path(G, s, t, two_phase=True))
コード例 #4
0
 def _test_graph(self, G, s, t, soln, pred=assert_equal):
     validate = partial(validate_flows, G, s, t, soln, pred=pred)
     #validate(*nx.ford_fulkerson(G, s, t))
     validate(*nx.edmonds_karp(G, s, t))
     validate(*nx.preflow_push(G, s, t))
     validate(*nx.shortest_augmenting_path(G, s, t, two_phase=False))
     validate(*nx.shortest_augmenting_path(G, s, t, two_phase=True))
コード例 #5
0
 def test_preflow_push_global_relabel_freq(self):
     G = nx.DiGraph()
     G.add_edge(1, 2, capacity=1)
     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)
コード例 #6
0
    def test_pyramid(self):
        N = 10
#        N = 100 # this gives a graph with 5051 nodes
        G = gen_pyramid(N)
        assert_almost_equal(nx.ford_fulkerson(G, (0, 0), 't')[0], 1.)
        assert_almost_equal(nx.preflow_push(G, (0, 0), 't')[0], 1.)
        assert_almost_equal(nx.shortest_augmenting_path(
            G, (0, 0), 't', two_phase=False)[0], 1.)
        assert_almost_equal(nx.shortest_augmenting_path(
            G, (0, 0), 't', two_phase=True)[0], 1.)
コード例 #7
0
ファイル: test_maxflow.py プロジェクト: CipherHat/networkx
def compare_flows(G, s, t, solnFlows, solnValue, capacity = 'capacity'):
    flowValue, flowDict = nx.ford_fulkerson(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    assert_equal(flowDict, solnFlows)
    flowValue, flowDict = nx.preflow_push(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    assert_equal(nx.min_cut(G, s, t, capacity), solnValue)
    assert_equal(nx.max_flow(G, s, t, capacity), solnValue)
    assert_equal(nx.ford_fulkerson_flow(G, s, t, capacity), solnFlows)
コード例 #8
0
 def test_complete_graph(self):
     N = 50
     G = nx.complete_graph(N)
     for (u, v) in G.edges():
         G[u][v]['capacity'] = 5
     assert_equal(nx.ford_fulkerson(G, 1, 2)[0], 5 * (N - 1))
     assert_equal(nx.preflow_push(G, 1, 2)[0], 5 * (N - 1))
     assert_equal(nx.shortest_augmenting_path(G, 1, 2, two_phase=False)[0],
                  5 * (N - 1))
     assert_equal(nx.shortest_augmenting_path(G, 1, 2, two_phase=True)[0],
                  5 * (N - 1))
コード例 #9
0
ファイル: test_maxflow.py プロジェクト: tempcyc/networkx
def test_preflow_push_global_relabel_freq():
    G = nx.DiGraph()
    G.add_edge(1, 2, capacity=1)
    R = nx.preflow_push(G, 1, 2, global_relabel_freq=None)
    assert_equal(R.graph['flow_value'], 1)
    assert_raises(nx.NetworkXError,
                  preflow_push,
                  G,
                  1,
                  2,
                  global_relabel_freq=-1)
コード例 #10
0
def compare_flows(G, s, t, solnFlows, solnValue, capacity = 'capacity'):
    flowValue, flowDict = nx.ford_fulkerson(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    assert_equal(flowDict, solnFlows)
    flowValue, flowDict = nx.preflow_push(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    flowValue, flowDict = nx.shortest_augmenting_path(G, s, t, capacity,
                                                      two_phase=False)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    flowValue, flowDict = nx.shortest_augmenting_path(G, s, t, capacity,
                                                      two_phase=True)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    assert_equal(nx.min_cut(G, s, t, capacity), solnValue)
    assert_equal(nx.max_flow(G, s, t, capacity), solnValue)
    assert_equal(nx.ford_fulkerson_flow(G, s, t, capacity), solnFlows)
コード例 #11
0
def compare_flows(G, s, t, solnFlows, solnValue, capacity='capacity'):
    flowValue, flowDict = nx.ford_fulkerson(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    assert_equal(flowDict, solnFlows)
    flowValue, flowDict = nx.preflow_push(G, s, t, capacity)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    flowValue, flowDict = nx.shortest_augmenting_path(G,
                                                      s,
                                                      t,
                                                      capacity,
                                                      two_phase=False)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    flowValue, flowDict = nx.shortest_augmenting_path(G,
                                                      s,
                                                      t,
                                                      capacity,
                                                      two_phase=True)
    assert_equal(flowValue, solnValue)
    validate_flows(G, s, t, flowDict, solnValue, capacity)
    assert_equal(nx.min_cut(G, s, t, capacity), solnValue)
    assert_equal(nx.max_flow(G, s, t, capacity), solnValue)
    assert_equal(nx.ford_fulkerson_flow(G, s, t, capacity), solnFlows)
コード例 #12
0
 def test_preflow_push_global_relabel(self):
     G = read_graph('gw1')
     assert_equal(nx.preflow_push(G, 1, len(G), global_relabel_freq=50)[0],
                  1202018)
コード例 #13
0
 def test_preflow_push_global_relabel_freq(self):
     G = nx.DiGraph()
     G.add_edge(1, 2, capacity=1)
     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)
コード例 #14
0
    def test_pyramid(self):
        N = 10 
#        N = 100 # this gives a graph with 5051 nodes
        G = gen_pyramid(N)
        assert_almost_equal(nx.ford_fulkerson(G, (0, 0), 't')[0], 1.)
        assert_almost_equal(nx.preflow_push(G, (0, 0), 't')[0], 1.)
コード例 #15
0
 def test_preflow_push_global_relabel(self):
     G = read_graph('gw1')
     R = nx.preflow_push(G, 1, len(G), global_relabel_freq=50)
     assert_equal(R.graph['flow_value'], 1202018)
コード例 #16
0
 def test_preflow_push_global_relabel(self):
     G = read_graph('gw1')
     R = nx.preflow_push(G, 1, len(G), global_relabel_freq=50)
     assert_equal(R.graph['flow_value'], 1202018)