Flow Networks

advertisement
Flow Networks
zichun@comp.nus.edu.sg
Formalization
Basic Results
Min-cut
Ford-Fulkerson
Edmunds-Karp
Bipartite Matching
Flow Network
• Directed Graph G = (V, E)
• Each edge 𝑒, 𝑣 ∈ 𝐸 has a capacity
– 𝑐 𝑒, 𝑣 ≥ 0
•
𝑒, 𝑣 ∉ 𝐸 ⇒ 𝑐 𝑒, 𝑣 = 0
Properties of Flow
π‘“π‘™π‘œπ‘€ 𝑖𝑛 𝐺 ≔ 𝑓 ∢ 𝑉 × π‘‰ → 𝐑
Capacity Constraint
∀𝑒, 𝑣 ∈ 𝑉 (𝑓 𝑒, 𝑣 ≤ 𝑐 𝑒, 𝑣 )
Skew Symmetry
∀𝑒, 𝑣 ∈ 𝑉 (𝑓 𝑒, 𝑣 = −𝑓 𝑣, 𝑒 )
Flow Conservation
∀𝑒 ∈ 𝑉 − {𝑠, 𝑑} ( 𝑒∈𝑉 𝑓 𝑒, 𝑣 = 0)
Maximum Flow
• π‘€π‘Žπ‘₯πΉπ‘™π‘œπ‘€ 𝐺 = 𝑉, 𝐸 , 𝑠 ∈ 𝑉, 𝑑 ∈ 𝑉
– ∀𝑣 ∈ 𝑉 ∃ π‘π‘Žπ‘‘β„Ž 𝑝 𝑠 → 𝑝 𝑣 → 𝑝 𝑑
– Returns Maximum Flow of G
Value of Flow
𝒇 =
𝑓 𝑠, 𝑣
𝑣∈𝑉
Motivating Problem
v1
16
10
s
12
4
v3
9
14
t
7
13
v2
20
v4
4
Motivating Problem
10
8/13
1/4
v2
4/9
11/14
v3
7/7
v1
11/16
s
12/12
v4
t
4/4
10
8/13
𝒇 =
1/4
v2
11/14
𝑓 𝑠, 𝑣 =
𝑣∈𝑉
= 19
4/9
v3
7/7
v1
11/16
s
12/12
v4
𝑓 𝑣, 𝑑
𝑣∈𝑉
t
4/4
Multiple Sources / Sinks
v1
16
s1
s2
13
4
12
10
4
v2
v3
9
14
7
v4
20
t1
4
4
t2
Multiple Sources / Sinks
v1
16
∞
s1
S
∞
s2
13
4
12
10
4
v2
v3
9
14
7
v4
20
t1
∞
t
4
4
t2
∞
Implicit Summation Notation
𝒇 𝑿, 𝒀 =
𝒇(𝒙, π’š)
𝒙∈𝑿 π’š∈𝒀
Key Equalities
Let G = (V, E) be a flow network, and let f be a
flow in G. Then
1. ∀𝑋 ⊂ 𝑉 𝑓 𝑋, 𝑋 = 0
2. ∀𝑋, π‘Œ ⊂ 𝑉 𝑓 𝑋, π‘Œ = −𝑓(π‘Œ, 𝑋)
3. ∀𝑋, π‘Œ, 𝑍 ⊂ 𝑉
𝑋∩π‘Œ =∅⇒
𝑓 𝑋 ∪ π‘Œ, 𝑍 = 𝑓 𝑋, 𝑍 + 𝑓 π‘Œ, 𝑍 ^
𝑓 𝑍, 𝑋 ∪ π‘Œ = 𝑓 𝑍, 𝑋 + 𝑓(𝑍, π‘Œ)
Capacity Constraint
∀𝑒, 𝑣 ∈ 𝑉 𝑓 𝑒, 𝑣 ≤ 𝑐 𝑒, 𝑣
Skew Symmetry
∀𝑒, 𝑣 ∈ 𝑉 𝑓 𝑒, 𝑣 = −𝑓 𝑣, 𝑒
∀𝑋, π‘Œ ⊂ 𝑉 𝑓 𝑋, π‘Œ = −𝑓(π‘Œ, 𝑋)
Flow Conservation
∀𝑒 ∈ 𝑉 − 𝑠, 𝑑
𝑒∈𝑉 𝑓
𝑒, 𝑣 = 0
∀𝑋 ⊂ 𝑉 𝑓 𝑋, 𝑋 = 0
Homomorphism
∀𝑋, π‘Œ, 𝑍 ⊂ 𝑉
𝑋∩π‘Œ =∅⇒
𝑓 𝑋 ∪ π‘Œ, 𝑍 = 𝑓 𝑋, 𝑍 + 𝑓 π‘Œ, 𝑍 ^
𝑓 𝑍, 𝑋 ∪ π‘Œ = 𝑓 𝑍, 𝑋 + 𝑓(𝑍, π‘Œ)
Flow Value
Prove 𝑓 = 𝑓 𝑉, 𝑑
𝑓 = 𝑓 𝑠, 𝑉
= 𝑓 𝑉, 𝑉 − 𝑓 𝑉 − 𝑠, 𝑉
= −𝑓 𝑉 − 𝑠, 𝑉
= 𝑓 𝑉, 𝑉 − 𝑠
= 𝑓 𝑉, 𝑑 + 𝑓 𝑉, 𝑉 − 𝑠 − 𝑑
= 𝑓(𝑉, 𝑑)
Definition
Homomorphism
Flow Conservation
Skew Symmetry
Homomorphism
Flow Conservation
Ford-Fulkerson
flow=0
while(∃ (augmenting path p)) {
augment flow f along p
}
return flow
Residual network
Induced network from G=(V, E) and flow f
𝑐𝑓 𝑒, 𝑣 = 𝑐 𝑒, 𝑣 − 𝑓(𝑒, 𝑣)
10
8/13
v2
5
3
4/9
11/14
0
v1
11
s
1/4
4
v2
4/4
v4
5
15
5
8
5
t
v3
12
11
v3
7/7
v1
11/16
s
12/12
11
3
t
0 7
0
v4
4
Augmenting Path
A path of
non-zero weight
from
s to t in Gf
10
8/13
v2
5
3
4/9
11/14
0
v1
11
s
1/4
4
v2
4/4
v4
5
15
5
8
5
t
v3
12
11
v3
7/7
v1
11/16
s
12/12
11
3
t
0 7
0
v4
4
10
8/13
v2
5
3
4/9
11/14
0
v1
11
s
1/4
4
v2
4/4
v4
5
15
5
8
5
t
v3
12
11
v3
7/7
v1
11/16
s
12/12
11
3
t
0 7
0
v4
4
10
8/13
v2
5
3
5
0
12
11
8
v2
4/9
11/14
v1
11
s
1/4
v3
7/7
v1
11/16
s
12/12
t
4/4
v4
v3
5
15
5
4
11
3
t
0 7
0
v4
4
10
13/13
v2
5
3
0/9
11/14
0
v1
11
s
1/4
0
v2
4/4
v4
0
20
9
13
0
t
v3
12
11
v3
7/7
v1
11/16
s
12/12
11
3
t
0 7
0
v4
4
S-T Cut
• A cut C=(S, T) of a flow network G=(V, E) is a
partition of V into S and T = V – S
– 𝑠 ∈ 𝑆, 𝑑 ∈ 𝑇
• Net flow across 𝐢: 𝑓 𝑆, 𝑇
• Capacity of cut: c 𝑆, 𝑇
10
8/13
1/4
v2
4/9
11/14
v3
7/7
v1
11/16
s
12/12
v4
t
4/4
f(S, T) = 12 – 4 + 11 = 19
c(S, T) = 12 + 14 = 26
Let f be a flow in a flow network G with source s and
sink t, and let (S, T) be a cut of G. Then the net flow
across (S, T) is f(S, T) = |f|
𝑓 𝑆, 𝑇 = 𝑓 𝑆, 𝑉 − 𝑓 𝑆, 𝑆
= 𝑓 𝑆, 𝑉
= 𝑓 𝑠, 𝑉 + 𝑓 𝑆 − 𝑠, 𝑉
= 𝑓 𝑠, 𝑉
= |𝑓|
Homomorphism
Flow Conservation
Homomorphism
Flow Conservation
Definition
The value of any flow f in a flow network G is bounded
by the capacity of any cut of G
𝑓 = 𝑓 𝑆, 𝑇
=
𝒇(𝒙, π’š)
𝒙∈𝑺 π’š∈𝑻
≤
𝒄 𝒙, π’š
𝒙∈𝑿 π’š∈𝒀
= 𝑐(𝑆, 𝑇)
Min-Cut Max-Flow
1. f is a maximum flow in G
2. The residual network Gf contains no
augmenting path
3. |f|= c(S, T) for some cut (S, T) of G
1 ⇒ (2)
1. Premise: f is a max-flow in G
2. Assume Gf has augmenting path p
3. We can augment Gf with p to get a flow f’ > f
– Contradicts [1]
• Hence Gf has no augmenting paths
2 ⇒ (3)
1. Premise: Gf has no augmenting paths
2. Let
1. 𝑆 = 𝑣 ∈ 𝑉: ∃ π‘π‘Žπ‘‘β„Ž π‘“π‘Ÿπ‘œπ‘š 𝑠 π‘‘π‘œ 𝑣 𝑖𝑛 𝐺𝑓
2. T = V-S
3. (S, T) is a cut
1. 𝑠 ∈ 𝑆, 𝑑 ∈ 𝑇 ∡ ~∃π‘π‘Žπ‘‘β„Ž π‘“π‘Ÿπ‘œπ‘š 𝑠 π‘‘π‘œ 𝑑 𝑏𝑦 1
4. ∀𝑒 ∈ 𝑆, 𝑣 ∈ 𝑇(𝑓 𝑒, 𝑣 = 𝑐 𝑒, 𝑣 )
1. Otherwise 𝑠 → 𝑒 → 𝑣 ⇒ 𝑣 ∈ 𝑆
5. 𝑓 = 𝑓 𝑆, 𝑇 = 𝑐(𝑆, 𝑇)
3 ⇒ (1)
The value of any flow f in a flow network G is bounded
by the capacity of any cut of G
1. 𝑓 ≤ 𝑐 𝑆, 𝑇 𝑏𝑦 πΏπ‘’π‘šπ‘šπ‘Ž
2. 𝑆𝑖𝑛𝑐𝑒 𝑓 = 𝑐 𝑆, 𝑇 , |f| is maximum
Ford-Fulkerson
flow=0
while(∃ (augmenting path p)) {
augment flow f along p
}
return flow
Termination: Gf has no augmenting path iff
flow is maximum
Run-time
flow=0
while(∃ (augmenting path p)) {
augment flow f along p
}
return flow
O(E|f*|) where |f*| is the maximum flow
v1
1,000,000
1,000,000
1
s
1,000,000
v2
t
1,000,000
v1
1,000,000
1,000,000
1
s
1,000,000
v2
t
1,000,000
v1
999,999
s
1,000,000
1,000,000
1
1
1
v2
t
1,000,000
v1
999,999
s
1,000,000
1,000,000
1
1
1
v2
t
1,000,000
v1
999,999
s
999,999
1
1
1
1
1
999,999
v2
t
1,000,000
v1
999,999
s
999,999
1
1
1
1
1
999,999
v2
t
1,000,000
Edmunds Karp
flow=0
while(∃ (augmenting path p)) {
find augmenting path by BFS
augment flow f along p
}
return flow
Run-time: O(VE2)
v1
11
5
s
3
12
11
8
5
0
v2
v3
5
15
5
4
11
3
t
0 7
0
v4
4
Critical Edge
Lemma: Edges can be critical at most
v1
11
5
s
3
12
11
8
5
0
v2
v3
5
15
5
4
11
3
t
0 7
0
v4
4
Critical Edge
𝑉
2
times
𝛿𝑓 𝑒, 𝑣 ≔ π‘ β„Žπ‘œπ‘Ÿπ‘‘π‘’π‘ π‘‘ − π‘π‘Žπ‘‘β„Ž π‘™π‘’π‘›π‘”π‘‘β„Ž π‘“π‘Ÿπ‘œπ‘š 𝑒 → 𝑣
v1
11
5
s
3
12
11
8
5
0
v2
v3
5
15
5
4
11
3
t
0 7
0
v4
4
𝛿𝑓 𝑒, 𝑣 ≔ π‘ β„Žπ‘œπ‘Ÿπ‘‘π‘’π‘ π‘‘ − π‘π‘Žπ‘‘β„Ž π‘™π‘’π‘›π‘”π‘‘β„Ž π‘“π‘Ÿπ‘œπ‘š 𝑒 → 𝑣
1. Assume (u, v) is a critical edge
2. Augmenting-paths are shortest path
[by EK]
3. 𝛿𝑓 𝑠, 𝑣 = 𝛿𝑓 𝑠, 𝑒 + 1
[from 1]
4. After flow-augmentation, cf(u,v) = 0
• (u, v) cannot be critical path until another
augmenting path containing (v, u).
• Let the flow at this point be f’
5. 𝛿𝑓′ 𝑠, 𝑒 = 𝛿𝑓′ 𝑠, 𝑣 + 1
≥ 𝛿𝑓 𝑠, 𝑣 + 1
= 𝛿𝑓 𝑠, 𝑒 + 2
6. i.e, each time (u, v) is augmenting-path, path
length increases by 2
7. (u, v) can be critical edge at most
𝑉
2
times
Lemma: Edges can be critical at most
𝑉
2
times
Since there are O(E) edges, the number of augmenting
path is bounded by O(VE) [by Lemma].
Run-time: O(VE2)
Bipartite Matching
Bipartite Matching
Bipartite Matching ≤ MaxFlow
s
t
Bipartite Matching ≤ MaxFlow
s
t
Download