local_edge_connectivity(G, s, t, flow_func=None, auxiliary=None, residual=None, cutoff=None)
Local edge connectivity for two nodes s and t is the minimum number of edges that must be removed to disconnect them.
This is a flow based implementation of edge connectivity. We compute the maximum flow on an auxiliary digraph build from the original network (see below for details). This is equal to the local edge connectivity because the value of a maximum s-t-flow is equal to the capacity of a minimum s-t-cut (Ford and Fulkerson theorem) .
This is a flow based implementation of edge connectivity. We compute the maximum flow using, by default, the edmonds_karp
algorithm on an auxiliary digraph build from the original input graph:
If the input graph is undirected, we replace each edge (u
,`v`) with two reciprocal arcs (u
, :None:None:`v`
) and (:None:None:`v`
, u
) and then we set the attribute 'capacity' for each arc to 1. If the input graph is directed we simply add the 'capacity' attribute. This is an implementation of algorithm 1 in .
The maximum flow in the auxiliary network is equal to the local edge connectivity because the value of a maximum s-t-flow is equal to the capacity of a minimum s-t-cut (Ford and Fulkerson theorem).
Undirected or directed graph
Source node
Target node
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.
Auxiliary digraph for computing flow based edge connectivity. If provided it will be reused instead of recreated. Default value: None.
Residual network to compute maximum flow. If provided it will be reused instead of recreated. Default value: None.
If specified, the maximum flow algorithm will terminate when the flow value reaches or exceeds the cutoff. This is only for the algorithms that support the cutoff parameter: edmonds_karp
and shortest_augmenting_path
. Other algorithms will ignore this parameter. Default value: None.
local edge connectivity for nodes s and t.
Returns local edge connectivity for nodes s and t in G.
edge_connectivity
meth
edmonds_karp
meth
maximum_flow
meth
node_connectivity
meth
preflow_push
meth
This function is not imported in the base NetworkX namespace, so you have to explicitly import it from the connectivity package:
>>> from networkx.algorithms.connectivity import local_edge_connectivity
We use in this example the platonic icosahedral graph, which has edge connectivity 5.
>>> G = nx.icosahedral_graph()
... local_edge_connectivity(G, 0, 6) 5
If you need to compute local connectivity on several pairs of nodes in the same graph, it is recommended that you reuse the data structures that NetworkX uses in the computation: the auxiliary digraph for edge connectivity, and the residual network for the underlying maximum flow computation.
Example of how to compute local edge connectivity among all pairs of nodes of the platonic icosahedral graph reusing the data structures.
>>> import itertools
... # You also have to explicitly import the function for
... # building the auxiliary digraph from the connectivity package
... from networkx.algorithms.connectivity import build_auxiliary_edge_connectivity
... H = build_auxiliary_edge_connectivity(G)
... # And the function for building the residual network from the
... # flow package
... from networkx.algorithms.flow import build_residual_network
... # Note that the auxiliary digraph has an edge attribute named capacity
... R = build_residual_network(H, "capacity")
... result = dict.fromkeys(G, dict())
... # Reuse the auxiliary digraph and the residual network by passing them
... # as parameters
... for u, v in itertools.combinations(G, 2):
... k = local_edge_connectivity(G, u, v, auxiliary=H, residual=R)
... result[u][v] = k
... all(result[u][v] == 5 for u, v in itertools.combinations(G, 2)) True
You can also use alternative flow algorithms for computing edge connectivity. For instance, in dense networks the algorithm shortest_augmenting_path
will usually perform better than the default edmonds_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_pathSee :
... local_edge_connectivity(G, 0, 6, flow_func=shortest_augmenting_path) 5
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.connectivity.connectivity.edge_connectivity
networkx.algorithms.connectivity.edge_kcomponents.k_edge_components
networkx.algorithms.connectivity.connectivity.local_node_connectivity
networkx.algorithms.connectivity.connectivity.local_edge_connectivity
networkx.algorithms.connectivity.connectivity.all_pairs_node_connectivity
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them