Capacity constraint
On every edge: no negative flow and no overload.
Algorithms · Directed graphs
Pipes, shipments, assignments: the problem is to send as much as possible from a source to a sink, respecting the limit of every connection.
Prerequisites: directed graphs and BFS / DFS.
A flow network is a finite directed graph with two distinct vertices: a source s and a sink t. Every edge has a finite, nonnegative capacity c(u,v). Its flow f(u,v) is the amount actually sent along that edge.
On every edge: no negative flow and no overload.
For every v other than s and t, inflow equals outflow: intermediate vertices do not store flow.
Set f(u,v) = 0 for missing edges. We use nonnegative flow on each original edge; we do not impose f(u,v) = −f(v,u). The flow value is the net outflow from the source, equal to the net inflow into the sink:
The maximum-flow problem asks for a feasible flow maximizing |f|. Do not add flows over all edges: the same amount may traverse several edges. If no flow leaves t or enters s, simply sum the inflow into t or the outflow from s.
For each original edge u → v, create two possibilities in the residual network Gf. Keep only those with strictly positive residual capacity.
Example: an edge of capacity 7 carrying 4 leaves 3 units forward and 4 backward. A reverse edge is not a new pipe: using it reduces flow on the original edge, freeing resources for another route.
An augmenting path is a path from s to t in the residual network. Its bottleneck Δ is the smallest residual capacity on that path. Add Δ on forward edges and subtract Δ on backward edges. The total flow value increases by Δ.
Keep a separate residual pair for each edge, with a reference to its reverse. Alternatively, aggregated residual capacity from u to v is c(u,v) − f(u,v) + f(v,u): it includes unused forward capacity and cancellable opposite flow. Never overwrite an original edge with a reverse residual edge.
Labels show flow / capacity. Ford–Fulkerson with DFS visits a and then b first, making a choice that will be revised using the reverse edge b → a. Edmonds–Karp uses BFS to choose paths with the fewest residual edges.
Initial zero flow.
| Edge | f / c | Forward residual | Backward residual |
|---|---|---|---|
| s → a | 0 / 3 | 3 | 0 |
| s → b | 0 / 2 | 2 | 0 |
| a → b | 0 / 2 | 2 | 0 |
| a → t | 0 / 2 | 2 | 0 |
| b → t | 0 / 3 | 3 | 0 |
The final flow is (3, 2, 1, 2, 3) in table order. It is maximum: the cut S = {s}, T = {a,b,t} has capacity 3 + 2 = 5. With BFS the augmentations are s → a → t (2), s → b → t (2), s → a → b → t (1): the same final value in three augmentations.
An s–t cut partitions V into (S,T), with s ∈ S and t ∈ T. Its capacity c(S,T) is the sum of original capacities from S to T; edges from T to S do not count.
By conservation, the net flow across any cut equals |f|. Forward flow cannot exceed the cut capacity and return flow is nonnegative, so |f| ≤ c(S,T). The max-flow min-cut theorem says this bound can be attained:
Equivalently, a flow is maximum if and only if its residual network has no augmenting path. Maximum flows and minimum cuts need not be unique.
Ford–Fulkerson is a method: repeat augmentations while a residual path exists. Edmonds–Karp specifies how to choose it: BFS finds a shortest path by edge count, not a path of greatest capacity.
initialize f = 0 on all edges
while a path P from s to t exists in the residual network:
Δ = minimum residual capacity on P
for each residual edge e of P:
residual[e] -= Δ
residual[reverse(e)] += Δ
value += Δ
return f and vertices reachable from s in the residual network
With residual pairs, recover each original edge’s flow as initial capacity minus forward residual capacity. Every update must also update the reverse edge.
| Method | Time | Conditions and meaning |
|---|---|---|
| Ford–Fulkerson | O(n + m(1 + F)) | Integer capacities, initial zero flow, linear path search. Each augmentation adds at least 1; the usual O(mF) bound omits initialization and assumes F ≥ 1. This is pseudopolynomial. |
| Edmonds–Karp | O(nm²) | O(nm) augmentations, each using BFS. Polynomial bound independent of capacity values, assuming exact, unit-cost arithmetic. |
Both use O(n + m) space with adjacency lists. The usual Edmonds–Karp bound considers vertices in the relevant network; initializing isolated vertices adds O(n). BFS distances in the residual network never decrease: an edge can become a bottleneck only O(n) times, giving O(nm) augmentations.
With rational capacities Ford–Fulkerson terminates, but scaling to integers can produce very large numbers. With irrational capacities and arbitrary path choices it may not terminate. Integer capacities guarantee that an integral maximum flow exists, since each augmentation preserves integrality; this does not mean every optimal solution must be integral.
Maximum flow optimizes quantity. Optimizing a cost per unit transported requires a different problem: minimum-cost flow.
Initially: 3 forward and 6 backward. Afterwards: flow drops to 4, leaving 5 forward and 4 backward. The reverse augmentation is part of a complete augmenting path, preserving conservation.
No. The flow of value 5 remains feasible and cut {s} still has capacity 5. Improving one edge does not guarantee increased overall throughput.
Send 3 along s → a → t and 2 along s → t: value 5. Cut S = {s,a}, T = {t} has capacity 3 + 2 = 5 and certifies optimality. Edge s → a is not saturated.
Zero. Zero flow is feasible; vertices reachable from s form one side of a cut with no outgoing edges, hence zero capacity.
Further reading: Princeton · Maximum Flow for Edmonds–Karp and its implementation; MIT · Network Flows for conventions, cuts and proofs.