How this calculation works
A directed flow assigns a nonnegative amount to each edge without exceeding capacity, while every internal vertex passes on as much as it receives. This page uses shortest augmenting paths in a residual network, then returns the edge flows and both residual directions for each original row. The vertices still reachable from the source define a cut. Capacity bounds, internal conservation and equality between the flow value and that cut’s capacity are checked before the result is shown.
Maximize net source outflow subject to 0≤f(e)≤c(e) and flow conservation; maximum flow value equals minimum directed source–sink cut capacity.A worked example
The default network has source edges 1→2 of capacity three and 1→3 of capacity two. A feasible flow sends three to vertex two and two to vertex three, then sends two along 2→4, one along 2→3 and three along 3→4. The sink receives five. The source-side cut S={1} has total outgoing capacity 3+2=5, so no feasible flow can exceed five and the returned flow is maximum.
Good to know
Directed single-source, single-sink networks with 1–30 vertices and at most 200 rows. Capacities are whole numbers from zero through 10⁶. Source and sink must differ, and self-loops are rejected. Parallel and antiparallel edges are supported as separate identities. The routine has an explicit augmentation budget. It does not optimize costs, handle multiple commodities or model physical pressure losses. A maximum flow and minimum cut need not be unique.
Reference: NetworkX — maximum flow, minimum cuts and residual networks (opens in a new tab) ↗
A reverse residual arc can undo an allocation without creating a new original edge
After sending flow along u→v, the residual network gains capacity in the opposite direction. Using that reverse arc later reduces the earlier allocation, allowing an augmenting path to reroute flow. It does not claim that the original network had a new independent v→u capacity. The table therefore keeps the original capacity and flow separate from its forward and reverse residual values.
If the input already contains an antiparallel original edge, its residual pair remains distinct from the reverse residual arc of the first edge. Parallel rows also remain distinct. Merging those identities carelessly can produce a plausible total while giving an impossible per-edge flow or incorrect residual update. The implementation maintains explicit paired arc indices and checks each original row against its own capacity after the augmentation phase.
The Shortest path calculator for a weighted graph edge list minimizes one route weight; it does not enforce network-wide capacity and conservation constraints.
An equal-capacity cut proves optimality more strongly than a stopped search alone
A feasible flow is a lower bound on the maximum, while the capacity of any source–sink cut is an upper bound. When those bounds agree, optimality follows from the certificate, not merely from a message that no path was found. The returned source partition consists of vertices reachable through positive residual capacity. Every original edge from that partition to its complement contributes its capacity to the displayed cut total.
A disconnected sink correctly gives maximum flow zero. That is not an input failure, and zero-capacity edges do not create a usable residual route. Source and sink being the same is rejected because it changes the usual source–sink problem. A nonunique optimum can distribute the same total differently among edges or produce a different minimum partition. Comparing another solver should therefore check feasibility, conservation and cut equality before insisting on one particular allocation.
A few questions, answered
Can capacities be negative?
No. Capacity is a nonnegative upper bound on flow. Negative edge weights belong to other graph problems, such as shortest paths, and are not treated as capacities.
Does this calculate a cheapest maximum flow?
No. It maximizes the total amount only. Costs, prices or travel times are not part of the objective; a minimum-cost flow calculation needs an additional cost model and algorithm.