Ejemplo n.º 1
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)]))
Ejemplo n.º 2
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)]))
Ejemplo n.º 3
0
def test_bidirectional_weighted_shortest_simple_path():
    def cost_func(path):
        return sum(G.edge[u][v]['weight'] for (u, v) in zip(path, path[1:]))
    G = nx.complete_graph(5)
    weight = {(u, v): random.randint(1, 100) for (u, v) in G.edges()}
    nx.set_edge_attributes(G, 'weight', weight)
    cost = 0
    for path in nx.bidirectional_all_shortest_paths(G, 0, 3):
        this_cost = cost_func(path)
        assert_true(cost <= this_cost)
        cost = this_cost
Ejemplo n.º 4
0
def test_bidirectional_weighted_shortest_simple_path():
    def cost_func(path):
        return sum(G.edge[u][v]['weight'] for (u, v) in zip(path, path[1:]))

    G = nx.complete_graph(5)
    weight = {(u, v): random.randint(1, 100) for (u, v) in G.edges()}
    nx.set_edge_attributes(G, 'weight', weight)
    cost = 0
    for path in nx.bidirectional_all_shortest_paths(G, 0, 3):
        this_cost = cost_func(path)
        assert_true(cost <= this_cost)
        cost = this_cost
Ejemplo n.º 5
0
def test_bidirectional_ssp_target_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_shortest_paths(G, 1, 4))
Ejemplo n.º 6
0
def test_bidirectional_ssp_source_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_shortest_paths(G, 0, 3))
Ejemplo n.º 7
0
def test_bidirectional_shortest_simple_paths_directed():
    G = nx.cycle_graph(7, create_using=nx.DiGraph())
    paths = nx.bidirectional_all_shortest_paths(G, 0, 3)
    assert_equal([path for path in paths], [[0, 1, 2, 3]])
Ejemplo n.º 8
0
def test_bidirectional_ssp_target_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_shortest_paths(G, 1, 4))
Ejemplo n.º 9
0
def test_bidirectional_ssp_source_missing():
    G = nx.Graph()
    G.add_path([1, 2, 3])
    paths = list(nx.bidirectional_all_shortest_paths(G, 0, 3))
Ejemplo n.º 10
0
def test_bidirectional_shortest_simple_paths_directed():
    G = nx.cycle_graph(7, create_using=nx.DiGraph())
    paths = nx.bidirectional_all_shortest_paths(G, 0, 3)
    assert_equal([path for path in paths], [[0, 1, 2, 3]])