networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
preflow_push(G, s, t, capacity='capacity', residual=None, global_relabel_freq=1, value_only=False)

This function returns the residual network resulting after computing the maximum flow. See below for details about the conventions NetworkX uses for defining residual networks.

This algorithm has a running time of $O(n^2 \sqrt{m})$ for $n$ nodes and $m$ edges.

Notes

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 node u in R , R.nodes[u]['excess'] represents the difference between flow into u and flow out of u .

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.

Parameters

G : NetworkX graph

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.

s : node

Source node for the flow.

t : node

Sink node for the flow.

capacity : string

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'.

residual : NetworkX graph

Residual network on which the algorithm is to be executed. If None, a new residual network is created. Default value: None.

global_relabel_freq : integer, float

Relative frequency of applying the global relabeling heuristic to speed up the algorithm. If it is None, the heuristic is disabled. Default value: 1.

value_only : bool

If False, compute a maximum flow; otherwise, compute a maximum preflow which is enough for computing the maximum flow value. Default value: False.

Raises

NetworkXError

The algorithm does not support MultiGraph and MultiDiGraph. If the input graph is an instance of one of these two classes, a NetworkXError is raised.

NetworkXUnbounded

If the graph has a path of infinite capacity, the value of a feasible flow on the graph is unbounded above and the function raises a NetworkXUnbounded.

Returns

R : NetworkX DiGraph

Residual network after computing the maximum flow.

Find a maximum single-commodity flow using the highest-label preflow-push algorithm.

See Also

edmonds_karp

meth

maximum_flow

meth

minimum_cut

meth

shortest_augmenting_path

meth

Examples

>>> from networkx.algorithms.flow import preflow_push

The functions that implement flow algorithms and output a residual network, such as this one, are not imported to the base NetworkX namespace, so you have to explicitly import them from the flow package.

>>> 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)
... R = preflow_push(G, "x", "y")
... flow_value = nx.maximum_flow_value(G, "x", "y")
... flow_value == R.graph["flow_value"] True
>>> # preflow_push also stores the maximum flow value
... # in the excess attribute of the sink node t
... flow_value == R.nodes["y"]["excess"] True
>>> # For some problems, you might only want to compute a
... # maximum preflow.
... R = preflow_push(G, "x", "y", value_only=True)
... flow_value == R.graph["flow_value"] True
>>> flow_value == R.nodes["y"]["excess"]
True
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.connectivity.cuts.minimum_node_cut networkx.algorithms.flow.edmondskarp.edmonds_karp networkx.algorithms.connectivity.connectivity.local_node_connectivity networkx.algorithms.flow.dinitz_alg.dinitz networkx.algorithms.connectivity.cuts.minimum_st_edge_cut networkx.algorithms.flow.maxflow.minimum_cut_value networkx.algorithms.connectivity.connectivity.local_edge_connectivity networkx.algorithms.connectivity.connectivity.edge_connectivity networkx.algorithms.flow.maxflow.maximum_flow networkx.algorithms.flow.maxflow.maximum_flow_value networkx.algorithms.connectivity.connectivity.all_pairs_node_connectivity networkx.algorithms.flow.preflowpush.preflow_push networkx.algorithms.connectivity.cuts.minimum_edge_cut networkx.algorithms.connectivity.connectivity.node_connectivity networkx.algorithms.flow.shortestaugmentingpath.shortest_augmenting_path networkx.algorithms.connectivity.disjoint_paths.node_disjoint_paths networkx.algorithms.flow.boykovkolmogorov.boykov_kolmogorov networkx.algorithms.flow.maxflow.minimum_cut networkx.algorithms.connectivity.connectivity.average_node_connectivity networkx.algorithms.connectivity.disjoint_paths.edge_disjoint_paths networkx.algorithms.connectivity.cuts.minimum_st_node_cut

Local connectivity graph

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


GitHub : /networkx/algorithms/flow/preflowpush.py#287
type: <class 'function'>
Commit: