principle of algorithms x -...
TRANSCRIPT
![Page 1: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/1.jpg)
Algorithm Design and ImplementationPrinciple of Algorithms X
Network Flow I
Guoqiang Li
School of Software, Shanghai Jiao Tong University
1
![Page 2: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/2.jpg)
Max-Flow and Min-Cut Problems
1
![Page 3: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/3.jpg)
A Flow network
A flow network is a tuple G = (V ,E , s, t, c).
• Diagraph (V ,E) with source s ∈ V and sink t ∈ V .
• Capacity c(e) > 0 for each e ∈ E .
Intuition. Material flowing through a transportation network, which originates
at source and is sent to sink.
2
![Page 4: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/4.jpg)
Minimum-cut problem
An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈B.
Definition
Its capacity is the sum of the capacities of the edges from A to B.
cap(A,B) =∑
e out of A
c(e)
Definition
3
![Page 5: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/5.jpg)
Minimum-cut problem
An st-cut (cut) is a partition (A,B) of the nodes with s ∈ A and t ∈B.
Definition
Its capacity is the sum of the capacities of the edges from A to B.
cap(A,B) =∑
e out of A
c(e)
Definition
4
![Page 6: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/6.jpg)
Minimum-cut problem
Min-cut problem. Find a cut of minimum capacity.
5
![Page 7: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/7.jpg)
Quiz 1
Which is the capacity of the given st-cut?
A. 11 (20 + 25− 8− 11− 9− 6)
B. 34 (8 + 11 + 9 + 6)
C. 45 (20 + 25)
D. 79 (20 + 25 + 8 + 11 + 9 + 6)
6
![Page 8: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/8.jpg)
Maximum-flow problem
An st-flow(flow) f is a function that satisfies:
• For each e ∈ E : 0 ≤ f (e) ≤ c(e)
• For each v ∈ V − {s, t}:∑
e in to v
f (e) =∑
e out of v
f (e)
Definition
7
![Page 9: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/9.jpg)
Maximum-flow problem
An st-flow(flow) f is a function that satisfies:
• For each e ∈ E : 0 ≤ f (e) ≤ c(e)
• For each v ∈ V − {s, t}:∑
e in to v
f (e) =∑
e out of v
f (e)
Definition
The value of a flow f is: val(f ) =∑
e out of s
f (e)−∑
e in to s
f (e)
Definition
8
![Page 10: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/10.jpg)
Maximum-flow problem
Max-flow problem. Find a flow of maximum value.
9
![Page 11: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/11.jpg)
Ford-Fulkerson Algorithm
9
![Page 12: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/12.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
10
![Page 13: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/13.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
11
![Page 14: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/14.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
12
![Page 15: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/15.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
13
![Page 16: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/16.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
14
![Page 17: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/17.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
15
![Page 18: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/18.jpg)
Toward a max-flow algorithm
Greedy algorithm.
• Start with f (e) = 0 for each 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.
16
![Page 19: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/19.jpg)
Why the greedy algorithm fails
Q. Why does the greedy algorithm fail?
A. Once greedy algorithm increases flow on an edge, it never decreases it.
Ex. Consider flow network G .
• The unique max flow has f ∗(v ,w) = 0.
• Greedy algorithm could choose s → v → w → t as first augmenting path.
Bottom line. Need some mechanism to undo a bad decision.
17
![Page 20: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/20.jpg)
Residual network
Original edge e = (u, v) ∈ E .
• Flow f (e).
• Capacity c(e)
Reverse edge e reverse = (v , u)
• Undo flow sent.
Residual capacity
cf (e) =
{c(e)− f (e) if e ∈ E
f (e) if e reverse ∈ E
Residual network Gf = (V ,Ef , s, t, cf )
• Ef = {e : f (e) < c(e)} ∪ {e reverse : f (e) > 0}.
• Key property: f ′ is a flow in Gf iff f + f ′ is a flow in G
18
![Page 21: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/21.jpg)
Augmenting path
An augmenting path is a simple s t path in the residual network Gf .
Definition
The bottleneck capacity of an augmenting path P is the minimum
residual capacity of any edge in P.
Definition
19
![Page 22: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/22.jpg)
Augmenting path
Key Property. Let f be a flow and let P be an augmenting path in Gf . After
calling f ′ ← Augment(f , c,P), the resulting f ′ is a flow and
val(f ′) = val(f ) + bottleneck(Gf ,P).
Augment(f ,c,P)
δ ← bottleneck capacity of augmenting path P;
for each edge e ∈ P do
if (e ∈ E) then f (e)← f (e) + δ;
elsef (e reverse )← f (e reverse )− δ
end
end
Return f ;
20
![Page 23: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/23.jpg)
Network flow: quiz 2
Which is the augmenting path of highest bottleneck capacity?
1. A→ F → G → H
2. A→ B → C → D → H
3. A→ F → B → G → H
4. A→ F → B → G → C → D → H
21
![Page 24: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/24.jpg)
Ford–Fulkerson algorithm
Ford–Fulkerson augmenting path algorithm.
• Start with f (e) = 0 for each edge e ∈ E .
• Find an s t path P in the residual network Gf .
• Augment flow along path P.
• Repeat until you get stuck.
Ford–Fulkerson(G)
for each edge e ∈ E dof (e)← 0
end
Gf ← residual network of G with respect to flow f ;
while there exists an s t path P in Gf do
f ← Augment(f ,c,P);
Update(Gf );
end
Return f ;
22
![Page 25: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/25.jpg)
Max-Flow Min-Cut Theorem
22
![Page 26: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/26.jpg)
Relationship between flows and cuts
Let f be any flow and let (A,B) be any cut. Then, the value of the
flow f equals the net flow across the cut (A,B).
val(f ) =∑out of A
f (e)−∑
e in to A
f (e)
Lemma
23
![Page 27: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/27.jpg)
Relationship between flows and cuts
Let f be any flow and let (A,B) be any cut. Then, the value of the
flow f equals the net flow across the cut (A,B).
val(f ) =∑out of A
f (e)−∑
e in to A
f (e)
Lemma
24
![Page 28: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/28.jpg)
Relationship between flows and cuts
Let f be any flow and let (A,B) be any cut. Then, the value of the
flow f equals the net flow across the cut (A,B).
val(f ) =∑out of A
f (e)−∑
e in to A
f (e)
Lemma
25
![Page 29: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/29.jpg)
Network flow: quiz 3
Which is the net flow across the given cut?
1. 11 (20 + 25− 8− 11− 9− 6)
2. 26 (20 + 22− 8− 4− 4)
3. 42 (20 + 22)
4. 45 (20 + 25)
26
![Page 30: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/30.jpg)
Relationship between flows and cuts
Let f be any flow and let (A,B) be any cut. Then, the value of the
flow f equals the net flow across the cut (A,B).
val(f ) =∑out of A
f (e)−∑
e in to A
f (e)
Lemma
Proof.
val(f ) =∑
e out of s
f (e)−∑
e in to s
f (e)
=∑v∈A
( ∑e out of v
f (e)−∑
e in to v
f (e)
)=
∑e out of A
f (e)−∑
e in to A
f (e).
27
![Page 31: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/31.jpg)
Relationship between flows and cuts
Weak Duality Let f be any flow and (A,B) be any cut. Then, val(f ) ≤cap(A,B).
Theorem
Proof.val(f ) =
∑e out of A
f (e)−∑
e in to A
f (e)
≤∑
e out of A
f (e)
≤∑
e out of A
c(e)
= cap(A,B)
28
![Page 32: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/32.jpg)
Certificate of optimality
Let f be a flow and let (A,B) be any cut. If val(f ) = cap(A,B), then
f is a max flow and (A,B) is a min cut.
Corollary
Proof.• For any flow f ′ : val (f ′) ≤ cap(A,B) = val(f ).
• For any cut (A′,B ′) : cap (A′,B ′) ≥ val(f ) = cap(A,B)
29
![Page 33: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/33.jpg)
Max-flow min-cut theorem
Value of a max flow = capacity of a min cut.
Max-Flow Min-Cut Theorem
30
![Page 34: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/34.jpg)
Max-flow min-cut theorem
Value of a max flow = capacity of a min cut.
Max-Flow Min-Cut Theorem
A flow f is a max flow iff no augmenting paths.
Augmenting path theorem
Proof. The following three conditions are equivalent for any flow f :
i. There exists a cut (A,B) such that cap(A,B) = val(f ).
ii. f is a max flow.
iii. There is no augmenting path with respect to f .
[i⇒ ii] This is the weak duality corollary.
31
![Page 35: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/35.jpg)
Max-flow min-cut theorem
Value of a max flow = capacity of a min cut.
Max-Flow Min-Cut Theorem
A flow f is a max flow iff no augmenting paths.
Augmenting path theorem
Proof. The following three conditions are equivalent for any flow f :
i. There exists a cut (A,B) such that cap(A,B) = val(f ).
ii. f is a max flow.
iii. There is no augmenting path with respect to f .
[ii⇒ iii] We prove contrapositive: ¬ iii ⇒ ¬ii.
• Suppose that there is an augmenting path with respect to f .
• Can improve flow f by sending flow along this path.
• Thus, f is not a max flow.
32
![Page 36: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/36.jpg)
Max-flow min-cut theorem
[ iii ⇒ i ]
• Let f be a flow with no augmenting paths.
• Let A be set of nodes reachable from s in residual network Gf .
• By definition of A : s ∈ A.
• By definition of flow f : t /∈ A.
val(f ) =∑
e out of A
f (e)−∑
e in to A
f (e)
=∑
e out of A
c(e)− 0
= cap(A,B)
33
![Page 37: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/37.jpg)
Capacity-Scaling Algorithm
33
![Page 38: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/38.jpg)
Analysis of Ford–Fulkerson algorithm (when capacities are integral)
Assumption. Every edge capacity c(e) is an integer between 1 and C .
Integrality invariant. Throughout Ford-Fulkerson, every edge flow f (e) and
residual capacity cf (e) is an integer.
Proof. By induction on the number of augmenting paths.
Ford–Fulkerson terminates after at most val (f ∗) ≤ nC
augmenting paths, where f ∗ is a max flow.
Theorem
Proof. Each augmentation increases the value of the flow by at least 1.
34
![Page 39: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/39.jpg)
Analysis of Ford–Fulkerson algorithm (when capacities are integral)
The running time of Ford–Fulkerson is O(mnC).
Corollary
Proof. Can use either BFS or DFS to find an augmenting path in O(m) time.
There exists an integral max flow f ∗Integrality Theorem
Proof. Since Ford–Fulkerson terminates, theorem follows from integrality
invariant.
35
![Page 40: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/40.jpg)
Ford–Fulkerson: exponential example
Q. Is generic Ford–Fulkerson algorithm poly-time in input size?
A. No. If max capacity is C , then algorithm can take ≥ C iterations.
• s → v → w → t
• s → w → v → t
• s → v → w → t
• s → w → v → t
• . . .
• s → v → w → t
• s → w → v → t
36
![Page 41: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/41.jpg)
Network flow: quiz 4
The Ford–Fulkerson algorithm is guaranteed to terminate if the edge
capacities are . . .
A. Rational numbers.
B. Real numbers.
C. Both A and B.
D. Neither A nor B.
37
![Page 42: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/42.jpg)
Choosing good augmenting paths
Use care when selecting augmenting paths.
• Some choices lead to exponential algorithms.
• Clever choices lead to polynomial algorithms.
Pathology. When edge capacities can be irrational, no guarantee that
Ford–Fulkerson terminates (or converges to a maximum flow)!
Goal. Choose augmenting paths so that:
• Can find augmenting paths efficiently.
• Few iterations.
38
![Page 43: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/43.jpg)
Choosing good augmenting paths
Choose augmenting paths with:
• Max bottleneck capacity(“fattest”).
• Sufficiently large bottleneck capacity.
• Fewest edges.
39
![Page 44: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/44.jpg)
Capacity-scaling algorithm
Overview. Choosing augmented paths with large bottleneck capacity.
• Maintain scaling parameter ∆.
• Let Gf (∆) be the part of the residual network containing only those
edges with capacity ≥ ∆.
• Any augmenting path in Gf (∆) has bottleneck capacity ≥ ∆.
40
![Page 45: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/45.jpg)
Capacity-scaling algorithm
Capacity-Scaling(G)
for each edge e ∈ E dof (e)← 0
end
∆← largest power of 2 ≤ C ;
while ∆ ≥ 1 do
Gf (∆)← ∆-residual network of G with respect to flow f ;
while there exists an s t path P in Gf (∆) do
f ← Augment(f , c, P);
Update(G∆(f ));
end
∆ = ∆/2;
end
Return f ;
41
![Page 46: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/46.jpg)
Capacity-scaling algorithm: proof of correctness
Assumption. All edge capacities are integers between 1 and C .
Invariant. The scaling parameter ∆ is a power of 2.
Proof. Initially a power of 2; each phase divides ∆ by exactly 2.
Integrality invariant. Throughout the algorithm, every edge flow f (e) and
residual capacity cf (e) is an integer.
Proof. Same as for generic Ford–Fulkerson.
42
![Page 47: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/47.jpg)
Capacity-scaling algorithm: proof of correctness
If capacity-scaling algorithm terminates, then f is a max flow.
Theorem
Proof.
• By integrality invariant, when ∆ = 1 ⇒ Gf (∆) = Gf
• Upon termination of ∆ = 1 phase, there are no augmenting paths.
• Result follows augmenting path theorem.
43
![Page 48: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/48.jpg)
Capacity-scaling algorithm: analysis of running time
There are 1 + blog2 Cc scaling phases.
Lemma 1
There are ≤ 2m augmentations per scaling phase.
Lemma 2
Let f be the flow at the end of a ∆-scaling phase.
Then, the max-flow value ≤ val(f ) + m∆.
Lemma 3
44
![Page 49: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/49.jpg)
Capacity-scaling algorithm: analysis of running time
The capacity-scaling algorithm takes O(m2logC) time.
Theorem
Proof.
• Lemma 1+ Lemma 2 ⇒ O(m log C) augmentations.
• Finding an augmenting path takes O(m) time.
45
![Page 50: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/50.jpg)
Capacity-scaling algorithm: analysis of running time
There are 1 + blog2 Cc scaling phases.
Lemma 1
Proof. Initially C/2 < ∆ ≤ C ; ∆ decreases by a factor of 2 in each iteration.
46
![Page 51: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/51.jpg)
Capacity-scaling algorithm: analysis of running time
There are ≤ 2m augmentations per scaling phase.
Lemma 2
Proof.
• Let f be the flow at the beginning of a ∆-scaling phase.
• Lemma 3 ⇒ max-flow value ≤ val(f ) + m(2∆).
• Each augmentation in a ∆-phase increases val(f ) by at least ∆.
47
![Page 52: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/52.jpg)
Capacity-scaling algorithm: analysis of running time
Let f be the flow at the end of a ∆-scaling phase.
Then, the max-flow value ≤ val(f ) + m∆.
Lemma 3
Proof.• We show there exists a cut (A,B) such that cap(A,B) ≤ val(f ) + m∆.
• Choose A to be the set of nodes reachable from s in Gf (∆).
• By definition of A : s ∈ A.
• By definition of flow f : t /∈ A.
val(f ) =∑
e out of A
f (e)−∑
e in to A
f (e)
≥∑
e out of A
(c(e)− ∆)−∑
e in to A
∆
≥∑
e out of A
c(e)−∑
e out of A
∆−∑
e in to A
∆
≥ cap(A,B)−m∆
48
![Page 53: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/53.jpg)
Shortest Augmenting Paths
48
![Page 54: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/54.jpg)
Shortest augmenting path
Q. How to choose next augmenting path in Ford–Fulkerson?
A. Pick one that uses the fewest edges.
Shortest-Augmenting-Path(G)
for each edge e ∈ E dof (e)← 0
end
Gf ← residual network of G with respect to flow f ;
while there exists an s t path in Gf do
P ← BFS((Gf ));
f ← Augment(f , c, P);
Update(Gf );
end
Return f ;
49
![Page 55: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/55.jpg)
Shortest augmenting path: overview of analysis
The length of a shortest augmenting path never decreases.
Lemma 1
After at most m shortest-path augmentations, the length of a shortest
augmenting path strictly increases.
Lemma 2
The shortest-augmenting-path algorithm takes O(m2n) time.
Theorem
Proof.
• O(m) time to find a shortest augmenting path via BFS.
• There are ≤ mn augmentations
- at most m augmenting paths of length k ←− Lemma 1 + Lemma 2
- at most n − 1 different lengths
50
![Page 56: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/56.jpg)
Shortest augmenting path: analysis
Given a digraph G = (V ,E) with source s, its level graph is defined by:
• `(v) = number of edges in shortest s v path.
• LG = (V ,EG ) is the subgraph of G that contains only those edges
(v ,w) ∈ E with `(w) = `(v) + 1.
Definition
51
![Page 57: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/57.jpg)
Network flow: quiz 5
Which edges are in the level graph of the following digraph?
A. D → F
B. E → F
C. Both A and B.
D. Neither A nor B.
52
![Page 58: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/58.jpg)
Shortest augmenting path: analysis
Given a digraph G = (V ,E) with source s, its level graph is defined by:
• `(v) = number of edges in shortest s v path.
• LG = (V ,EG ) is the subgraph of G that contains only those edges
(v ,w) ∈ E with `(w) = `(v) + 1.
Definition
Key property. P is a shortest s v path in G iff P is an s v path in LG .
53
![Page 59: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/59.jpg)
Shortest augmenting path: analysis
The length of a shortest augmenting path never decreases.
Lemma 1
Proof.
• Let f and f ′ be flow before and after a shortest-path augmentation.
• Let LG and LG ′ be level graphs of Gf and Gf ′ .
• Only back edges added to Gf ′
(any s t path that uses a back edge is longer than previous length)
54
![Page 60: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/60.jpg)
Shortest augmenting path: analysis
After at most m shortest-path augmentations, the length of a shortest
augmenting path strictly increases.
Lemma 2
Proof.
• At least one (bottleneck) edge is deleted from LG per augmentation.
• No new edge added to LG until shortest path length strictly increases.
55
![Page 61: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/61.jpg)
Shortest augmenting path: review of analysis
The length of a shortest augmenting path never decreases.
Lemma 1
After at most m shortest-path augmentations, the length of a shortest
augmenting path strictly increases.
Lemma 2
The shortest-augmenting-path algorithm takes O(m2n) time.
Theorem
56
![Page 62: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/62.jpg)
Shortest augmenting path: improving the running time
Note. Θ(mn) augmentations necessary for some flow networks.
• Try to decrease time per augmentation instead.
• Simple idea ⇒ O(mn2) [Dinitz 1970]
• Dynamic trees ⇒ O(mn log n) [Sleator–Tarjan 1983]
57
![Page 63: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/63.jpg)
Augmenting-path algorithms: summary
year method # augmentations running time
1955 augmenting path nC O(mnC)
1972 fattest path m log(mC) O(m2 log n log(mC)
)1972 capacity scaling m logC O
(m2 logC
)1985 improved capacity scaling m logC O(mn logC)
1970 shortest augmenting path mn O(m2n
)1970 level graph mn O
(mn2
)1983 dynamic trees mn O(mn log n)
augmenting-path algorithms with m edges, n nodes, and integer capacities between 1 and C
58
![Page 64: Principle of Algorithms X - SJTUbasics.sjtu.edu.cn/~liguoqiang/teaching/SE121/lectures/hand10.pdf · Minimum-cut problem An st-cut (cut)is a partition (A;B) of the nodes with s 2A](https://reader033.vdocument.in/reader033/viewer/2022050213/5f5fc08b1e5326581b3aae09/html5/thumbnails/64.jpg)
Maximum-flow algorithms: theory highlights
year method worst case discovered by
1951 simplex O(mn2C
)Dantzig
1955 augmenting paths O(mnC) Ford–Fulkerson
1970 shortest augmenting paths O(mn2
)Edmonds–Karp, Dinitz
1974 blocking flows O(n3)
Karzanov
1983 dynamic trees O(mn log n) Sleator–Tarjan
1985 improved capacity scaling O(mn logC) Gabow
1988 push–relabel O(mn log
(n2/m
))Goldberg–Tarjan
1998 binary blocking flows O(m3/2 log
(n2/m
)logC
)Goldberg–Rao
2013 compact networks O(mn) Orlin
2014 interior-point methods O(mm1/2 logC
)Lee–Sidford
2016 electrical flows O(m10/7C1/7
)Madry
20xx ???
augmenting-path algorithms with m edges, n nodes, and integer capacities between 1 and C
59