node_connectivity#
- node_connectivity(G, s=None, t=None, flow_func=None)[source]#
Returns node connectivity for a graph or digraph G.
Node connectivity is equal to the minimum number of nodes that must be removed to disconnect G or render it trivial. If source and target nodes are provided, this function returns the local node connectivity: the minimum number of nodes that must be removed to break all paths from source to target in G.
- Parameters:
- GNetworkX graph
Undirected graph
- snode
Source node. Optional. Default value: None.
- tnode
Target node. Optional. Default value: None.
- flow_funcfunction
A function for computing the maximum flow among a pair of nodes. The function has to accept at least three parameters: a Digraph, a source node, and a target node. And return a residual network that follows NetworkX conventions (see
maximum_flow()for details). If flow_func is None, the default maximum flow function (edmonds_karp()) is used. See below for details. The choice of the default function may change from version to version and should not be relied on. Default value: None.
- Returns:
- Kinteger
Node connectivity of G, or local node connectivity if source and target are provided.
See also
Notes
This is a flow based implementation of node connectivity. The algorithm works by solving \(O((n-\delta-1+\delta(\delta-1)/2))\) maximum flow problems on an auxiliary digraph. Where \(\delta\) is the minimum degree of G. For details about the auxiliary digraph and the computation of local node connectivity see
local_node_connectivity(). This implementation is based on algorithm 11 in [1].The local node connectivity of an ordered pair of nodes of a digraph is not symmetric, so both orders of each pair are considered [2].
Before each of those maximum flow problems a much cheaper call is made to the shortest path based approximation of local node connectivity (see
networkx.algorithms.approximation.local_node_connectivity()), following [3]. That approximation is a strict lower bound on the exact value, so whenever it already reaches the best value of \(K\) found so far the maximum flow computation cannot lower \(K\) and is skipped. This does not change the result, which is still exact.References
[1]Abdol-Hossein Esfahanian. Connectivity Algorithms. http://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
[2]Shimon Even and R. Endre Tarjan. Network Flow and Testing Graph Connectivity. SIAM Journal on Computing, Volume 4, Issue 4, pp. 507-518, 1975. https://doi.org/10.1137/0204043
[3]Robert S. Sinkovits. Fast and Accurate Determination of Graph Node Connectivity Leveraging Approximate Methods. Computational Science - ICCS 2021, Lecture Notes in Computer Science, Volume 12742, Springer, 2021. https://doi.org/10.1007/978-3-030-77961-0_41
Examples
>>> # Platonic icosahedral graph is 5-node-connected >>> G = nx.icosahedral_graph() >>> nx.node_connectivity(G) 5
You can use alternative flow algorithms for the underlying maximum flow computation. In dense networks the algorithm
shortest_augmenting_path()will usually perform better than the defaultedmonds_karp(), which is faster for sparse networks with highly skewed degree distributions. Alternative flow functions have to be explicitly imported from the flow package.>>> from networkx.algorithms.flow import shortest_augmenting_path >>> nx.node_connectivity(G, flow_func=shortest_augmenting_path) 5
If you specify a pair of nodes (source and target) as parameters, this function returns the value of local node connectivity.
>>> nx.node_connectivity(G, 3, 7) 5
If you need to perform several local computations among different pairs of nodes on the same graph, it is recommended that you reuse the data structures used in the maximum flow computations. See
local_node_connectivity()for details.