Max Flow and Min Cut Algorithms Explained
Max Flow and Min Cut Algorithms Explained
Network Flow
1
Soviet Rail Network, 1955
2
Maximum Flow and Minimum Cut
3
Minimum Cut Problem
Flow network.
Abstraction for material flowing through the edges.
G = (V, E) = directed graph, no parallel edges.
Two distinguished nodes: s = source, t = sink.
c(e) = capacity of edge e.
2 9 5
10 15 15 10
4
source s 5 3 8 6 10 t sink
4 6 15
15 10
capacity
4 30 7
4
Cuts
2 9 5
10 15 15 10
4
s 5 3 8 6 10 t
4 6 15
15 10
Capacity = 10 + 5 + 15
4 30 7 = 30
5
Cuts
2 9 5
10 15 15 10
4
s 5 3 8 6 10 t
A
4 6 15
15 10
Capacity = 9 + 15 + 8 + 30
4 30 7 = 62
6
Minimum Cut Problem
2 9 5
10 15 15 10
4
s 5 3 8 6 10 t
4 6 15
A 15 10
Capacity = 10 + 8 + 10
4 30 7 = 28
7
Flows
0 4 4
s 5 3 8 6 10 t
0 0
4 0 6 15 0
10
capacity 15
flow 0
0
Value = 4
4 30 7
8
Flows
3 8 8
s 5 3 8 6 10 t
1 10
4 0 6 15 0
10
capacity 15
flow 11
11
Value = 24
4 30 7
9
Maximum Flow Problem
9
2 9 5
10 9
1
10 15 15 0 10
4 0
4 8 9
s 5 3 8 6 10 t
4 10
4 0 6 15 0
10
capacity 15
flow 14
14
Value = 28
4 30 7
10
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
f (e) − f (e) = v( f )
e out of A e in to A
6
2 9 5
10 6
0
10 15 15 0 10
4 4
3 8 8
s 5 3 8 6 10 t
A
1 10
4 0 6 15 0
15 10
11
11
Value = 24
4 30 7
11
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
f (e) − f (e) = v( f )
e out of A e in to A
6
2 9 5
10 6
0
10 15 15 0 10
4 4
3 8 8
s 5 3 8 6 10 t
A
1 10
4 0 6 15 0
15 10
11
11 Value = 6 + 0 + 8 - 1 + 11
4 30 7 = 24
12
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut.
Then, the net flow sent across the cut is equal to the amount leaving s.
f (e) − f (e) = v( f )
e out of A e in to A
6
2 9 5
10 6
0
10 15 15 0 10
4 4
3 8 8
s 5 3 8 6 10 t
A
1 10
4 0 6 15 0
15 10
11
11 Value = 10 - 4 + 8 - 0 + 10
4 30 7 = 24
13
Flows and Cuts
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then
f (e) − f (e) = v( f ) .
e out of A e in to A
Pf. v( f ) = f (e)
e out of s
by flow conservation, all terms = f (e) − f (e)
except v = s are 0 v A e out of v e in to v
= f (e) − f (e).
e out of A e in to A
14
Flows and Cuts
Weak duality. Let f be any flow, and let (A, B) be any s-t cut. Then the
value of the flow is at most the capacity of the cut.
2 9 5
10 15 15 10
4
s 5 3 8 6 10 t
4 6 15
15 10
Capacity = 30
4 30 7
15
Flows and Cuts
Weak duality. Let f be any flow. Then, for any s-t cut (A, B) we have
v(f) cap(A, B).
Pf.
A 4 B
v( f ) = f (e) − f (e) 8
e out of A e in to A t
f (e)
e out of A
c(e)
e out of A s
7
= cap(A, B) 6
16
Certificate of Optimality
Value of flow = 28
Cut capacity = 28 Flow value 28
9
2 9 5
10 9
1
10 15 15 0 10
4 0
4 8 9
s 5 3 8 6 10 t
4 10
A 4 0 6 15 0
15 10
14
14
4 30 7
17
Towards a Max Flow Algorithm
Greedy algorithm.
Start with f(e) = 0 for all edge e E.
Find an s-t path P where each edge has f(e) < c(e).
Augment flow along path P.
Repeat until you get stuck.
0 0
20 10
s 30 0 t
10 20
0 0 Flow value = 0
18
Towards a Max Flow Algorithm
Greedy algorithm.
Start with f(e) = 0 for all edge e E.
Find an s-t path P where each edge has f(e) < c(e).
Augment flow along path P.
Repeat until you get stuck.
20 X
0 0
20 10
s 30 X
0 20 t
10 20
0 X
0 20 Flow value = 20
19
Towards a Max Flow Algorithm
Greedy algorithm.
Start with f(e) = 0 for all edge e E.
Find an s-t path P where each edge has f(e) < c(e).
Augment flow along path P.
Repeat until you get stuck.
locally optimality global optimality
1 1
20 0 20 10
20 10 20 10
s 30 20 t s 30 10 t
10 20 10 20
0 20 10 20
2 2
greedy = 20 opt = 30
20
Residual Graph
Residual edge.
"Undo" flow sent.
residual capacity
e = (u, v) and eR = (v, u).
Residual capacity: u 11 v
c(e) − f (e) if e E 6
c f (e) = residual capacity
f (e) if e R E
21
Ford-Fulkerson Algorithm
2 4 4
capacity
G:
10 2 8 6 10
s 10 3 9 5 10 t
22
Augmenting Path Algorithm
forward edge
reverse edge
23
Max-Flow Min-Cut Theorem
24
Proof of Max-Flow Min-Cut Theorem
(iii) (i)
Let f be a flow with no augmenting paths.
Let A be set of vertices reachable from s in residual graph.
By definition of A, s A.
By definition of f, t A.
v( f ) = f (e) − f (e)
e out of A e in to A A B
= c(e)
e out of A t
= cap(A, B)
original network
25
Running Time
Invariant. Every flow value f(e) and every residual capacities cf (e)
remains an integer throughout the algorithm.
26
7.3 Choosing Good Augmenting Paths
Ford-Fulkerson: Exponential Number of Augmentations
1 1
1 X
0 0 1 X
0 X
0 1
C C C C
s 1 X
0 1 t s 1 X
0X1 0 t
C C C C
0 X
0 1 1 X
0 X
0 1
2 2
28
Choosing Good Augmenting Paths
29
Capacity Scaling
4 4
s 1 t s t
2 2
Gf Gf (100)
30
Capacity Scaling
31
Capacity Scaling: Correctness
Integrality invariant. All flow and residual capacity values are integral.
32
Capacity Scaling: Running Time
Lemma 2. Let f be the flow at the end of a -scaling phase. Then the
value of the maximum flow is at most v(f) + m . proof on next slide
Theorem. The scaling max-flow algorithm finds a max flow in O(m log C)
augmentations. It can be implemented to run in O(m2 log C) time.
33
Capacity Scaling: Running Time
Lemma 2. Let f be the flow at the end of a -scaling phase. Then value
of the maximum flow is at most v(f) + m .
Pf. (almost identical to proof of max-flow min-cut theorem)
We show that at the end of a -phase, there exists a cut (A, B)
such that cap(A, B) v(f) + m .
Choose A to be the set of nodes reachable from s in Gf().
By definition of A, s A.
By definition of f, t A.
A B
v( f ) = f (e) − f (e)
e out of A e in to A t
(c(e) − ) −
e out of A e in to A
= c(e) − −
s
e out of A e out of A e in to A
cap(A, B) - m
original network
34
7.5 Bipartite Matching
Matching
Matching.
Input: undirected graph G = (V, E).
M E is a matching if each node appears in at most edge in M.
Max matching: find a max cardinality matching.
36
Bipartite Matching
Bipartite matching.
Input: undirected, bipartite graph G = (L R, E).
M E is a matching if each node appears in at most edge in M.
Max matching: find a max cardinality matching.
1 1'
2 2' matching
1-2', 3-1', 4-5'
3 3'
4 4'
L 5 5' R
37
Bipartite Matching
Bipartite matching.
Input: undirected, bipartite graph G = (L R, E).
M E is a matching if each node appears in at most edge in M.
Max matching: find a max cardinality matching.
1 1'
3 3'
4 4'
L 5 5' R
38
Bipartite Matching
G' 1 1'
1 1
2 2'
s 3 3' t
4 4'
L 5 5' R
39
Bipartite Matching: Proof of Correctness
1 1' 1 1'
1 1
2 2' 2 2'
3 3' s 3 3' t
4 4' 4 4'
G G'
5 5' 5 5'
40
Bipartite Matching: Proof of Correctness
1 1' 1 1'
1 1
2 2' 2 2'
s 3 3' t 3 3'
4 4' 4 4'
G' G
5 5' 5 5'
41
Bipartite Matching: Running Time
Non-bipartite matching.
Structure of non-bipartite graphs is more complicated, but
well-understood. [Tutte-Berge, Edmonds-Galai]
Blossom algorithm: O(n4). [Edmonds 1965]
Best known: O(m n1/2). [Micali-Vazirani 1980]
42