2 - 6 MaxFlow EN V2
2 - 6 MaxFlow EN V2
Mathematics
PART 1
COMBINATORIAL THEORY
(Lý thuyết tổ hợp)
PART 2
GRAPH THEORY
(Lý thuyết đồ thị)
3
Content of Part 2
E-(v) and E+(v) are sets of arcs entering and leaving vertex v, respectively.
v 1/ 3
Conditions 1) and 2) are satisfied => 2/ 6
1/ 1
??/ t
f is flow in network 3/ 7
s 3/ 3
e.g. oil flowing through w
4/ 5
1/1 2/ 9
??/ ??/
pipes, internet routing 3/5
2/ 2
??/
u z
Flow in network
Definition. Flow f in network G=(V,E) is to assign value f(e) on each edge e
(f(e) is flow on edge e) so that following conditions are satisfied:
1) Capacity rule:
For each edge e, 0 ≤ f (e) ≤ c(e)
2) Conservation Rule (Điều kiện cân bằng luồng): Each v ≠ s, t
v v 3/3
1/3 4/6
2/6 1/1
1/1 t 3/7 t
3/7 s 3/3
s 3/3
w w
2/9 4/5 1/1 2/9 4/5
3/5 1/1 3/5
u z u z
2/2 2/2
Maximum flow with value 10 = 4 + 3 + 3 = 3 + 3 + 4
Some applications
Goods,
Traffic airport, station highways, flights
customers
4 6 15 10
15
4 30 7
Flow through the cut
Definition. Assume f is a flow in network and (S,T) is a cut. We call value of flow
through the cut (S,T) is the value
6+0+8+10 0
4 8 8
s 5 3 8 6 10 t
0 10
4 0 6 15 0 10
15
10 10
4 30 7
Flow and cut
Lemma 1. Assume f is flow, and (S, T) is a cut. Then
Flow through this cut is equal to the value of flow f:
Flow and cut
Lemma 2. Assume f is a flow, (S, T) is a cut. Then
val( f ) ≤ cap(S, T).
Proof
S 4 T
8
t
s
7
6
Max Flow and Min Cut
Corollary. Assume f is a flow, (S, T) is a cut. If val( f ) = cap(S, T), then
f is maximum flow and (S, T) is minimum cut.
The flow in network G is called maximum flow if among all Minimum cut: the cut of minimum capacity
flows in G, its value is maximum
f ’ is arbitrary
Lemma flowf is a flow, and (S, T) is a cut. Then
2. Assume f is max flow
val( f’ ) ≤ val (f ) val( f ) ≤ cap(S, T)
9
2 9 5
10 9
1
10 15 15 0 10
4 0
4 8 9
s 5 3 8 6 10 t
4 10
4 0 6 15 0 10
15
14
4 30 7
14 Flow value = 28
Cut capacity = 28
Contents
4 5
0
0 4 0
4
0 4
0 10 4
0 10 0 10
s 10 2 13 3 10 t
Value
Valueof
offlow
flow==10
0
Greedy algorithm
Greedy algorithm does not provide optimal solution.
4 5
0 Greedy algorithm:
0 4 0
4
Value of flow = 10
0 4
10 4
10 10
s 10 2 13 3 10 t
Optimal:
4 5 Value of flow = 14
4
4 4 4
4
4 4
10 4
6 10
s 10 2 13 3 10 t
Residual graph
e = (u,v) ⇒ eR = (v,u)
Residual graph: Gf = (V, Ef ).
• Ef = {e: f(e) < c(e) } ∪ {eR : f(e) > 0 }
• Capacity of each arc e
v 11 w
6
Residual graph - Example
Residual graph: Gf = (V, Ef ).
– Ef = {e : f(e) < c(e)} ∪ {eR : f(e) > 0}.
– cf(e) indicates the maximum amount that can increase flow on arc e.
– cf(eR) indicates the maximum amount that can decrease flow on arc e.
(s,4)
4 5 (s,2)
0
0 4 (2,3)
0
G 4
4
(4,3)
0
4
(2,5)
10 10 10
(3,t)
s 10 2 13 3 10 t
4 5
(5,t)
4
Gf 4
4
4
s 10 2 10 3 10 t
3
Residual graph - Example
Residual graph: Gf = (V, Ef ).
– Ef = {e : f(e) < c(e)} ∪ {eR : f(e) > 0}.
– cf(e) indicates the maximum amount that can increase flow on arc e.
– cf(eR) indicates the maximum amount that can decrease flow on arc e.
(s,4)
Augmenting path = path from s to t on the residual graph Gf.
(s,2)
Capacity of the path: cf (P) = min {cf (e): e ∈ P }.
(2,3)
Build new Gf 4 5
Find augmenting path
4 X
0 (4,3)
4 X
0 4 (2,5)
On new Gf 0 4
X
4
G 4 X
0 4 (3,t)
10 4 (5,t)
X 6
10 10
s 10 2 13 3 10 t
Example: Augmenting path P: 4 5
cf (P) = 4
s, 4, 3, 2, 5, t 4
Gf 4
4
4
s 10 2 10 3 10 t
3
Augmenting path
Augmenting path = path from s to t on the residual graph.
• Max flow ⇔ could not find any augmenting path??? (s,4)
(s,2)
(2,3)
Value of flow = 14 4 5 (4,3)
4
4 (2,5)
4 4
G 4 (3,t)
4 4
4 (5,t)
10 6 10
s 10 2 13 3 10 t
4
Gf 4
4
4
s 10 2 6 3 10 t
7
Theorem about maximum flow and minimum cut
Max flow and min cut Theorem (Ford-Fulkerson, 1956): the maximum
possible flow in a network (from source to sink) is exactly equal to the
minimum capacity of all possible cuts.
The following example shows how the algorithm can take a lot of
iteration
Ford – Fulkerson algorithm is not polynomial algoirthm
Augmenting path P: s, 4, 2, t
G 4 Gf 4
10X 0 1
X
10 10 10 10
9 9 9 9
s XX
10 10 t s 1 t
10 10 10 10
09
1X X9 1
0 9 9
2 2
Algorithm executes alternating Gf 4
1
augmenting flow along two paths P and P’ 109-1 109
(s, 4) 9
(s, 2) 2×10 iterations s 1 t
(4, 2)
(2, t ) 109 109 -1
(4, t ) 1
2
Zwick constructs examples showing that the algorithm may not stop,
if the capacity of arcs is irrational
s
X X
X
1 1 φ
X
X X
t
Ford – Fulkerson algorithm
Assumption: All capacities on arcs are integers in the range [0, C].
Immutability: Each value of flow value f(e) and capacity cf (e) are
always integer during algorithm execution.
Theorem: F-F algorithm stops after not more than val( f *) ≤ nC
iterations.
Proof.
After each augmenting flow, value of flow is augmented by at least 1
• WHILE
Augmenting
(therepath has the
exists anleast edges
augmenting path P)
{ f ← augment(f, P)
update Gf
}
RETURN f
}
0
Flow
2 4 5
Capacity
G: 0 0 0
10 2 0 8 60 10
0 0 0
s 10 3 9 4 10 t
Value of flow = 0
Build the residual graph Gf
38
Edmonds-Karp Algorithm
0
flow
2 4 5
capacity
G: 8 X
0 0 8
X 0
10 2 0 8 60 10
0 0 8 X
0
s 10 3 9 4 10 t
Value of flow
flow==80
Augmenting path P: s, 2, 4, t
Augment flow along P 2 4 5
capacity
Gf:
10 2 8 6 10
s 10 3 9 4 10 t
Edmonds-Karp Algorithm
X 2
0
2 4 5
G: 10 8
X X
0 2
8
10 2 0 8 60 10
0 0 8
s 10 3 9 4 10 t
2
2 4 5
G: 10 8 2
10 2 0 8 60 10
0
X 2 0 2
X 10 8
X
s 10 3 9 4 10 t
Gf: 2
10 2 8 6 8
s 10 3 9 4 2 t
8
Edmonds-Karp Algorithm
2
2 4 5
G: 10 8 2 8
X
10 2 0 8 6X
0 10
6
2 8
X X 8
2 10
s 10 3 9 4 10 t
Gf: 2
10 2 8 6 8
s 8 3 7 4 10 t
2 2
Edmonds-Karp Algorithm
X
2 3
2 4 5
G: 10 X 7
8 X
8 9
10 2 0 8 66 10
X
8 9 8 9
X 10
s 10 3 9 4 10 t
Gf: 8
10 2 8 6 2
s 2 3 1 4 10 t
8 8
Conclusion: In graph Gf, S = set of vertices reached from s by BFS(s)
- Min cut (S, T): S = {s, 3}; T = {2,4,5,t}
- Max flow: val ( f ) = 10 + 9 = 19
3
2 4 5
G: 10 7 9
10 2 0 8 66 10
9 9 10
s 10 3 9 4 10 t
Gf: 9
1
10 2 7 6 1
s 1 3 9 4 10 t
9
Applications
46