12: Network Flows

Flow Networks

A flow network is a directed graph G=(V,E)G = (V, E) with two distinguished vertices — a source ss and a sink tt — together with a capacity function c:ER0c : E \to \mathbb{R}_{\geq 0} assigning a nonneg capacity to each edge. A flow is a function f:ER0f : E \to \mathbb{R}_{\geq 0} satisfying two constraints:

  1. Capacity constraint: for every edge (u,v)E(u, v) \in E, we require 0f(u,v)c(u,v)0 \leq f(u,v) \leq c(u,v).
  2. Flow conservation: for every vertex vV{s,t}v \in V \setminus \{s, t\}, the total flow entering vv equals the total flow leaving vv:

u:(u,v)Ef(u,v)=w:(v,w)Ef(v,w)\sum_{u:(u,v) \in E} f(u,v) = \sum_{w:(v,w) \in E} f(v,w)

The value of a flow is the net flow leaving the source: f=v:(s,v)Ef(s,v)u:(u,s)Ef(u,s)|f| = \sum_{v:(s,v) \in E} f(s,v) - \sum_{u:(u,s) \in E} f(u,s). The maximum flow problem asks for a flow of maximum value.

Residual Graphs and Augmenting Paths

Given a flow ff on GG, the residual graph Gf=(V,Ef)G_f = (V, E_f) encodes remaining capacity. For each edge (u,v)E(u,v) \in E:

  • If f(u,v)<c(u,v)f(u,v) < c(u,v), include a forward edge (u,v)(u,v) with residual capacity cf(u,v)=c(u,v)f(u,v)c_f(u,v) = c(u,v) - f(u,v).
  • If f(u,v)>0f(u,v) > 0, include a backward edge (v,u)(v,u) with residual capacity cf(v,u)=f(u,v)c_f(v,u) = f(u,v).

An augmenting path is any sts \to t path in the residual graph GfG_f. The bottleneck capacity of such a path PP is min(u,v)Pcf(u,v)\min_{(u,v) \in P} c_f(u,v). We can increase the flow value by this bottleneck amount by pushing flow along PP, incrementing forward edges and decrementing backward edges accordingly.

The Ford-Fulkerson Method

The Ford-Fulkerson method is an iterative approach to computing maximum flows:

  1. Initialize f(u,v)=0f(u,v) = 0 for all edges.
  2. While there exists an augmenting path PP in GfG_f:
    • Compute the bottleneck capacity δ=min(u,v)Pcf(u,v)\delta = \min_{(u,v) \in P} c_f(u,v).
    • Update the flow: for each edge (u,v)P(u,v) \in P, increase f(u,v)f(u,v) by δ\delta (forward) or decrease f(v,u)f(v,u) by δ\delta (backward).
  3. Return ff.

With integer capacities, each iteration increases f|f| by at least 1, so the method terminates in at most f|f^*| iterations, where ff^* is a maximum flow. Each iteration requires O(E)O(E) time to find an augmenting path, yielding O(Ef)O(E \cdot |f^*|) total time. This can be arbitrarily bad: a network with capacity CC on critical edges yields O(EC)O(EC) time, which is pseudo-polynomial.

The Max-Flow Min-Cut Theorem

An ss-tt cut is a partition (S,T)(S, T) of VV with sSs \in S and tTt \in T. Its capacity is c(S,T)=uS,vTc(u,v)c(S, T) = \sum_{u \in S, v \in T} c(u,v). For any flow ff and any cut (S,T)(S, T), the value of ff equals the net flow across the cut, and therefore fc(S,T)|f| \leq c(S, T).

Theorem (Max-Flow Min-Cut). The following three conditions are equivalent:

  1. ff is a maximum flow in GG.
  2. The residual graph GfG_f contains no augmenting path.
  3. f=c(S,T)|f| = c(S, T) for some ss-tt cut (S,T)(S, T).

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 SS of vertices reachable from ss in GfG_f 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 GfG_f.

Theorem. Edmonds-Karp runs in O(VE2)O(VE^2) 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 ss to any vertex in GfG_f is monotonically nondecreasing. Since each edge can be critical at most O(V)O(V) times and there are O(E)O(E) edges, the total number of augmentations is O(VE)O(VE). Each BFS takes O(E)O(E) time, giving O(VE2)O(VE^2).

More advanced algorithms achieve better bounds. Dinic’s algorithm runs in O(V2E)O(V^2 E) using the concept of blocking flows in layered graphs. For unit-capacity networks, this improves to O(EV)O(E\sqrt{V}). The push-relabel algorithm of Goldberg and Tarjan achieves O(V2E)O(V^2 E) as well, with practical implementations often outperforming augmenting-path methods.

Applications

Bipartite Matching

Given a bipartite graph G=(LR,E)G = (L \cup R, E), a matching is a subset MEM \subseteq E where no vertex appears more than once. To find a maximum matching, construct a flow network: add source ss with edges to all vertices in LL, add sink tt with edges from all vertices in RR, direct all original edges from LL to RR, 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 ss-tt paths in a directed graph equals the maximum ss-tt flow when all capacities are 1 (Menger’s theorem). This follows directly from the integrality theorem: each unit of flow traces a distinct ss-tt path, and no edge carries more than one unit.

Minimum Cut in Undirected Graphs

For undirected graphs, replace each edge {u,v}\{u,v\} with two directed edges (u,v)(u,v) and (v,u)(v,u), each with the original capacity. The minimum ss-tt cut in this directed network gives the minimum ss-tt cut in the original undirected graph. The global minimum cut (over all s,ts,t pairs) can be found by fixing ss and trying all V1|V|-1 choices of tt.

Connection to Machine Learning

Graph cuts for image segmentation. In binary image segmentation, each pixel ii is assigned a label xi{0,1}x_i \in \{0,1\} (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):

E(x)=iDi(xi)+λ(i,j)NVij(xi,xj)E(x) = \sum_i D_i(x_i) + \lambda \sum_{(i,j) \in \mathcal{N}} V_{ij}(x_i, x_j)

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 ss-tt 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 E(x)E(x) 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