Exemplo n.º 1
0
 def test_null_graph(self):
     G = nx.DiGraph()
     assert_equal(list(nx.strongly_connected_components(G)), [])
     assert_equal(list(nx.kosaraju_strongly_connected_components(G)), [])
     assert_equal(list(nx.strongly_connected_components_recursive(G)), [])
     assert_equal(len(nx.condensation(G)), 0)
     assert_raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph())
Exemplo n.º 2
0
 def test_null_graph(self):
     G = nx.DiGraph()
     assert list(nx.strongly_connected_components(G)) == []
     assert list(nx.kosaraju_strongly_connected_components(G)) == []
     assert list(nx.strongly_connected_components_recursive(G)) == []
     assert len(nx.condensation(G)) == 0
     pytest.raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected, nx.DiGraph())
Exemplo n.º 3
0
 def test_connected_raise(self):
     G = nx.Graph()
     with pytest.raises(NetworkXNotImplemented):
         next(nx.strongly_connected_components(G))
     with pytest.raises(NetworkXNotImplemented):
         next(nx.kosaraju_strongly_connected_components(G))
     with pytest.raises(NetworkXNotImplemented):
         next(nx.strongly_connected_components_recursive(G))
     pytest.raises(NetworkXNotImplemented, nx.is_strongly_connected, G)
     pytest.raises(nx.NetworkXPointlessConcept, nx.is_strongly_connected,
                   nx.DiGraph())
     pytest.raises(NetworkXNotImplemented, nx.condensation, G)
Exemplo n.º 4
0
nx.betweenness_centrality(G)
nx.closeness_centrality(G)
nx.eigenvector_centrality(G)

# clique
#list(nx.find_cliques(G))
#list(nx.make_max_clique_graph(G))
#list(nx.make_clique_bipartite(G))
#nx.graph_clique_number(G)
#nx.graph_number_of_cliques(G)

# components
nx.is_strongly_connected(G)
nx.number_strongly_connected_components(G)
scc = nx.strongly_connected_components(G)
nx.strongly_connected_components_recursive(G)
nx.condensation(G, scc)

# attracting components
nx.is_attracting_component(G)
nx.number_attracting_components(G)
nx.attracting_components(G)

# directed acyclic graphs
nx.is_directed_acyclic_graph(G)
nx.is_aperiodic(G)

# distance measure  (all for connected graph)
nx.center(Gcc)
nx.diameter(Gcc)
nx.eccentricity(Gcc)
Exemplo n.º 5
0
    cnt = 0
    stack = []
    for source in G:
        print("_________________")
        print("source:", source)
        print("Visited:", visited)
        print("Component:", component)
        print("root", root)
        print("cnt:", cnt)
        print("stack:", stack)
        print("_________________")
        if source not in visited:
            print("not")
            yield from visit(source, cnt)


G = nx.DiGraph()
G.add_edges_from([(1, 3), (2, 1), (3, 2), (3, 4), (4, 5), (5, 6), (6, 7),
                  (7, 8), (8, 5)])

lensccs = [
    len(c) for c in sorted(
        strongly_connected_components_recursive(G), key=len, reverse=True)
]
sccs = [
    tuple(sorted(c)) for c in nx.strongly_connected_components_recursive(G)
]
print(lensccs)
print(sccs)
print(strongly_connected_components_recursive(G))
Exemplo n.º 6
0
nx.betweenness_centrality(G)
nx.closeness_centrality(G)
nx.eigenvector_centrality(G)

# clique
#list(nx.find_cliques(G))
#list(nx.make_max_clique_graph(G))
#list(nx.make_clique_bipartite(G))
#nx.graph_clique_number(G)
#nx.graph_number_of_cliques(G)

# components
nx.is_strongly_connected(G)
nx.number_strongly_connected_components(G)
scc = nx.strongly_connected_components(G)
nx.strongly_connected_components_recursive(G)
nx.condensation(G, scc)

# attracting components
nx.is_attracting_component(G)
nx.number_attracting_components(G)
nx.attracting_components(G)

# directed acyclic graphs
nx.is_directed_acyclic_graph(G)
nx.is_aperiodic(G)

# distance measure  (all for connected graph)
nx.center(Gcc)
nx.diameter(Gcc)
nx.eccentricity(Gcc)