The Max-Flow Min-Cut Theorem
Every cut's capacity bounds every flow's value from above, as the previous lesson showed. The max-flow min-cut theorem (Ford and Fulkerson; Elias, Feinstein and Shannon; both 1956) says the bound is always reached: the largest flow equals the smallest cut. It is the reason the augmenting-path method is correct, it tells us how to certify that a flow is maximum, and it turns many "minimum cut" questions (how many links must fail to disconnect a network? which pixels belong to the foreground?) into flow computations. It is also a first example of duality, which the linear programming course develops in general.
The theorem
Theorem. For a flow in a flow network with source and sink , the following are equivalent:
- is a maximum flow;
- the residual network contains no augmenting path;
- for some cut .
Proof
(1) implies (2). If had an augmenting path , augmenting along it would give a flow of value , so would not be maximum.
(2) implies (3). Let be the set of vertices reachable from in , and . Then , and because there is no augmenting path, so is a cut. Look at any and :
- If , then : otherwise the residual edge would exist and would be reachable.
- If , then : otherwise the backward residual edge would exist and would be reachable.
So every edge from to is full and every edge from to is empty, and by the lemma on cuts
(3) implies (1). Every flow satisfies , so is maximum.
Two consequences are worth stating separately:
- Max flow = min cut. The value of a maximum flow equals the minimum capacity of a cut. A maximum flow and a minimum cut certify each other: anyone can check that the flow is valid, that the cut has the same number as its capacity, and conclude that both are optimal.
- Finding a minimum cut. After computing a maximum flow, the set of vertices reachable from in gives a minimum cut, at the cost of one more search, .
Finding the cut
The program runs a short augmenting-path algorithm on the network of Flow Networks (BFS for each path, as in the animation there), takes the residual reachable set as , and checks the result against all 16 cuts.
from collections import deque
from itertools import combinations
cap = {("S", "A"): 10, ("S", "B"): 7, ("A", "B"): 4, ("A", "C"): 5, ("B", "D"): 9,
("C", "B"): 3, ("C", "T"): 8, ("D", "C"): 4, ("D", "T"): 6}
V = "SABCDT"
flow = {e: 0 for e in cap}
def residual_neighbours(u):
for (a, b), c in cap.items():
if a == u and c - flow[(a, b)] > 0:
yield b
if b == u and flow[(a, b)] > 0:
yield a
def reachable(s):
prev, q = {s: None}, deque([s])
while q:
u = q.popleft()
for v in sorted(residual_neighbours(u)):
if v not in prev:
prev[v] = u; q.append(v)
return prev
while "T" in (prev := reachable("S")):
path, v = ["T"], "T"
while prev[v]:
v = prev[v]; path.append(v)
path.reverse()
def rc(u, v):
return cap[(u, v)] - flow[(u, v)] if (u, v) in cap else flow[(v, u)]
b = min(rc(u, v) for u, v in zip(path, path[1:]))
for u, v in zip(path, path[1:]):
if (u, v) in cap: flow[(u, v)] += b
else: flow[(v, u)] -= b
print("augment", "".join(path), "by", b)
value = flow[("S", "A")] + flow[("S", "B")]
S = set(reachable("S"))
crossing = [(u, v) for (u, v) in cap if u in S and v not in S]
print("max flow:", value)
print("residual reachable set S:", sorted(S), " cut edges:", crossing,
" capacity:", sum(cap[e] for e in crossing))
print("edges from T back to S carry flow:", [flow[(u, v)] for (u, v) in cap if v in S and u not in S])
caps = {}
for k in range(5):
for extra in combinations("ABCD", k):
side = {"S", *extra}
caps["".join(sorted(side))] = sum(c for (u, v), c in cap.items() if u in side and v not in side)
best = min(caps.values())
print("minimum over all 16 cuts:", best, " achieved by", [s for s, c in caps.items() if c == best])augment SACT by 5
augment SBDT by 6
augment SBDCT by 1
augment SABDCT by 2
max flow: 14
residual reachable set S: ['A', 'B', 'S'] cut edges: [('A', 'C'), ('B', 'D')] capacity: 14
edges from T back to S carry flow: [0]
minimum over all 16 cuts: 14 achieved by ['ABS', 'ABCDS']
The residual reachable set is . The edges and leaving it are full (5 and 9), the edge coming back is empty, and the capacity equals the flow. The brute force confirms 14 as the minimum and finds a second minimum cut, , crossed by the two edges into . Minimum cuts need not be unique; the residual set always gives the one closest to .
Menger's theorem: disjoint paths and cuts
Give every edge capacity 1. An integer flow of value then decomposes into paths from to that share no edge, and a cut of capacity is a set of edges whose removal disconnects from . Max-flow min-cut becomes Menger's theorem: the maximum number of edge-disjoint paths from to equals the minimum number of edges whose removal disconnects them. In network terms, it is how many link failures a connection can survive. The program computes both numbers for a small network and prints the paths, found by following unit flows.
from collections import deque
links = [("S", "A"), ("S", "B"), ("S", "C"), ("A", "D"), ("B", "D"), ("B", "E"), ("C", "E"),
("D", "T"), ("E", "T"), ("A", "B")]
cap = {e: 1 for e in links}
flow = {e: 0 for e in links}
def bfs_path():
prev, q = {"S": None}, deque(["S"])
while q:
u = q.popleft()
nbrs = [(b, "f") for (a, b) in links if a == u and flow[(a, b)] < 1] + \
[(a, "b") for (a, b) in links if b == u and flow[(a, b)] > 0]
for v, kind in sorted(nbrs):
if v not in prev:
prev[v] = (u, kind); q.append(v)
return prev
count = 0
while "T" in (prev := bfs_path()):
v = "T"
while prev[v]:
u, kind = prev[v]
if kind == "f": flow[(u, v)] += 1
else: flow[(v, u)] -= 1
v = u
count += 1
paths = []
for _ in range(count): # peel off one path per unit of flow
p, u = ["S"], "S"
while u != "T":
v = next(b for (a, b) in links if a == u and flow[(a, b)] == 1)
flow[(u, v)] = 0
p.append(v); u = v
paths.append("".join(p))
print("edge-disjoint paths:", count, paths)
for e in links: # restore the maximum flow to read off the cut
flow[e] = 0
for p in paths:
for u, v in zip(p, p[1:]):
flow[(u, v)] = 1
reach = set(bfs_path())
cut = [f"{a}{b}" for (a, b) in links if a in reach and b not in reach]
print("residual reachable set:", sorted(reach), " cut edges:", cut)edge-disjoint paths: 2 ['SADT', 'SBET']
residual reachable set: ['A', 'B', 'C', 'D', 'E', 'S'] cut edges: ['DT', 'ET']
Three edges leave , but only two enter , so at most two edge-disjoint paths can exist, and the program finds two. The residual reachable set is everything except , and the cut it defines is exactly the two edges into : if both fail, is cut off, while any single failure leaves one of the two paths intact. Menger's theorem also has a vertex version (internally vertex-disjoint paths versus vertex cuts), which follows by giving every vertex capacity 1 with the splitting trick of Flow Networks.
Test yourself
Which three statements does the max-flow min-cut theorem prove equivalent?
- is maximum; has no augmenting path; for some cut
- is integral; is acyclic; is unique
- is maximum; is bipartite; every edge is full
- is maximum; every cut has capacity ; is empty
After a maximum flow is computed, how do you find a minimum cut?
- Take the edges with the largest capacities
- Let be the set of vertices reachable from in the residual network; is a minimum cut
- Remove all full edges
- Run Kruskal's algorithm
In a network with unit capacities, the maximum flow from to is 3. What does Menger's theorem say?
- There are exactly 3 paths from to
- There are 3 edge-disjoint paths from to , and removing some 3 edges disconnects from
- Every vertex has degree 3
- Any 3 edges disconnect