예제 #1
0
def test_bidirectional_weight_name():
    G = nx.cycle_graph(7)
    nx.set_edge_attributes(G, 'weight', 1)
    nx.set_edge_attributes(G, 'foo', 1)
    G.edge[1][2]['foo'] = 7
    paths = list(nx.bidirectional_all_simple_paths(G, 0, 3))
    solution = [[0, 1, 2, 3], [0, 6, 5, 4, 3]]
    assert_equal(paths, solution)
예제 #2
0
def test_bidirectional_weight_name():
    G = nx.cycle_graph(7)
    nx.set_edge_attributes(G, 'weight', 1)
    nx.set_edge_attributes(G, 'foo', 1)
    G.edge[1][2]['foo'] = 7
    paths = list(nx.bidirectional_all_simple_paths(G, 0, 3))
    solution = [[0, 1, 2, 3], [0, 6, 5, 4, 3]]
    assert_equal(paths, solution)
예제 #3
0
def test_bidirectional_shortest_simple_paths():
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.bidirectional_all_shortest_paths(G, 1, 12)
    assert_equal(next(paths), [1, 5, 6, 10, 11, 12])
    assert_equal(next(paths), [1, 5, 6, 7, 8, 12])
    assert_equal(
        [len(path) for path in nx.bidirectional_all_simple_paths(G, 1, 12)],
        sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
예제 #4
0
def test_bidirectional_shortest_simple_paths():
    G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
    paths = nx.bidirectional_all_shortest_paths(G, 1, 12)
    assert_equal(next(paths), [1, 5, 6, 10, 11, 12])
    assert_equal(next(paths), [1, 5, 6, 7, 8, 12])
    assert_equal(
        [len(path) for path in nx.bidirectional_all_simple_paths(G, 1, 12)],
        sorted([len(path) for path in nx.all_simple_paths(G, 1, 12)]))
예제 #5
0
def test_bidirectional_target_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 1, 4))
예제 #6
0
def test_bidirectional_source_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3))
예제 #7
0
def test_bidirectional_cutoff_zero():
    G = nx.complete_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=0)
    assert_equal(list(list(p) for p in paths), [])
    paths = nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3, cutoff=0)
    assert_equal(list(list(p) for p in paths), [])
예제 #8
0
def test_bidirectional_all_simple_paths_empty():
    G = nx.path_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=2)
    assert_equal(list(list(p) for p in paths), [])
예제 #9
0
def test_bidirectional_all_simple_paths_directed():
    G = nx.DiGraph()
    G.add_path([1, 2, 3])
    G.add_path([3, 2, 1])
    paths = nx.bidirectional_all_simple_paths(G, 1, 3)
    assert_equal(list(list(p) for p in paths), [[1, 2, 3]])
예제 #10
0
def test_bidirectional_all_simple_paths_multigraph_with_cutoff():
    G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)])
    paths = nx.bidirectional_all_simple_paths(G, 1, 2, cutoff=1)
    assert_equal(list(list(p) for p in paths), [[1, 2], [1, 2]])
예제 #11
0
def test_bidirectional_all_simple_paths_cutoff():
    G = nx.complete_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=1)
    assert_equal(list(list(p) for p in paths), [[0, 1]])
    paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=2)
    assert_equal(list(list(p) for p in paths), [[0, 1], [0, 2, 1], [0, 3, 1]])
예제 #12
0
def test_bidirectional_all_simple_paths_cutoff():
    G = nx.complete_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=1)
    assert_equal(list(list(p) for p in paths), [[0, 1]])
    paths = nx.bidirectional_all_simple_paths(G, 0, 1, cutoff=2)
    assert_equal(list(list(p) for p in paths), [[0, 1], [0, 2, 1], [0, 3, 1]])
예제 #13
0
def test_bidirectional_target_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 1, 4))
예제 #14
0
def test_bidirectional_source_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3))
예제 #15
0
def test_bidirectional_cutoff_zero():
    G = nx.complete_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=0)
    assert_equal(list(list(p) for p in paths), [])
    paths = nx.bidirectional_all_simple_paths(nx.MultiGraph(G), 0, 3, cutoff=0)
    assert_equal(list(list(p) for p in paths), [])
예제 #16
0
def test_bidirectional_all_simple_paths_empty():
    G = nx.path_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3, cutoff=2)
    assert_equal(list(list(p) for p in paths), [])
예제 #17
0
def test_bidirectional_all_simple_paths_directed():
    G = nx.DiGraph()
    G.add_path([1, 2, 3])
    G.add_path([3, 2, 1])
    paths = nx.bidirectional_all_simple_paths(G, 1, 3)
    assert_equal(list(list(p) for p in paths), [[1, 2, 3]])
예제 #18
0
def test_bidirectional_all_simple_paths_multigraph_with_cutoff():
    G = nx.MultiGraph([(1, 2), (1, 2), (1, 10), (10, 2)])
    paths = nx.bidirectional_all_simple_paths(G, 1, 2, cutoff=1)
    assert_equal(list(list(p) for p in paths), [[1, 2], [1, 2]])
예제 #19
0
def test_bidirectional_all_simple_paths():
    G = nx.path_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3)
    assert_equal(list(list(p) for p in paths), [[0, 1, 2, 3]])
예제 #20
0
def test_bidirectional_all_simple_paths():
    G = nx.path_graph(4)
    paths = nx.bidirectional_all_simple_paths(G, 0, 3)
    assert_equal(list(list(p) for p in paths), [[0, 1, 2, 3]])