Exemple #1
0
def test_three_components_mgd_2():
    G = nx.Graph()
    # First triad
    G.add_edges_from([(1, 2), (2, 3), (3, 1)])
    # Second triad
    G.add_edges_from([(4, 5), (5, 6), (6, 4)])
    G.add_edge(9, 10)
    num_distances, sum_distances = ss.all_pairs_shortest_paths_rolling_sum(G)
    dist = apsp_multi_component(networkx_to_igraph(G))
    assert sum_distances/num_distances == sum([k*v for k, v in dist.items()])/sum([v for _, v in dist.items()])
Exemple #2
0
def test_zkc_mgd():
    G = nx.karate_club_graph()
    num_distances, sum_distances = ss.all_pairs_shortest_paths_rolling_sum(G)
    dist = apsp_multi_component(networkx_to_igraph(G))
    assert sum_distances/num_distances == sum([k*v for k, v in dist.items()])/sum([v for _, v in dist.items()])
Exemple #3
0
def test_singleton_mgd():
    g = igraph.Graph()
    g.add_vertices(1)
    assert apsp_multi_component(g) == {0.0: 1}  # convention
Exemple #4
0
def test_single_edge_mgd():
    g = igraph.Graph()
    g.add_vertices(2)
    g.add_edge(0, 1)
    assert apsp_multi_component(g) == {0.0: 2, 1.0: 2}
Exemple #5
0
def test_empty_mgd():
    g = igraph.Graph()
    assert apsp_multi_component(g) == {0.0: 1} # convention