Goal: determine the maximum amount of syrup that can be shipped from Montreal to Vancouver in a month.
Flow Network
A flow network is a directed graph G=(V,E) with a source vertex x and target vertex t such that
each edge e has capacity c(e), which is a non-negative number;
the source s has no incoming edges;
the target t has no outgoing edges.
For most of the lectures we will assume capacities are integers between 0 and
C (finite). We want to model the flow of goods through the network.
An s−t is a function f:E→R≥0 satisfying
(capacity constraints) for each e∈E,0≤f(e)≤c(e);
(flow conservation constraints) for each u∈V∖{s,t}:
fout(v)=(v,u)∈E∑f(v,u)==(u,v)∑f(u,v)=fin(v)
Problem Statement
Input: a flow network G=(V,E) with source s, target t, and capacities c:E→R≥9
Goal: Output a flow f:E→R≥0 satisfying the capacity and flow conservation constraitns, and maximizing flow value.
val(f)=fout(s)=fin(t)
Ford Fulkerson Method (doesn't quite work?)
Obersvation 1: if flows f and f′ flow conservation, so does f+f′.
Observation 2: for any s→t path p, the flow
fp(e)={1,e∈p0,e∈/p
satisfies flow conservation.
Greedy algorithm: push as much flow as possible on some path
for e in E: f(e) = 0while there exists (s->t path) p in G: delta = min{c(e) - f(e)} // minimum available capacity for e in E f'(e) = f(e) + delta f = f' remove edges e with f(e) = c(e) from Ereturn f
Counterexample: why the greedy push fails
The shipping network below witnesses that “pick any s→t path and saturate it” can get stuck strictly below the true maximum flow.
The greedy algorithm might first pick the path s→a→b→t. The bottleneck is the 1-capacity arc a→b, so it sends one unit of flow and removes that saturated edge from E.
With a→b gone, the remaining graph only allows 9 units along s→a→t and 9 units along s→b→t, for a total flow of 19.
The optimal solution is 10 units on each of s→a→t and s→b→t, totalling 20. The single unlucky greedy choice permanently blocks one unit and prevents us from reaching the optimum.
Residual Network
Idea: allow reversing decision by pushing flow back
For an s−t flow f in G, the residual network Gf=(V,Ef) has
forward edge: u→v for each u→v in E such that f(u,v)<c(u,v), with capacity cf(u,v)=c(u,v)−f(u,v) (residual capacity).
backward edge: v→u for each u→v in E such that f(u,v)>0, with capacity cf(u,v)=f(u,v) (residual capacity).
Flow f after saturating s → a → b → t.Residual network G_f with the unit flow captured by dashed backward edges.
Augmenting flow
def Augment(f, p): residual_cap = min{c_f(u, v) : (u, v) in p} for edge (u, v) in p: if (u, v) is a forward edge: f'(u, v) = f(u, v) + residual_cap else: f'(u, v) = f(u, v) - residual_cap return f'
Ford-Fulkerson (Meta-) algorithm
FordFulkerson(G, s, t): for e in E: f(e) = 0 G_f = G while there is a simple path p from s to t in G_f: f' = Augment(f, p) f = f' update G_f return f
Validity of argument
f' = Augment(f, p)
Why does f′ satify capacity and flow conservation constraints?
capacity: from definition of cf(u,v)
flow conservation: Consider arbitrary vertex v
case 1: (u,v),(v,w) are forward edges
f′(u,v)=f(u,v)+cf(p)
f′(v,w)=f(v,w)+cf(p)
case 2: (u,v) is forward, (v,w) is backward
f′(u,v)=f(u,v)+cf(p)
f′(v,w)=f(v,w)−cf(p)
Running Time Analysis
Reminder: we assume all capacities in G are integers between 1 and C.
Observation: throughout, residual capacities and flow values are integers.
Lemma 1
Lemma 1: For a simple s→t path p in Gf, and f′=Augment(f,p),val(f′)=val(f)+cf(p).
Since p is simple, there is exactly 1 edge (s,v) in p touching s.
Also (s,v) is a forward edge, since no edges in G go into s. Which means we have
f′out(s)=fout(s)+cf(p)
Lemma 2
We want to somehow show that this while loop terminates.
Lemma 2: Suppose f is an s−t flow in G. Then val(f)≤∑(s,u)∈Ec(s,u)≤Cn