Network Flow: Slides by Kevin Wayne. All Rights Reserved
Network Flow: Slides by Kevin Wayne. All Rights Reserved
Network Flow
Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Reference: On the history of the transportation and maximum flow problems. Alexander Schrijver in Math Programming, 91: 3, 2002.
2
Two very rich algorithmic problems. Cornerstone problems in combinatorial optimization. Beautiful mathematical duality.
Data mining. Open-pit mining. Project selection. Airline scheduling. Bipartite matching. Baseball elimination. Image segmentation. Network connectivity.
Network reliability. Distributed computing. Egalitarian stable matching. Security of statistical data. Network intrusion detection. Multi-camera scene reconstruction. Many many more
10
15
15
10
source
10
sink
capacity
15
15
10
30
7
4
Cuts
Def. An s-t cut is a partition (A, B) of V with s A and t B. Def. The capacity of a cut (A, B) is:
cap( A, B) = " c(e)
e out of A
!
2 9 5
10
15
15
10
s A
10
15
15
10 Capacity = 10 + 5 + 15 = 30
5
30
Cuts
Def. An s-t cut is a partition (A, B) of V with s A and t B. Def. The capacity of a cut (A, B) is:
cap( A, B) = " c(e)
e out of A
!
2 9 5
10
15
15
10
s A
10
15
15
10 Capacity = 9 + 15 + 8 + 30 = 62
6
30
10
15
15
10
10
15
15
10 Capacity = 10 + 8 + 10 = 28
7
30
Flows
Def. An s-t flow is a function that satisfies: For each e E: 0 " f (e) " c(e) For each v V {s, t}: " f (e) = " f (e)
[capacity] [conservation]
e in to v
e out of v
e out of s
" f (e) .
!
0 4 10 0 s 5 3
9 0 15 4 8 0
5 0 15 0 10 4 6 10 0 10 t
4 4
capacity flow
15 0
4 0
6 0
15 0
30
Value = 4
8
Flows
Def. An s-t flow is a function that satisfies: For each e E: 0 " f (e) " c(e) For each v V {s, t}: " f (e) = " f (e)
[capacity] [conservation]
e in to v
e out of v
e out of s
" f (e) .
!
6 10 10 3 s 5 3
9 0 15 8 8 1
5 6 15 0 10 8 6 10 10 10 t
4 4
capacity flow
15 11
4 0
6 11
15 0
30
Value = 24
9
9 2 10 10 4 s 5 3 4 0 9 1 15 8 8 4 6 5 9 15 0 10 9 10 10 10 t
capacity flow
15 14
4 0
6 14
15 0
30
Value = 28
10
!
2 10 10 3 s A 15 11 4 4 0 5 3 4 4
6 9 0 15 8 8 1 6 11 30 7 15 0 6 5 6 15 0 10 8 10 10 10 t
Value = 24
11
!
2 10 10 3 s A 15 11 4 4 0 5 3 4 4
6 9 0 15 8 8 1 6 11 30 7 15 0 6 5 6 15 0 10 8 10 10 10 Value = 6 + 0 + 8 - 1 + 11 = 24
12
!
2 10 10 3 s A 15 11 4 4 0 5 3 4 4
6 9 0 15 8 8 1 6 11 30 7 15 0 6 5 6 15 0 10 8 10 10 10 Value = 10 - 4 + 8 - 0 + 10 = 24
13
Pf.
!
by flow conservation, all terms except v = s are 0
v( f ) = =
" f (e)
e out of s
% ( " ' " f (e) $ " f (e)* ) v # A & e out of v e in to v " f (e) $ " f (e).
e out of A e in to A
14
Cut capacity = 30
Flow value 30
10
15
15
10
s A
10
15
15
10
30
Capacity = 30
15
v( f ) = $ $
4 8
B
t
" f (e)
e out of A
" c(e)
e out of A
7 6
= cap(A, B)
16
Certificate of Optimality
Corollary. Let f be any flow, and let (A, B) be any cut. If v(f) = cap(A, B), then f is a max flow and (A, B) is a min cut.
Value of flow = 28 Cut capacity = 28
Flow value 28
9 2 10 10 4 s 5 3 4 0 9 1 15 8 8 4 6 5 9 15 0 10 9 10 10 10 t
15 14
4 0
6 14
15 0
30
7
17
0 20
0 10
30 0
10 0
2
20 0
Flow value = 0
18
20 X 0 20
0 10
30 X 20 0
10 0
2
20
X 20 0
Flow value = 20
19
20 20
s
0 10 30 20
t s
20 20 30 10
10 10
t
10 0
20 20
2
10 10
20 20
2
20
greedy = 20
opt = 30
Residual Graph
Original edge: e = (u, v) E. Flow f(e), capacity c(e).
capacity
17 6
flow
Residual edge. "Undo" flow sent. e = (u, v) and eR = (v, u). Residual capacity:
residual capacity
11 6
v
residual capacity
21
Ford-Fulkerson Algorithm
4 8
G:
10
s
capacity 10 10
t
2
3
10
22
Ford-Fulkerson(G, s, t, c) { foreach e E f(e) 0 Gf residual graph while (there exists augmenting path P) { f Augment(f, c, P) update Gf } return f }
23
24
v( f ) = =
" c(e)
e out of A
B
t
= cap(A, B)
s
!
original network
25
Running Time
Assumption. All capacities are integers between 1 and C. Invariant. Every flow value f(e) and every residual capacity cf (e) remains an integer throughout the algorithm. Theorem. The algorithm terminates in at most v(f*) nC iterations. Pf. Each augmentation increase value by at least 1. Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time. Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer. Pf. Since algorithm terminates, theorem follows from invariant.
26
0 X C
0 C 1 X 1 0
t s
X 0
C 1 XX0 0 1
0 X 1 C
t
C 0
2
C 0 X 1
C 0 1 X
2
X 1 0
28
Goal: choose augmenting paths so that: Can find augmenting paths efficiently. Few iterations.
Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970] Max bottleneck capacity. Sufficiently large bottleneck capacity. Fewest number of edges.
29
Capacity Scaling
Intuition. Choosing path with highest bottleneck capacity increases flow by max possible amount. Don't worry about finding exact highest bottleneck path. Maintain scaling parameter . Let Gf () be the subgraph of the residual graph consisting of only arcs with capacity at least .
110
s
102 1
t s
110
102
t
122
2
170
122
2
170
Gf
Gf (100)
30
Capacity Scaling
Scaling-Max-Flow(G, s, t, c) { foreach e E f(e) 0 smallest power of 2 greater than or equal to C Gf residual graph while ( 1) { Gf() -residual graph while (there exists augmenting path P in Gf()) { f augment(f, c, P) update Gf() } / 2 } return f }
31
32
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
v( f ) = $ =
B
t
%
e in to A
" c(e) #
e out of A
" % # "%
e out of A
$ cap(A, B) - m%
original network
34