comparison env/lib/python3.9/site-packages/networkx/algorithms/components/semiconnected.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Semiconnectedness."""
2 import networkx as nx
3 from networkx.utils import not_implemented_for, pairwise
4
5 __all__ = ["is_semiconnected"]
6
7
8 @not_implemented_for("undirected")
9 def is_semiconnected(G, topo_order=None):
10 """Returns True if the graph is semiconnected, False otherwise.
11
12 A graph is semiconnected if, and only if, for any pair of nodes, either one
13 is reachable from the other, or they are mutually reachable.
14
15 Parameters
16 ----------
17 G : NetworkX graph
18 A directed graph.
19
20 topo_order: list or tuple, optional
21 A topological order for G (if None, the function will compute one)
22
23 Returns
24 -------
25 semiconnected : bool
26 True if the graph is semiconnected, False otherwise.
27
28 Raises
29 ------
30 NetworkXNotImplemented
31 If the input graph is undirected.
32
33 NetworkXPointlessConcept
34 If the graph is empty.
35
36 Examples
37 --------
38 >>> G = nx.path_graph(4, create_using=nx.DiGraph())
39 >>> print(nx.is_semiconnected(G))
40 True
41 >>> G = nx.DiGraph([(1, 2), (3, 2)])
42 >>> print(nx.is_semiconnected(G))
43 False
44
45 See Also
46 --------
47 is_strongly_connected
48 is_weakly_connected
49 is_connected
50 is_biconnected
51 """
52 if len(G) == 0:
53 raise nx.NetworkXPointlessConcept(
54 "Connectivity is undefined for the null graph."
55 )
56
57 if not nx.is_weakly_connected(G):
58 return False
59
60 G = nx.condensation(G)
61 if topo_order is None:
62 topo_order = nx.topological_sort(G)
63
64 return all(G.has_edge(u, v) for u, v in pairwise(topo_order))