$ \def\opt{ {\mathrm{opt}} } \def\val{ {\mathrm{val}} } $
Network Flow
A new interpretation of directed graphs:
Question. How much fluid be routed from $s$ to $t$ per unit time?
Setup.
Flows. An s-t flow $f$ is a function $f : E \to \mathbf{R}^+$ satisfying:
The value of the flow $f$ is $\val(f) = \sum_{s \to v} f(s, v)$
Input.
Output.
Repeat until done:
Flow along $P$ may block other viable paths
Question. How to fix this?
Idea. Add “undo” feature for each edge
if $f$ routes $f(u, v) \leq c(u, v)$ flow from $u$ to $v$, add reverse edge $(v, u)$ with capacity $c(v, u) = f(u, v)$
using $(v, u)$ corresponds to “pushing back” flow from $(u, v)$
if an alternate route for this flow can be found, then more flow can be routed through $u$
Residual graph $G_f = (V_f, E_f)$
Very high level
How do we…
find a path $P$ from $s$ to $t$?
update flow $f$?
update residual graph $G_f$?
MaxFlow(G, s, t):
Gf <- G
f <- zero flow
P <- FindPath(Gf, s, t)
while P is not null do:
b <- min capacity of any edge in P
Augment(Gf, f, P, b)
P <- FindPath(Gf, s, t)
endwhile
return f
Augment(Gf, f, P, b):
for each edge (u, v) in P
if (u, v) is forward edge then
f(u, v) <- f(u, v) + b
c(u, v) <- c(u, v) - b
c(v, u) <- c(v, u) + b
else
f(v, u) <- f(v, u) - b
c(v, u) <- c(v, u) + b
c(u, v) <- c(u, v) - b
Assume:
Observe:
How long to find augmenting path $P$?
How long to run Augment
?
How many iteraions of find/augment?
Conclude: Overall running time?
Question. How do we know this flow is optimal?
Ford-Fulkerson Correctness: