12: Network Flows
Flow Networks
A flow network is a directed graph with two distinguished vertices — a source and a sink — together with a capacity function assigning a nonneg capacity to each edge. A flow is a function satisfying two constraints:
- Capacity constraint: for every edge , we require .
- Flow conservation: for every vertex , the total flow entering equals the total flow leaving :
The value of a flow is the net flow leaving the source: . The maximum flow problem asks for a flow of maximum value.
Residual Graphs and Augmenting Paths
Given a flow on , the residual graph encodes remaining capacity. For each edge :
- If , include a forward edge with residual capacity .
- If , include a backward edge with residual capacity .
An augmenting path is any path in the residual graph . The bottleneck capacity of such a path is . We can increase the flow value by this bottleneck amount by pushing flow along , incrementing forward edges and decrementing backward edges accordingly.
The Ford-Fulkerson Method
The Ford-Fulkerson method is an iterative approach to computing maximum flows:
- Initialize for all edges.
- While there exists an augmenting path in :
- Compute the bottleneck capacity .
- Update the flow: for each edge , increase by (forward) or decrease by (backward).
- Return .
With integer capacities, each iteration increases by at least 1, so the method terminates in at most iterations, where is a maximum flow. Each iteration requires time to find an augmenting path, yielding total time. This can be arbitrarily bad: a network with capacity on critical edges yields time, which is pseudo-polynomial.
The Max-Flow Min-Cut Theorem
An - cut is a partition of with and . Its capacity is . For any flow and any cut , the value of equals the net flow across the cut, and therefore .
Theorem (Max-Flow Min-Cut). The following three conditions are equivalent:
- is a maximum flow in .
- The residual graph contains no augmenting path.
- for some - cut .
This theorem, due to Ford and Fulkerson (1956), establishes a strong duality between flows and cuts. The proof is constructive: when no augmenting path exists, the set of vertices reachable from in defines a minimum cut.
Edmonds-Karp Algorithm
The Edmonds-Karp algorithm is Ford-Fulkerson with the specific rule of always choosing the shortest augmenting path (fewest edges), found via BFS on .
Theorem. Edmonds-Karp runs in time.
The key insight is that after each augmentation, at least one edge becomes saturated (its residual capacity drops to zero), and the distance from to any vertex in is monotonically nondecreasing. Since each edge can be critical at most times and there are edges, the total number of augmentations is . Each BFS takes time, giving .
More advanced algorithms achieve better bounds. Dinic’s algorithm runs in using the concept of blocking flows in layered graphs. For unit-capacity networks, this improves to . The push-relabel algorithm of Goldberg and Tarjan achieves as well, with practical implementations often outperforming augmenting-path methods.
Applications
Bipartite Matching
Given a bipartite graph , a matching is a subset where no vertex appears more than once. To find a maximum matching, construct a flow network: add source with edges to all vertices in , add sink with edges from all vertices in , direct all original edges from to , and set all capacities to 1. An integral maximum flow corresponds to a maximum matching. By the integrality theorem, the max-flow in a network with integer capacities is integer-valued, so this reduction is exact.
By K”onig’s theorem, the size of the maximum matching in a bipartite graph equals the size of the minimum vertex cover, a combinatorial analogue of max-flow min-cut duality.
Edge-Disjoint Paths
The maximum number of edge-disjoint - paths in a directed graph equals the maximum - flow when all capacities are 1 (Menger’s theorem). This follows directly from the integrality theorem: each unit of flow traces a distinct - path, and no edge carries more than one unit.
Minimum Cut in Undirected Graphs
For undirected graphs, replace each edge with two directed edges and , each with the original capacity. The minimum - cut in this directed network gives the minimum - cut in the original undirected graph. The global minimum cut (over all pairs) can be found by fixing and trying all choices of .
Connection to Machine Learning
Graph cuts for image segmentation. In binary image segmentation, each pixel is assigned a label (foreground or background). The energy function combines unary terms (how likely each pixel belongs to each class, derived from a learned model) and pairwise terms (a penalty for neighboring pixels with different labels):
When the pairwise terms are submodular (the penalty for disagreeing neighbors exceeds that for agreeing ones), this energy can be exactly minimized via a minimum - cut. Construct a flow network with pixels as nodes, source representing foreground and sink representing background. Edge capacities encode the energy terms. The minimum cut partitions pixels into foreground and background, minimizing in polynomial time.
This technique, popularized by Boykov, Veksler, and Zabih (2001), is widely used in computer vision. Extensions handle multi-label problems via alpha-expansion moves, where each move solves a binary graph cut subproblem.
Next: 13: Linear Programming