Professional Documents
Culture Documents
7. Network Flow
Data mining.
Open-pit mining.
Project selection.
Airline scheduling.
Bipartite matching.
Baseball elimination.
Image segmentation.
Network reliability.
15
15
10
10
15
30
Distributed computing.
Egalitarian stable matching.
10
source
Network connectivity.
capacity
15
sink
10
Cuts
Cuts
cap( A, B) =
" c(e)
cap( A, B) =
e out of A
10
" c(e)
e out of A
15
15
10
10
15
30
15
15
10
10
15
30
10
A
15
10
15
Capacity = 10 + 5 + 15
= 30
10
Capacity = 9 + 15 + 8 + 30
= 62
Flows
(capacity)
(conservation)
e in to v
e out of v
" f (e) .
e out of s
!
0
2
5
4
10
4 4
0
15
15
4 0
30
15
15
10
10
15
30
10
0
5
0
0
4
6
0
A
15
10
Capacity = 10 + 8 + 10
= 28
7
capacity
15
flow
10
15 0
0
7
10
0
10
Value = 4
8
Flows
e in to v
e out of v
" f (e) .
e out of s
!
6
2
10
10
4 4
0
15
4 0
30
3
5
9
5
15
15
flow
11
10
10
10
4 0
1
15
15
8
6
10
capacity
15 0
capacity
15
flow
14
Value = 24
4 0
30
10
9
8
6
10
10
10
11
9
0
15 0
10
10
14
Value = 28
10
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.
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.
e out of A
e out of A
6
2
10
10
4 4
0
15
3
s
e in to A
15
30
11
10
10
10
15 0
11
7
4 4
0
15
15
4 0
30
8
6
1
4 0
15
10
10
11
11
10
8
1
15
Value = 24
6
0
10
e in to A
15 0
11
7
10
10
10
Value = 6 + 0 + 8 - 1 + 11
= 24
12
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.
Flow value lemma. Let f be any flow, and let (A, B) be any s-t cut. Then
e out of A
e in to A
6
9
4 4
0
15
15
2
10
10
3
s
6
0
1
15
4 0
11
15 0
30
10
10
A
Value = 10 - 4 + 8 - 0 + 10
= 24
t
v
10
11
4
e in to v
e out of v
10
A'
s
Before
13
After
14
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.
Weak duality. Let f be any flow. Then, for any s-t cut (A, B) we have
v(f) % cap(A, B).
Pf.
Cut capacity = 30 $
Flow value % 30
v( f ) =
e out of A
10
15
15
15
30
4
8
e in to A
B
t
" f (e)
e out of A
10
" c(e)
e out of A
10
= cap( A, B)
7
6
A
15
!
10
Capacity = 30
15
16
Certificate of Optimality
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.
!
Value of flow = 28
Cut capacity = 28 $
Flow value % 28
9
2
1
15
10
10
4
5
5
9
15
8
8
15
4 0
14
10
15 0
10
30
0
10
30 0
10
10
14
4
0
20
10
20
Flow value = 0
7
17
18
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.
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
20
10
30 X
0 20
20
20
t
10
20
X
0 20
0
10
greedy = 20
2
19
20
20
t
30 20
10
0
Flow value = 20
20
20
2
10
10
10
10
opt = 30
30 10
20
20
2
20
Residual Graph
Original edge: e = (u, v) ! E.
Flow f(e), capacity c(e).
!
Ford-Fulkerson Algorithm
capacity
flow
s
10
10
10
10
capacity
G:
Residual edge.
"Undo" flow sent.
e = (u, v) and eR = (v, u).
Residual capacity:
17
residual capacity
11
6
residual capacity
21
22
(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 ) =
e out of A
e in to A
" c(e)
B
t
e out of A
= cap( A, B)
original network
23
24
Running Time
Assumption. All capacities are integers between 1 and C.
Augment(f, c, P) {
b ' bottleneck(P)
foreach e ! P {
if (e ! E) f(e) ' f(e) + b
else
f(eR) ' f(e) - b
}
return f
}
Invariant. Every flow value f(e) and every residual capacities cf (e)
remains an integer throughout the algorithm.
forward edge
reverse edge
Ford-Fulkerson(G, s, t, c) {
foreach e ! E f(e) ' 0
Gf ' residual graph
26
0
X
1 X
0 1
0 1
X
2
X
0
0 1
X
C
1 X
0 X
1 0
X
0 1
0
1 X
2
28
Capacity Scaling
110
102
1
122
110
170
102
122
170
Gf
Gf (100)
29
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
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.
Lemma 2. Let f be the flow at the end of a (-scaling phase. Then the
proof on next slide
value of the maximum flow is at most v(f) + m (.
v( f ) =
e out of A
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. !
" c(e) #
e out of A
B
t
e in to A
e out of A
e in to A
" % # "%
e out of A
e in to A
$ cap(A, B) - m%
original network
33
34