Jaehyeon
Heo
(Teddy)

Software Engineer

The shipping problem

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)G = (V, E) with a source vertex xx and target vertex tt such that

  • each edge ee has capacity c(e)c(e), which is a non-negative number;
  • the source ss has no incoming edges;
  • the target tt has no outgoing edges.

For most of the lectures we will assume capacities are integers between 00 and CC (finite). We want to model the flow of goods through the network.


An sts-t is a function f:ER0f: E \rightarrow \mathbb{R}_{\geq 0} satisfying

  1. (capacity constraints) for each eE,0f(e)c(e)e\in E, 0\leq f(e) \leq c(e);
  2. (flow conservation constraints) for each uV{s,t}u\in V \setminus \{s, t\}: fout(v)=(v,u)Ef(v,u)==(u,v)f(u,v)=fin(v)\begin{aligned} f^{out}(v) = \sum_{(v, u)\in E}f(v, u) == \sum_{(u, v)}f(u, v) = f^{in}(v) \end{aligned}

Problem Statement

Input: a flow network G=(V,E)G = (V, E) with source ss, target tt, and capacities c:ER9c: E \rightarrow \mathbb{R}_{\geq 9}

Goal: Output a flow f:ER0f: E \rightarrow \mathbb{R}_{\geq 0} satisfying the capacity and flow conservation constraitns, and maximizing flow value.

val(f)=fout(s)=fin(t) \begin{aligned}val(f) = f^{out}(s) = f^{in}(t)\end{aligned}

Ford Fulkerson Method (doesn't quite work?)

Obersvation 1: if flows ff and ff' flow conservation, so does f+ff + f'. Observation 2: for any sts\rightarrow t path pp, the flow

fp(e)={1,ep0,ep\begin{aligned} f_p(e) = \begin{cases}1, e\in p \\ 0, e\notin p\end{cases} \end{aligned}

satisfies flow conservation.


Greedy algorithm: push as much flow as possible on some path

for e in E:
    f(e) = 0

while 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 E
return f

Counterexample: why the greedy push fails

The shipping network below witnesses that “pick any sts \rightarrow t path and saturate it” can get stuck strictly below the true maximum flow.

c=10c=10c=1c=10c=10sabt
  1. The greedy algorithm might first pick the path sabts \rightarrow a \rightarrow b \rightarrow t. The bottleneck is the 11-capacity arc aba \rightarrow b, so it sends one unit of flow and removes that saturated edge from EE.
  2. With aba \rightarrow b gone, the remaining graph only allows 99 units along sats \rightarrow a \rightarrow t and 99 units along sbts \rightarrow b \rightarrow t, for a total flow of 1919.
  3. The optimal solution is 1010 units on each of sats \rightarrow a \rightarrow t and sbts \rightarrow b \rightarrow t, totalling 2020. 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 sts-t flow ff in GG, the residual network Gf=(V,Ef)G_f = (V, E_f) has

  • forward edge: uvu\rightarrow v for each uvu \rightarrow v in EE such that f(u,v)<c(u,v)f(u, v) < c(u, v), with capacity cf(u,v)=c(u,v)f(u,v)c_f(u, v) = c(u, v) - f(u, v) (residual capacity).
  • backward edge: vuv\rightarrow u for each uvu \rightarrow v in EE such that f(u,v)>0f(u, v) > 0, with capacity cf(u,v)=f(u,v)c_f(u, v) = f(u, v) (residual capacity).
1 / 100 / 101 / 10 / 101 / 10sabt
Flow f after saturating s → a → b → t.
910109111sabt
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 ff' satify capacity and flow conservation constraints?

capacity: from definition of cf(u,v)c_f(u, v)

flow conservation: Consider arbitrary vertex vv

  • case 1: (u,v),(v,w)(u, v), (v, w) are forward edges
    • f(u,v)=f(u,v)+cf(p)f'(u, v) = f(u, v) + c_f(p)
    • f(v,w)=f(v,w)+cf(p)f'(v, w) = f(v, w) + c_f(p)
  • case 2: (u,v)(u, v) is forward, (v,w)(v, w) is backward
    • f(u,v)=f(u,v)+cf(p)f'(u, v) = f(u, v) + c_f(p)
    • f(v,w)=f(v,w)cf(p)f'(v, w) = f(v, w) - c_f(p)

Running Time Analysis

Reminder: we assume all capacities in GG are integers between 11 and CC.

Observation: throughout, residual capacities and flow values are integers.

Lemma 1

Lemma 1: For a simple sts\rightarrow t path pp in GfG_f, and f=Augment(f,p),val(f)=val(f)+cf(p)f' = Augment(f, p), val(f') = val(f) + c_f(p).

Since pp is simple, there is exactly 1 edge (s,v)(s, v) in pp touching ss. Also (s,v)(s, v) is a forward edge, since no edges in GG go into ss. Which means we have fout(s)=fout(s)+cf(p)f'^{out}(s) = f^{out}(s) + c_f(p)


Lemma 2

We want to somehow show that this while loop terminates.

Lemma 2: Suppose ff is an sts-t flow in GG. Then val(f)(s,u)Ec(s,u)Cnval(f)\leq \sum_{(s, u)\in E}c(s, u) \leq Cn