TExcelTAD
Home › Linear Programming & Duality for Algorithms › Max-Flow Min-Cut as LP Duality

Max-Flow Min-Cut as LP Duality

The max-flow min-cut theorem of Part I was proved combinatorially, from the Ford-Fulkerson algorithm: when no augmenting path is left, the vertices reachable in the residual network form a cut whose capacity equals the flow. This lesson proves it a second way, which generalizes far beyond flows: write maximum flow as an LP, write its dual mechanically, and show that the dual's optimum is attained at a cut. Strong duality then gives the theorem, and the explanation of why the dual optimum is a cut (total unimodularity, or a threshold-rounding argument) is a pattern that reappears in rounding algorithms for cut problems.

The flow LP and its dual

Let G=(V,E)G = (V, E) be a directed network with source ss, sink tt and capacities ue≥0u_e \ge 0. The flow LP has one variable fef_e per arc:

max⁡∑e∈δout(s)fe−∑e∈δin(s)fes.t.∑e∈δin(v)fe−∑e∈δout(v)fe=0for v≠s,t0≤fe≤uefor e∈E.\begin{aligned} \max \quad & \sum_{e \in \delta^{out}(s)} f_e - \sum_{e \in \delta^{in}(s)} f_e \\ \text{s.t.} \quad & \sum_{e \in \delta^{in}(v)} f_e - \sum_{e \in \delta^{out}(v)} f_e = 0 && \text{for } v \ne s, t \\ & 0 \le f_e \le u_e && \text{for } e \in E . \end{aligned}

Apply the recipe of Building the Dual Mechanically: a free variable per conservation equation and a non-negative variable ded_e per capacity row. After renaming the conservation multipliers as potentials pvp_v and fixing ps=1p_s = 1, pt=0p_t = 0 (which absorbs the objective), the dual reads

min⁡∑e∈Eue des.t.duv≥pu−pvfor every arc uvps=1,pt=0,d≥0.\begin{aligned} \min \quad & \sum_{e \in E} u_e \, d_e \\ \text{s.t.} \quad & d_{uv} \ge p_u - p_v && \text{for every arc } uv \\ & p_s = 1, \quad p_t = 0, \quad d \ge 0 . \end{aligned}

Every ss-tt cut (S,Sˉ)(S, \bar S) with s∈Ss \in S, t∉St \notin S gives a feasible dual solution: pv=1p_v = 1 on SS and 00 elsewhere, de=1d_e = 1 exactly on the arcs from SS to Sˉ\bar S. Its value is the capacity of the cut. So the dual is a relaxation of the min-cut problem, the primal is max flow, and weak duality is the easy half of the theorem: every flow is at most every cut.

The program builds both LPs for a small network and solves them.

python · try it yourself
from scipy.optimize import linprog

arcs = [("s", "a", 3), ("s", "b", 2), ("a", "b", 1), ("a", "t", 2), ("b", "t", 3)]
V = ["s", "a", "b", "t"]
m = len(arcs)

# primal: maximize net flow out of s
obj = [-(1 if u == "s" else 0) + (1 if v == "s" else 0) for u, v, _ in arcs]
A_eq = [[(1 if v == x else 0) - (1 if u == x else 0) for u, v, _ in arcs] for x in V if x not in ("s", "t")]
flow = linprog(obj, A_eq=A_eq, b_eq=[0] * len(A_eq), bounds=[(0, cap) for _, _, cap in arcs], method="highs")
print("max flow value:", round(float(-flow.fun), 6))

# dual: variables d_e (one per arc) then p_v (one per vertex)
c = [cap for _, _, cap in arcs] + [0] * len(V)
A_ub = []
for k, (u, v, _) in enumerate(arcs):              # p_u - p_v - d_uv <= 0
    row = [0] * (m + len(V))
    row[k] = -1
    row[m + V.index(u)] += 1
    row[m + V.index(v)] -= 1
    A_ub.append(row)
bounds = [(0, None)] * m + [(1, 1) if x == "s" else (0, 0) if x == "t" else (None, None) for x in V]
dual = linprog(c, A_ub=A_ub, b_ub=[0] * m, bounds=bounds, method="highs")
print("dual (fractional min cut) value:", round(float(dual.fun), 6))
max flow value: 5.0
dual (fractional min cut) value: 5.0

Both optima are 5. Strong duality guarantees equal values; what it does not guarantee is that the dual optimum is an actual cut rather than a fractional assignment of potentials. That is the integrality question.

Why the dual optimum is a cut: threshold rounding

Take any feasible dual solution (d,p)(d, p). We may assume 0≤pv≤10 \le p_v \le 1 (clipping potentials to [0,1][0, 1] does not increase any pu−pvp_u - p_v beyond duvd_{uv}). Pick a threshold θ\theta uniformly at random in (0,1](0, 1] and let Sθ={v:pv≥θ}S_\theta = \{ v : p_v \ge \theta \}. Then s∈Sθs \in S_\theta and t∉Sθt \notin S_\theta, and an arc uvuv crosses from SθS_\theta to its complement exactly when pv<θ≤pup_v < \theta \le p_u, which has probability max⁡(0,pu−pv)≤duv\max(0, p_u - p_v) \le d_{uv}. By linearity of expectation,

E[cap⁡(Sθ)]=∑uv∈Euuvmax⁡(0,pu−pv)≤∑euede.\mathbb{E}\big[\operatorname{cap}(S_\theta)\big] = \sum_{uv \in E} u_{uv} \max(0, p_u - p_v) \le \sum_{e} u_e d_e .

Some threshold does at least as well as the expectation, so some cut has capacity at most the dual value. Applied to an optimal dual, this cut is a minimum cut, and its capacity equals the max flow. Only the distinct values of pp matter as thresholds, so the rounding is deterministic: try them all.

The network above has three minimum cuts, {s}\{s\}, {s,a}\{s, a\} and {s,a,b}\{s, a, b\}, each of capacity 5. The average of the first and third is an optimal dual that is not a cut: p=(1,12,12,0)p = (1, \frac{1}{2}, \frac{1}{2}, 0). The program checks that it is optimal and rounds it.

python · try it yourself
from fractions import Fraction as F

arcs = [("s", "a", 3), ("s", "b", 2), ("a", "b", 1), ("a", "t", 2), ("b", "t", 3)]
p = {"s": F(1), "a": F(1, 2), "b": F(1, 2), "t": F(0)}
d = {(u, v): max(F(0), p[u] - p[v]) for u, v, _ in arcs}
print("dual value of the fractional solution:", sum(cap * d[(u, v)] for u, v, cap in arcs))

for theta in sorted({x for x in p.values() if x > 0}):
    S = sorted(v for v in p if p[v] >= theta)
    cap = sum(c for u, v, c in arcs if u in S and v not in S)
    print(f"threshold {theta}: S = {S}, cut capacity {cap}")
dual value of the fractional solution: 5
threshold 1/2: S = ['a', 'b', 's'], cut capacity 5
threshold 1: S = ['s'], cut capacity 5

Both thresholds give minimum cuts. In general the expected capacity equals the dual value only when duv=max⁡(0,pu−pv)d_{uv} = \max(0, p_u - p_v) on every arc; at an optimal dual this holds automatically, because a larger duvd_{uv} would cost more.

The integrality explanation

A second explanation applies to every LP of this kind. The constraint matrix of the flow LP consists of the node-arc incidence matrix (conservation) stacked on an identity (capacities). The node-arc incidence matrix of a directed graph is totally unimodular, and adding identity rows keeps it so. For a TU matrix and integer right-hand sides every vertex of the polytope is integral, on both sides:

  • Primal: with integer capacities, some maximum flow is integral. (Ford-Fulkerson gives a second proof: every augmentation adds an integer.)
  • Dual: the dual's matrix is the transpose, also TU, and its right-hand side (00, 11) is integral; so some optimal dual is integral. An integral pp with ps=1p_s = 1, pt=0p_t = 0 rounds to a cut at threshold 1 with no loss.

Both routes are proved in the Integrality section (Totally Unimodular Matrices). The combination "LP duality + integral polytope = combinatorial min-max theorem" is one of the most productive patterns in combinatorial optimization; König's theorem in the next lesson is another instance.

Complementary slackness for flows

Read with complementary slackness, the duality says what Ford-Fulkerson's proof says. For a maximum flow ff and a minimum cut (S,Sˉ)(S, \bar S):

  • an arc from SS to Sˉ\bar S has de=1>0d_e = 1 > 0, so its capacity row is tight: fe=uef_e = u_e (saturated);
  • an arc from Sˉ\bar S to SS has pu−pv=−1<de=0p_u - p_v = -1 < d_e = 0, a slack dual constraint, so fe=0f_e = 0.
python · try it yourself
arcs = [("s", "a", 3), ("s", "b", 2), ("a", "b", 1), ("a", "t", 2), ("b", "t", 3)]
f = {("s", "a"): 3, ("s", "b"): 2, ("a", "b"): 1, ("a", "t"): 2, ("b", "t"): 3}     # a maximum flow
for S in [{"s"}, {"s", "a"}, {"s", "a", "b"}]:
    forward = [(u, v) for u, v, _ in arcs if u in S and v not in S]
    backward = [(u, v) for u, v, _ in arcs if v in S and u not in S]
    sat = all(f[e] == c for u, v, c in arcs for e in [(u, v)] if e in forward)
    empty = all(f[e] == 0 for e in backward)
    print(f"S = {sorted(S)}: forward arcs saturated {sat}, backward arcs empty {empty}")
S = ['s']: forward arcs saturated True, backward arcs empty True
S = ['a', 's']: forward arcs saturated True, backward arcs empty True
S = ['a', 'b', 's']: forward arcs saturated True, backward arcs empty True

Every minimum cut satisfies the conditions with the same maximum flow, as complementary slackness requires: one optimal primal is complementary to every optimal dual.

Note: The multicommodity version (several source-sink pairs sharing capacities) has an LP pair of the same shape, but the dual is no longer integral: the gap between the sparsest cut and the maximum concurrent flow can be as large as Θ(log⁡k)\Theta(\log k) for kk pairs, and O(log⁡k)O(\log k) is always achieved (Linial, London and Rabinovich, 1995; Aumann and Rabani, 1998, building on Leighton and Rao's work for uniform demands). That gap, and the rounding of the fractional dual (a metric), is the starting point of approximation algorithms for sparsest cut.

Test yourself

Which feasible dual solution corresponds to an ss-tt cut (S,Sˉ)(S, \bar S)?

  1. pv=1p_v = 1 on SS, 00 elsewhere, and de=1d_e = 1 on arcs from SS to Sˉ\bar S
  2. de=1d_e = 1 on every arc
  3. pv=12p_v = \frac{1}{2} everywhere
  4. de=fed_e = f_e

In threshold rounding, what is the probability that arc uvuv is cut by Sθ={v:pv≥θ}S_\theta = \{ v : p_v \ge \theta \} for θ\theta uniform in (0,1](0, 1]?

  1. pu+pvp_u + p_v
  2. max⁡(0,pu−pv)\max(0, p_u - p_v) when 0≤p≤10 \le p \le 1
  3. 12\frac{1}{2}
  4. duv2d_{uv}^2

At a maximum flow and a minimum cut, what does complementary slackness say about arcs from SS to Sˉ\bar S?

  1. They carry no flow
  2. They are saturated: fe=uef_e = u_e
  3. They have zero capacity
  4. Nothing