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 be a directed network with source , sink and capacities . The flow LP has one variable per arc:
Apply the recipe of Building the Dual Mechanically: a free variable per conservation equation and a non-negative variable per capacity row. After renaming the conservation multipliers as potentials and fixing , (which absorbs the objective), the dual reads
Every - cut with , gives a feasible dual solution: on and elsewhere, exactly on the arcs from to . 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.
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 . We may assume (clipping potentials to does not increase any beyond ). Pick a threshold uniformly at random in and let . Then and , and an arc crosses from to its complement exactly when , which has probability . By linearity of expectation,
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 matter as thresholds, so the rounding is deterministic: try them all.
The network above has three minimum cuts, , and , each of capacity 5. The average of the first and third is an optimal dual that is not a cut: . The program checks that it is optimal and rounds it.
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 on every arc; at an optimal dual this holds automatically, because a larger 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 (, ) is integral; so some optimal dual is integral. An integral with , 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 and a minimum cut :
- an arc from to has , so its capacity row is tight: (saturated);
- an arc from to has , a slack dual constraint, so .
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 for pairs, and 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 - cut ?
- on , elsewhere, and on arcs from to
- on every arc
- everywhere
In threshold rounding, what is the probability that arc is cut by for uniform in ?
- when
At a maximum flow and a minimum cut, what does complementary slackness say about arcs from to ?
- They carry no flow
- They are saturated:
- They have zero capacity
- Nothing