CS 401
Max Flow
Xiaorui Sun
1
CS 401 Max Flow Xiaorui Sun 1 Stuff Homework 3 due today - - PowerPoint PPT Presentation
CS 401 Max Flow Xiaorui Sun 1 Stuff Homework 3 due today Homework 4 will be out soon Flow network Flow network. G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e. 9
Xiaorui Sun
1
G = (V, E) = directed graph, no parallel edges. Two distinguished nodes: s = source, t = sink. c(e) = capacity of edge e.
s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4
capacity source sink
s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 Capacity = 10 + 5 + 15 = 30 A
5
s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 A Capacity = 10 + 8 + 10 = 28
6
For each e Î E: (capacity) For each v Î V – {s, t}: (conservation)
4 4 4
Value = 4 capacity flow
s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 4
7
10 9 9 14 4 10 4 8 9 1 14
capacity flow
s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4
Value = 28
8
10 6 6 1 10 3 8 8 11 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4 Value = 6 + 0 + 8 - 1 + 11 = 24 4 11 A
Cut capacity = 28 Þ Flow value £ 28
10 9 9 14 4 10 4 8 9 1 14 s 2 3 4 5 6 7 t 15 5 30 15 10 8 15 9 6 10 10 10 15 4 4
A
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.
s 1 2 t
10 10 20 20 30
Flow value = 0
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.
s 1 2 t
20
Flow value = 20
10 10 20 30
X X X
20 20 20
12
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 = 20
s 1 2 t
20 10 10 20 30 20 20 20
s 1 2 t
20 10 10 20 30 20 10 10 10 20 locally optimality Þ global optimality
Flow f(e), capacity c(e).
"Undo" flow sent. e = (u, v) and eR = (v, u). Residual capacity:
Residual edges with positive residual capacity. Ef = {e : f(e) < c(e)} È {eR : c(e) > 0}. u v 17 6
capacity
u v 11
residual capacity
6
residual capacity flow
14
Original graph
s 1 2 t
20 10 10 20 30 20 20 20
Residual graph
s 1 2 t
10 10 20 10 20 20
15
Original graph
s 1 2 t
20 10 10 20 30 20 20 20
Residual graph
s 1 2 t
10 10 20 10 20 20
16
Original graph
s 1 2 t
20 10 10 20 30 20 10 10 10 20
Residual graph
s 1 2 t
10 10 20 10 20 20
17
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2
G:
Flow value = 0 flow capacity
18
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2
G:
s 2 3 4 5 t
10 9 4 10 6 2
Gf:
10 8 10 8 8 8 X X X Flow value = 0 capacity residual capacity flow
19
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 8 8 8
G:
s 2 3 4 5 t
10 4 10 6
Gf:
8 8 8 9 2 2 2 10 2 10 X X X 2 X Flow value = 8
20
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 10 2 10 8 2
G:
s 2 3 4 5 t
4 2
Gf:
10 8 10 2 10 7 10 6 X 6 6 6 X X 8 X Flow value = 10
21
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 10 6 6 8 10 8 2
G:
s 2 3 4 5 t
1 6
Gf:
10 8 10 8 6 6 6 4 4 4 2 X 8 2 8 X X X Flow value = 16
22
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 10 2 8 8 8 10 8
G:
s 2 3 4 5 t
6 2
Gf:
10 10 8 6 8 8 2 2 1 2 8 2 X 9 7 9 X X 9 X X 3 Flow value = 18
23
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7
G:
s 2 3 4 5 t
1 9 1 1 6 2
Gf:
10 7 10 6 9 9 3 1 Flow value = 19
24
Ford-Fulkerson Algorithm
s 2 3 4 5 t
10 10 9 8 4 10 10 6 2 10 3 9 9 9 10 7
G:
s 2 3 4 5 t
1 9 1 1 6 2
Gf:
10 7 10 6 9 9 3 1 Flow value = 19 Cut capacity = 19
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 } 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 }
forward edge reverse edge
(i) There exists a cut (A, B) such that v(f) = cap(A, B). (ii) Flow f is a max flow. (iii) There is no augmenting path relative to f.
Let f be a flow. If there exists an augmenting path, then we can improve f by sending flow along path.
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.
s t
A B
s 1 2 t
C C C C 1
s 1 2 t
C C 1
X 1
C C
X X X
1 1 1
X X
1 1
X X X
1 1
m, n, and log C
Some choices lead to exponential algorithms. Clever choices lead to polynomial algorithms. If capacities are irrational, algorithm not guaranteed to terminate!
Can find augmenting paths efficiently. Few iterations.
Sufficiently large bottleneck capacity. Fewest number of edges.
How to find exact highest bottleneck path? Homework 4 Maintain scaling parameter D. Let Gf (D) be the subgraph of the residual graph consisting of only arcs with capacity at least D.
110
s 4 2 t
1 170 102 122 Gf 110
s 4 2 t
170 102 122 Gf (100)
Scaling-Max-Flow(G, s, t, c) { foreach e Î E f(e) ¬ 0 D ¬ smallest power of 2 greater than or equal to C Gf ¬ residual graph while (D ³ 1) { Gf(D) ¬ D-residual graph while (there exists augmenting path P in Gf(D)) { f ¬ augment(f, c, P) update Gf(D) } D ¬ D / 2 } return f }
By integrality invariant, when D = 1 Þ Gf(D) = Gf. Upon termination of D = 1 phase, there are no augmenting paths. ▪
Lemma 1. The outer while loop repeats 1 + élog2 Cù times.
Lemma 2. Let f be the flow at the end of a D-scaling phase. Then the value of the maximum flow is at most v(f) + m D. Lemma 3. There are at most 2m augmentations per scaling phase. Let f be the flow at the end of the previous scaling phase. L2 Þ v(f*) £ v(f) + m (2D). Each augmentation in a D-phase increases v(f) by at least D. ▪
log C) augmentations. It can be implemented to run in O(m2 log C)
proof on next slide
We show that at the end of a D-phase, there exists a cut (A, B) such that cap(A, B) £ v(f) + m D. Choose A to be the set of nodes reachable from s in Gf(D). By definition of A, s Î A. By definition of f, t Ï A.
s t
A B
37