Lecture 27 - MaximumFlow - NP-Completeness
Lecture 27 - MaximumFlow - NP-Completeness
Maximum Flow / P or NP
Introduction to Algorithms
Sungkyunkwan University
Hyunseung Choo
[email protected]
1
10, 8 8,7
s 1,1
t
6, 5 10,6
2
warehouses retailers
6 1
6 6
5 2
7 7
4 3
8 6
5 4
9 5
4 5
6 1
6
6 6
5 5 2 6
4 7 77
s 4 3 t
6
5
8 6
5 4 4 5
9 5
4 5
persons tasks
1 5
2 6
3 7
4 8
persons tasks
1 5
1 1
1 2 6 1
s 1 1 t
3 7
1
1
4 8
1 8,7
10, 8
1,1 uij ,xij
s t i j
6, 5 10,6
2
1
2 1
rij = uij - xij
8 7
s 1 t i j
1 4
xij
5 6
2
Let rij denote the
The Residual Network G(x) residual capacity of
arc (i,j)
Superintelligence Laboratory H.CHOO 8/39
Augmenting Paths
To augment along P, send d(P) units of flow along each arc of the
path, then, modify x and the residual capacities appropriately
1 1
2 1 2
8 7 8 8
s 1 t s 1 t
1 4 4
5 6 6 6
2 2
Begin
x := 0
create the residual network G(x)
while there is some directed path from s to t in G(x) do
begin
let P be a path from s to t in G(x)
:= d(P)
send units of flow along P
update the r's
end
End {the flow x is now maximum}
4
2 5
3 1 1 1
2 2
s 4 t
3 1 2
4
2 5
3 1 1 1
2 2
s 4 t
3 1 2
3
This is the original network, and
the original residual network
4
2 5
3 1 1 1
2 2
s 4 t
3 2
1
4
2 5
3 1 1 1
2 1
2
s 4 t
2 1
3 1 2
1 1
3
Determine residual capacity of the path
Send units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 14/39
Ford-Fulkerson Max-Flow (6/16)
4
2 5
3 1 1 1
2 1
2
s 4 t
1
2
3 2
1
1
3
4
2 5
3 1 1 1
2
1 11
s 4 t
1 1
2
3 1 2
1
1
1 1
3
Determine the residual capacity of the path
Send units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 16/39
Ford-Fulkerson Max-Flow (8/16)
4
2 5
3 1 1 1
2
1 11
s 4 1
t
1
2
3 2
1
1
1 1
3
4
2 5
3 1 1 1
1 11
s 2
1 4 1
2
t
32 1
1
1
3 1
4
2 5
3 1 1 1
1
2 11
s 21 4 1
2
t
2
3 1
1
1
3 1
4
2 5
3 1 1 1
1
2 11
s 2 4 2 t
1 1
2 1
1
11
2
1 2
1
3
Determine the residual capacity of the path
Send units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 20/39
Ford-Fulkerson Max-Flow (12/16)
4
2 5
3 1 1 1
1
2 11
s 21
4 1
2
t
1
2 1
12 2
1
3
4
3
2 1
5
2
3 1 1 1
1 1
s 4 t
1 21
2 1
2
1
2
1 2
1
3
Determine the residual capacity of the path
Send units of flow in the path
Update residual capacities
Superintelligence Laboratory H.CHOO 22/39
Ford-Fulkerson Max-Flow (14/16)
4
3
2 5
1
23 1 1 1
1 1
s 21
4 1
2
t
1
2 1
2
1 2
1
3
4
3
2 1
5
3
2 1 1 1
1 1
s 1
2 4 1
2 t
1
2
1
2
1 2
1
3
1
2 5
1 1
2 2
s 4 t
2 2
s 1,1
t
6,6 10,7
2
METHOD
There is no augmenting path in the residual network
1 reachable
1 8
from s in G(x)
9
s 1 t
3 not reachable
6
2
7 from s in G(x)
1
M M
s 1 t
M M
1
M-1 M
1
s 1 t
M M-1
1
2
1
M-1 M-1
1 1
s 1 t
M-1 M-1
1 1
2
1
M-2 M-1
2 1
s 1 t
M-1 M-2
1 2
2
And so on
Superintelligence Laboratory H.CHOO 30/39
After 2M Augmentations
1
M M
s 1 t
M M
I couldn’t find a
polynomial time
algorithm. I guess I’m
too dumb.