a
HlX`xã@s\dZddlZddlmZgd¢Zedƒdd„ƒZedƒdd „ƒZedƒd
d„ƒZdd
„Z dS)zWeakly connected components.éN)Únot_implemented_for)Ú"number_weakly_connected_componentsÚweakly_connected_componentsÚis_weakly_connectedZ
undirectedccs:tƒ}|D]*}||vr
tt||ƒƒ}|V| |¡q
dS)aÚGenerate weakly connected components of G.
Parameters
----------
G : NetworkX graph
A directed graph
Returns
-------
comp : generator of sets
A generator of sets of nodes, one for each weakly connected
component of G.
Raises
------
NetworkXNotImplemented
If G is undirected.
Examples
--------
Generate a sorted list of weakly connected components, largest first.
>>> G = nx.path_graph(4, create_using=nx.DiGraph())
>>> nx.add_path(G, [10, 11, 12])
>>> [
... len(c)
... for c in sorted(nx.weakly_connected_components(G), key=len, reverse=True)
... ]
[4, 3]
If you only want the largest component, it's more efficient to
use max instead of sort:
>>> largest_cc = max(nx.weakly_connected_components(G), key=len)
See Also
--------
connected_components
strongly_connected_components
Notes
-----
For directed graphs only.
N)ÚsetÚ
_plain_bfsÚupdate)ÚGÚseenÚvÚc©r
ú—/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/lib/python3.9/site-packages/networkx/algorithms/components/weakly_connected.pyrs/rcCstdd„t|ƒDƒƒS)aéReturns the number of weakly connected components in G.
Parameters
----------
G : NetworkX graph
A directed graph.
Returns
-------
n : integer
Number of weakly connected components
Raises
------
NetworkXNotImplemented
If G is undirected.
See Also
--------
weakly_connected_components
number_connected_components
number_strongly_connected_components
Notes
-----
For directed graphs only.
css|]
}dVqdS)éNr
)Ú.0Zwccr
r
rÚ aóz5number_weakly_connected_components..)Úsumr©r r
r
rrCsrcCs2t|ƒdkrt d¡‚ttt|ƒƒdƒt|ƒkS)a7Test directed graph for weak connectivity.
A directed graph is weakly connected if and only if the graph
is connected when the direction of the edge between nodes is ignored.
Note that if a graph is strongly connected (i.e. the graph is connected
even when we account for directionality), it is by definition weakly
connected as well.
Parameters
----------
G : NetworkX Graph
A directed graph.
Returns
-------
connected : bool
True if the graph is weakly connected, False otherwise.
Raises
------
NetworkXNotImplemented
If G is undirected.
See Also
--------
is_strongly_connected
is_semiconnected
is_connected
is_biconnected
weakly_connected_components
Notes
-----
For directed graphs only.
rz-Connectivity is undefined for the null graph.)ÚlenÚnxZNetworkXPointlessConceptÚlistrrr
r
rrds
'ÿrccsj|j}|j}tƒ}|h}|rf|}tƒ}|D]8}||vr*|V| |¡| ||¡| ||¡q*qdS)zwA fast BFS node generator
The direction of the edge between nodes is ignored.
For directed graphs only.
N)ÚsuccÚpredrÚaddr)r ÚsourceZGsuccZGpredr
Z nextlevelZ thislevelrr
r
rr“s
r)
Ú__doc__ZnetworkxrZnetworkx.utils.decoratorsrÚ__all__rrrrr
r
r
rÚs
6
.