minimum_cut(flowG, _s, _t, capacity='capacity', flow_func=None, **kwargs)
Use the max-flow min-cut theorem, i.e., the capacity of a minimum capacity cut is equal to the flow value of a maximum flow.
The function used in the flow_func parameter has to return a residual network that follows NetworkX conventions:
The residual network R
from an input graph G
has the same nodes as G
. R
is a DiGraph that contains a pair of edges (u, v)
and (v, u)
iff (u, v)
is not a self-loop, and at least one of (u, v)
and (v, u)
exists in G
.
For each edge (u, v)
in R
, R[u][v]['capacity']
is equal to the capacity of (u, v)
in G
if it exists in G
or zero otherwise. If the capacity is infinite, R[u][v]['capacity']
will have a high arbitrary finite value that does not affect the solution of the problem. This value is stored in R.graph['inf']
. For each edge (u, v)
in R
, R[u][v]['flow']
represents the flow function of (u, v)
and satisfies R[u][v]['flow'] == -R[v][u]['flow']
.
The flow value, defined as the total flow into t
, the sink, is stored in R.graph['flow_value']
. Reachability to t
using only edges (u, v)
such that R[u][v]['flow'] < R[u][v]['capacity']
induces a minimum s
- t
cut.
Specific algorithms may store extra data in R
.
The function should supports an optional boolean parameter value_only. When True, it can optionally terminate the algorithm as soon as the maximum flow value and the minimum cut can be determined.
Edges of the graph are expected to have an attribute called 'capacity'. If this attribute is not present, the edge is considered to have infinite capacity.
Source node for the flow.
Sink node for the flow.
Edges of the graph G are expected to have an attribute capacity that indicates how much flow the edge can support. If this attribute is not present, the edge is considered to have infinite capacity. Default value: 'capacity'.
A function for computing the maximum flow among a pair of nodes in a capacitated graph. The function has to accept at least three parameters: a Graph or Digraph, a source node, and a target node. And return a residual network that follows NetworkX conventions (see Notes). If flow_func is None, the default maximum flow function ( preflow_push
) is used. See below for alternative algorithms. The choice of the default function may change from version to version and should not be relied on. Default value: None.
computes the maximum flow.
If the graph has a path of infinite capacity, all cuts have infinite capacity and the function raises a NetworkXError.
Value of the minimum cut.
A partitioning of the nodes that defines a minimum cut.
Compute the value and the node partition of a minimum (s, t)-cut.
edmonds_karp
meth
maximum_flow
meth
maximum_flow_value
meth
minimum_cut_value
meth
preflow_push
meth
>>> G = nx.DiGraph()
... G.add_edge("x", "a", capacity=3.0)
... G.add_edge("x", "b", capacity=1.0)
... G.add_edge("a", "c", capacity=3.0)
... G.add_edge("b", "c", capacity=5.0)
... G.add_edge("b", "d", capacity=4.0)
... G.add_edge("d", "e", capacity=2.0)
... G.add_edge("c", "y", capacity=2.0)
... G.add_edge("e", "y", capacity=3.0)
minimum_cut computes both the value of the minimum cut and the node partition:
>>> cut_value, partition = nx.minimum_cut(G, "x", "y")
... reachable, non_reachable = partition
'partition' here is a tuple with the two sets of nodes that define the minimum cut. You can compute the cut set of edges that induce the minimum cut as follows:
>>> cutset = set()
... for u, nbrs in ((n, G[n]) for n in reachable):
... cutset.update((u, v) for v in nbrs if v in non_reachable)
... print(sorted(cutset)) [('c', 'y'), ('x', 'b')]
>>> cut_value == sum(G.edges[u, v]["capacity"] for (u, v) in cutset) True
You can also use alternative algorithms for computing the minimum cut by using the flow_func parameter.
>>> from networkx.algorithms.flow import shortest_augmenting_pathSee :
... cut_value == nx.minimum_cut(G, "x", "y", flow_func=shortest_augmenting_path)[0] True
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.connectivity.cuts.minimum_st_edge_cut
networkx.algorithms.connectivity.cuts.minimum_node_cut
networkx.algorithms.flow.preflowpush.preflow_push
networkx.algorithms.flow.edmondskarp.edmonds_karp
networkx.algorithms.flow.boykovkolmogorov.boykov_kolmogorov
networkx.algorithms.flow.maxflow.maximum_flow
networkx.algorithms.flow.maxflow.minimum_cut
networkx.algorithms.flow.dinitz_alg.dinitz
networkx.algorithms.flow.maxflow.minimum_cut_value
networkx.algorithms.flow.gomory_hu.gomory_hu_tree
networkx.algorithms.flow.maxflow.maximum_flow_value
networkx.algorithms.flow.shortestaugmentingpath.shortest_augmenting_path
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