algorithm design and analysis cse 565cs-people.bu.edu › sofya › cse565 › lecture-notes ›...
TRANSCRIPT
Sofya Raskhodnikova
Algorithm Design and Analysis
LECTURES 17Network Flow
•Duality of Max Flow and
Min Cut
•Algorithms:
•Ford-Fulkerson
•Capacity Scaling
S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L17.1
Network Flow
S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L17.2
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.
Minimum Cut Problem
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4
capacity
source sink
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:
Cuts
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4
Capacity = 10 + 5 + 15= 30
A
cap(A, B) c(e)e out of A
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4A
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
Capacity = 9 + 15 + 8 + 30= 62
we don’t count edges
into A
Min s-t cut problem. Find an s-t cut of minimum capacity.
Minimum Cut Problem
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4A
Capacity = 10 + 8 + 10= 28
Def. An s-t flow is a function that satisfies:
For each e E: (capacity)
For each v V – {s, t}: (conservation)
Def. The value of a flow f is:
Flows
4
0
0
0
0 0
0 4 4
0
0
0
Value = 40
f (e)e in to v
f (e)e out of v
0 f (e) c(e)
capacity
flow
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4 0
v( f ) f (e) e out of s
.
4
Water flowing in
and out of 𝑣
Max flow problem. Find s-t flow of maximum value.
Maximum Flow Problem
10
9
9
14
4 10
4 8 9
1
0 0
0
14
capacity
flow
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4 0
Value = 28
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.
Flows and Cuts
10
6
6
11
1 10
3 8 8
0
0
0
11
s
2
3
4
5
6
7
t
15
5
30
15
10
8
15
9
6 10
10
10154
4 0
Value = 24
f (e)e out of A
f (e)e in to A
v( f )
4
A
Weak duality. Let f be any flow. Then, for any s-t cut (A, B),
v(f) cap(A, B).
Proof.
▪
Flows and Cuts
v( f ) f (e)e out of A
f (e)e in to A
f (e)e out of A
c(e)e out of A
cap(A,B)
s
t
A B
7
6
8
4
Review Questions
True/False
Let G be an arbitrary flow network, with a source s, and sink t, and a positive integer capacity ce on every edge e.
1) If f is a maximum s-t flow in G, then f saturates every edge out of s with flow (i.e., for all edges e out of s, we have f(e) = ce).
2) Let (A,B) be a minimum s-t cut with respect to these capacities . If we add 1 to every capacity, then (A,B) is still a minimum s-t cut with respect to the new capacities.
Towards a Max Flow Algorithm
Greedy algorithm.
Start with f(e) = 0 for all edges 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
0 0
0 0
0
20
20
30
Flow value = 0
Towards a Max Flow Algorithm
Greedy algorithm.
Start with f(e) = 0 for all edges 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
0 0
0 0
0
X
X
X
20
20
20
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.
greedy = 20
s
1
2
t
20 10
10 20
30
20 0
0
20
20
opt = 30
s
1
2
t
20 10
10 20
30
20 10
10
10
20
locally optimality global optimality
How can we get from greedy to opt here? What if we push water back
across middle edge?
Residual Graph
Original edge: e = (u, v) E.
Flow f(e), capacity c(e).
Residual edge.
"Undo" flow sent.
e = (u, v) and eR = (v, u).
Residual capacity:
Residual graph: Gf = (V, Ef ).
Residual edges with positive residual capacity.
Ef = {e : f(e) < c(e)} {eR : c(e) > 0}.
u v17
6
capacity
u v11
residual capacity
6residual capacity
flow
c f (e) c(e) f (e) if e E
f (e) if eR E
Ford-Fulkerson Algorithm
s
2
3
4
5 t10
10
9
8
4
10
1062
G:capacity
16
Augmenting Path Algorithm
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
}
Augment(f, c, P) {
b bottleneck-capacity(P)
foreach e P {
if (e E) f(e) f(e) + b
else f(𝒆𝑹) f(𝒆𝑹) - b
}
return f
}
forward edge
reverse edge
Min residual capacity of an edge in P
Ford-Fulkerson: Analysis
Ford-Fulkerson summary:
• While you can,
• Greedily push flow
• Update residual graph
Lemma 1 (Feasibility): Ford-Fulkerson outputs a valid flow.
Proof: Check capacity and conservation conditions. (Details in KT)
Still to do:
• Optimality: Does it output a maximum flow?
• Running time (in particular, termination!)
Max-Flow Min-Cut Theorem
Augmenting path theorem. Flow f is a max flow iff there are no
augmenting paths.
Max-flow min-cut theorem. [Ford-Fulkerson 1956] The value of the
max flow is equal to the value of the min cut.
Proof strategy. We prove both simultaneously by showing that TFAE:
(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.
(i) (ii) This was the corollary to weak duality lemma.
(ii) (iii) We show contrapositive.
Let f be a flow. If there exists an augmenting path, then we can
improve f by sending flow along path.
Proof of Max-Flow Min-Cut Theorem
v( f ) f (e)e out of A
f (e)e in to A
c(e)e out of A
cap(A,B)
original network
s
t
A B
(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, source s A.
By definition of f, sink t A.
Observation: No edges of the residual graph go from A to B.
Claim 1: If e goes from A to B,
then f(e) =c(e).
Proof: Otherwise there would be
residual capacity, and the residual
graph would have an edge A to B.
Claim 2: If e goes from B to A,
then f(e)=0.
Proof: Otherwise residual edge
would go from A to B.
Ford-Fulkerson: Analysis
Ford-Fulkerson summary:
• While you can,
• Greedily push flow
• Update residual graph
Lemma 1 (Feasibility): Ford-Fulkerson outputs a valid flow.
Augmenting path theorem. Flow f is a max flow iff there are no
augmenting paths.
Optimality: If Ford-Fulkerson terminates then the output is a max flow.
Still to do:
• Running time (in particular, termination!)