rmykkänen

notes

Max flow

date

Consider a directed graph GG with arbitrary vertices ss and tt. Thinking of the weight of each edge as a capacity, max flow asks for the maximum amount we can push from ss (the source) to tt (the sink). The "liquid in pipes" metaphor is pretty useless, but there are many seemingly difficult problems that are made obvious via a mapping to max-flow.

In later definitions you'll find references to the "amount" or "how much" of something we can push from ss to tt. A natural question asks what exactly is being counted and pushed. The genericness of the capacity and thus the flow is inherited from the unitless nature of edge weights. Our edge weights are unitless integers, so the max flow from ss to tt is as well.

Defining flow networks

Along with a directed graph G=(V,E)G = (V, E), we have a capacity for each edge c(uv)≥0c(u v) \ge 0, and two vertices ss and tt.

A flow f(uv)f(uv) for any edge in GG satisfies:

  • the capacity constraint, that 0≤f(uv)≤c(uv)0 \le f(u v) \le c(u v).
  • conservation, that for nodes besides ss and tt, ∑xf(xv)=∑yf(vy)\sum_x f(x v) = \sum_y f(v y). In other words, the sum of all flows with directed edges to any vv is equal to that of edges from vv.
  • the amount leaving ss is equal to the amount entering tt, that ∣f∣=∑yf(s,y)=∑xf(x,t)|f| = \sum_y f(s, y) = \sum_x f(x, t).

The goal of max flow is to maximize flow.

Residual capacities, augmenting paths

Given a flow ff, define the residual capacity cfc_f:

  • Forward room is cf(uv)=c(uv)−f(uv)c_f(u v) = c(u v) - f(u v). It's how much beyond the flow our capacity would let us push.
  • Backward room is cf(vu)=f(uv)c_f(v u) = f(u v). It's how much we could send backwards in the network for use in a more optimal subpath. All edges with positive cfc_f form the residual graph GfG_f, an augmenting path is any s,ts,t-path in GfG_f.

Let Δ\Delta be the minimum residual capacity along an augmenting path. If we add Δ\Delta to every forward edge and subtract it from every backward edge, we increase the flow of the network by Δ\Delta. In essence, the residual path uses the flow at immediate edges to instruct the s,ts,t-path that maximizes ff.

Algorithms

Ford-Fulkerson

As long as there's a way to increase flow (there's some augmenting path in GfG_f), push as much as you safely can onto it. The amount being pushed is inherently Δ\Delta. Update the residual capacities and continue. When no augmenting path exists, we've reached maximum flow.

Edmonds-Karp

Edmonds-Karp combines Ford-Fulkerson with BFS. FF shows us that if we build a residual graph, find an augmenting path, increase the network flow by Δ\Delta, and repeat until there is no augmenting path, then we've reached max flow. EK constructs the residual graph like FF but intelligently chooses the augmenting path with the fewest edges via BFS. Augmenting along this path by Δ\Delta and recomputing until no augmenting path exists gives a polynomial bound to the max flow problem.