Max Flow Slides
Max Flow Slides
Maximum Flow 1 / 42
Outline
Introduction
Definitions
Multi-Source Multi-Sink
Maximum Flow 2 / 42
Maximum Flow
Maximum Flow 3 / 42
Maximum Flow
16
20
10
4
s t
7
9
13
4
v2 v4
14
A Flow Network and its capacities
Maximum Flow 4 / 42
12
v1 v3
16
20
10
4
s t
7
9
13
4
v2 v4
14
A Flow Network and its capacities
v 1 6/12 v3
6
8/
1
20
5/
1/4
6/7
10
s t
9
4/
6/
13
4
3/
v 2 9/14 v4
A flow: value 11
Maximum Flow 4 / 42
12
v1 v3
16
20
10
4
s t
7
9
13
4
v2 v4
14
A Flow Network and its capacities
v 1 6/12 v3 v1 12/12 v3
19
/1
6
8/
/2
11
1
20
5/
0
1/4
7/7
9
6/7
10
1/4
10
s t s t
9
4/
4
4/
12
6/
/1
13
v2 v4
3/
3
v 2 9/14 v4
11/14
A flow: value 11 A max-flow: value = 23
Maximum Flow 4 / 42
Flow Definition: I
Maximum Flow 5 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:
∑
∀u ∈ V − {s, t}, v∈V f (u, v) = 0.
Maximum Flow 6 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:
∑
∀u ∈ V − {s, t}, v∈V f (u, v) = 0.
∑
The VALUE of flow f is |f | = v∈V f (s, v) .
Maximum Flow 6 / 42
Flow Definition: II
A FLOW is a function f : V × V → R satisfying:
Capacity Constraint:
∀u, v, ∈ V, f (u, v) ≤ c(u, v).
Skew Symmetry:
∀u, v, ∈ V, f (u, v) = −f (v, u).
Flow Conservation:
∑
∀u ∈ V − {s, t}, v∈V f (u, v) = 0.
∑
The VALUE of flow f is |f | = v∈V f (s, v) .
MAXIMUM-FLOW PROBLEM:
Given G, c, s, t, find f that maximizes |f |.
Maximum Flow 6 / 42
Multi-Source Multi-Sink Problem
Maximum Flow 7 / 42
Multi-Source Multi-Sink Problem
Maximum Flow 7 / 42
Multi-Source Multi-Sink Problem
s1
10
12 3
s2 t1
5 15
8 6
s3 t2
14 20
7 13
s4 t3
11 18
2
s5
Maximum Flow 8 / 42
A multi-source multi-sink problem and its equivalent single-
source single-sink version.
s1
10
s1
10 12 3
s2 t1
12 3
s2 t1 5 15
5 15 8 6
8 6 s s3 t2 t
s3 t2 14 20
14 20
7 13
7 13 s4 t3
s4 t3
11 18 11 18
2 2
s5 s5
Maximum Flow 8 / 42
Manipulating Flows
Let X, Y ⊆ V. We define
∑∑
f (X, Y) = f (x, y).
x∈X y∈Y
Maximum Flow 9 / 42
Lemma: (Proof in Homework)
∀X ⊆ V, f (X, X) = 0.
∀X, Y, Z ⊆ V with X ∩ Y = ∅
f (X ∪ Y, Z) = f (X, Z) + f (Y, Z) and
f (Z, X ∪ Y) = f (Z, X) + f (Z, Y)
Maximum Flow 10 / 42
Flow f was defined as
amount that leaves source s.
We now see that this is the same as
amount that enters sink t.
|f | = f (s, V) definition
= f (V, V) − f (V − s, V) previous page
= −f (V − s, V) previous page
= f (V, V − s) previous page
= f (V, t) + f (V, V − s − t) previous page
= f (V, t) flow conservation
Maximum Flow 11 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?
Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?
Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?
Maximum Flow 12 / 42
All optimization problems must deal with the question:
How to prove that solution is optimal (maximal/minimal)?
Maximum Flow 12 / 42
12/12
v1 v3
6
/1
15
11
/2
1/4
0
7/7
10
s t
9
4/
8/
13
4
4/
v 2 11/14 v4
S T
|f | = f (s, V)
= f (s, V) + f (S − s, V)
= f (S, V)
= f (S, V) − f (S, S)
= f (S, V − S)
= f (S, T)
≤ C(S, T)
Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .
Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .
Stops when there is no s-t path in current Gf .
S = set of nodes reachable from s in Gf & T = V − S.
Maximum Flow 15 / 42
The Ford-Fulkerson Method
Is iterative.
Starts with flow f = 0, (∀u, v, f (u, v) = 0)
At each step
Constructs a residual network Gf of f indicating how
much capacity “remains” to be used .
Finds an augmenting path s-t path p in Gf along which
flow can be pushed.
pushes f ′ units of flow along p.
Creates new flow f = f + f ′ .
Stops when there is no s-t path in current Gf .
S = set of nodes reachable from s in Gf & T = V − S.
Maximum Flow 16 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).
Maximum Flow 17 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).
Maximum Flow 17 / 42
Residual Capacity: cf (u, v) = c(u, v) − f (u, v).
Maximum Flow 17 / 42
v 1 12/12 v 3
6
/1
19
11
/ 20
1/4
7/7
10
s t
9
12
4
/1
4/
v 2 11/14 v4
3
A Flow
Maximum Flow 18 / 42
12
v 1 12/12 v 3 v1 v3
6
1
/1
19
11
11
/
19
20
1/4
11
s t
7/7
10
7
s t
9
9
1
12
4
12
4 v2 3 v4
/1
4/
v 2 11/14 v4
3
11
A Flow Its residual network
Maximum Flow 18 / 42
Lemma:
Maximum Flow 19 / 42
Lemma:
Maximum Flow 19 / 42
Let p be an augmenting path in Gf and define
cf (p) if (u, v) is on p
fp (u, v) = −cf (p) if (v, u) is on p
0 otherwise
Maximum Flow 20 / 42
12/12 v1 12 v3
v1 v3
16
5
15
/
11
11
15
/2
4
1/4
11
s t
7/7
10
7
s t
5
4/
4
8/
8
13
4
v2 v4
4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6
1
/1
19
11
11
/2
19
1/4
11
s t
7/7
10
7
s t
9
9
1
12
4
12
3
4
v2 v4
/1
4/
v 2 11/14 v4
3
11
An initial flow f .
Maximum Flow 21 / 42
12/12 v1 12 v3
v1 v3
16
5
15
/
11
11
15
/2
4
1/4
11
s t
7/7
10
7
s t
5
4/
4
8/
8
13
4
v2 v4
4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6
1
/1
19
11
11
/2
19
1/4
11
s t
7/7
10
7
s t
9
9
1
12
4
12
3
4
v2 v4
/1
4/
v 2 11/14 v4
3
11
An initial flow f .
Its residual network Gf and an augmenting path f ′ in Gf .
Maximum Flow 21 / 42
12/12 v1 12 v3
v1 v3
16
5
15
/
11
11
15
/2
4
1/4
11
s t
7/7
10
7
s t
5
4/
4
8/
8
13
4
v2 v4
4/
v 2 11/14 v4
11
12
v 1 12/12 v 3 v1 v3
6
1
/1
19
11
11
/2
19
1/4
11
s t
7/7
10
7
s t
9
9
1
12
4
12
3
4
v2 v4
/1
4/
v 2 11/14 v4
3
11
An initial flow f .
Its residual network Gf and an augmenting path f ′ in Gf .
The flow f + f ′ and its residual network.
Maximum Flow 21 / 42
Optimality
1 f is a maximum flow in G.
Maximum Flow 22 / 42
Proof:
Maximum Flow 23 / 42
Proof:
Maximum Flow 23 / 42
Proof:
Maximum Flow 24 / 42
FF Example: Steps 1 & 2
v1 12
v3
16
20
10
9
4
s t
4
13
v2 14 v4
Maximum Flow 25 / 42
FF Example: Steps 1 & 2
12 v1 4/12
v1 v3 v3
61
4/
20
16
20
9
10
4/
10
4
9 s t
4
7
s t
4
4/
4
13
13
v2 14 v4 v2 v4
4/14
Maximum Flow 25 / 42
FF Example: Steps 1 & 2
12 v1 4/12
v1 v3 v3
61
4/
20
16
20
9
10
4/
10
4
9 s t
4
7
s t
4
4/
4
13
13
v2 14 v4 v2 v4
4/14
8
v1 v3
4
20
12
4
4
10
s t
4
7
5
4
13
10
v2 v4
4
Maximum Flow 25 / 42
FF Example: Steps 1 & 2
12 v1 4/12
v1 v3 v3
61
4/
20
16
20
9
10
4/
10
4
9 s t
4
7
s t
4
4/
4
13
13
v2 14 v4 v2 v4
4/14
8 4/12
v1 v3 v1 v3
4
7/
/1
20
12
20
11
7/10
4
7/7
4
10
4/
4
s t s t
4
7
5
4
4
4/
13
13
10
v2 v4 v2 v4
4 11/14
Maximum Flow 25 / 42
FF Example: Steps 2 & 3
8 4/12
v1 v3 v1 v3
4
7/
/1
20
12
2
11
0
7/10
4
7/7
4
10
4/
4
s t s t
4
7
5
4
4
4/
13
13
v2 10 v4 v2 v4
4 11/14
Maximum Flow 26 / 42
FF Example: Steps 2 & 3
8 4/12
v1 v3 v1 v3
4
7/
/1
20
12
2
11
0
7/10
4
7/7
4
10
4/
4
s t s t
4
7
5
4
4
4/
13
13
v2 10 v4 v2 v4
4 11/14
8
v1 4 v3 v1 12/12 v3
15
/1
5
13
/2
11
11
1/4
0
7
9
11
4
7/7
4/
s
3
10
s t
7
5
4
4
4/
13
8/
3
13
v2 v4 v2 v4
11 11/14
Maximum Flow 26 / 42
FF Example: Steps 3 & 4
8
v1 4 v3 v1 12/12 v3
15
/1
5
13
/2
11
11
1/4
0
7
9
11
4
7/7
4/
s
3
10
s t
7
5
4
4
4/
13
8/
3
13
v2 v4 v2 v4
11 11/14
Maximum Flow 27 / 42
FF Example: Steps 3 & 4
8
v1 4 v3 v1 12/12 v3
15
/1
5
13
/2
11
11
1/4
0
7
9
11
4
7/7
4/
s
3
10
s t
7
5
4
4
4/
13
8/
3
13
v2 v4 v2 v4
11 11/14
v1 12 v3 v1 12/12 v3
19
/1
5
/2
11
11
0
15
4
7/7
11
9
1/4
3
10
t s t
7
5
5
4
4
4/
12
8
3
/1
v2 v4 v2 v4
3
11 11/14
Maximum Flow 27 / 42
FF Example: Steps 4 & 5 (End)
v1 12 v3 v1 12/12 v3
19
/1
5
/2
11
11
0
15
4
7/7
11
9
1/4
3
s
10
t s t
7
5
5
4
4
4/
12
8
/1
v2 v4 v2 v4
3
11 11/14
Maximum Flow 28 / 42
FF Example: Steps 4 & 5 (End)
v1 12 v3 v1 12/12 v3
19
/1
5
/2
11
11
0
15
4
7/7
11
9
1/4
3
s
10
t s t
7
5
5
4
4
4/
12
8
/1
v2 v4 v2 v4
3
11 11/14
v1 12 v3
5
1
11
19
11
3
s t
7
9
1
4
12
3
v2 v4
11
Maximum Flow 28 / 42
Running Time & Finiteness
Maximum Flow 29 / 42
Running Time & Finiteness
Maximum Flow 29 / 42
If the capacities are all integers
⇒ then each cp will be an integer ≥ 1
⇒ the algorithm must terminate after |f ∗ | steps,
where f ∗ is a max-flow.
Maximum Flow 30 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
Running Time
Maximum Flow 31 / 42
A pathological example in which each augmenting path
only increases flow value by 1 unit.
u u u
1,
1,
99 1
0
9
00
00
00
9,
9
9
,9
,9
0
99
0,
,0
,0
9
9
00
9
99
99
00
00
1,
1
s t s t s t
1
1
99
9
9
99
99
1,
1,
9,
0
00
00
99
9,
9,
00
99
99
0,
0,
9
0,
1
1
00
00
00
v v v
0
0
1,
u u
99 1
99
8
8
9,
9,
99
99
99
99
9,
9,
9
8
99
99
2
2
s t s t
1
1
99
99
8
8
99
99
9,
9,
99
99
9,
9,
99
99
9
8
2
2
1
v v
Maximum Flow 32 / 42
The Edmonds-Karp Algorithm
Maximum Flow 33 / 42
Lemma: ∀v ∈ V − {s, t}, δf (s, v) does not decrease after a
flow augmentation.
Lemma:
Edge (u, v) is critical on a.p. p if cf (u, v) = cf (p).
Suppose when running the E.K. algorithm that (u, v) is crit-
ical for a.p. p in Gf , and is later critical again for another
a.p. p′ in Gf ′ . Then
δf ′ (s, u) ≥ δf (s, u) + 2.
Augmenting paths are simple and do not contain s,t internally, so
δf (s, v) is always ≤ |V|−2 (as long as v is reachable). Combining
the two lemmas therefore shows that no specific edge can be-
come critical more than (|V| − 2)/2 = O(|V|) times. Some edge
is critical in each step, so there can be at most O(|V||E|) steps.
Maximum Flow 34 / 42
Application: Max Bipartite Matching
Maximum Flow 35 / 42
A bipartite graph with 2 matchings
L R L R
Maximum Flow 36 / 42
Our approach will be to write the Max Bipartite Matching
problem as a Max-Flow problem.
We also assign
∀(u, v) ∈ E′ , c(u, v) = 1.
Maximum Flow 37 / 42
Lemma: If f is an integer valued flow in G′ then there is a
matching M of G with |f | = |M|.
Similarly, if M is a matching of G then there is an integer
valued flow f with |f | = |M|.
Maximum Flow 38 / 42
Lemma: If f is an integer valued flow in G′ then there is a
matching M of G with |f | = |M|.
Similarly, if M is a matching of G then there is an integer
valued flow f with |f | = |M|.
Maximum Flow 38 / 42
A bipartite graph and its associated flow network.
A matching and associated flow are illustrated
s t
L R L R
Maximum Flow 39 / 42
Theorem:
Maximum Flow 40 / 42
Theorem:
Maximum Flow 40 / 42
The theorem guarantees that if G′ is the flow network cor-
responding to a bipartite matching problem then max flow
value |f | is the value of a maximum matching.
Maximum Flow 41 / 42
Odds and Ends