Network Flow Problems: Kvarya
Network Flow Problems: Kvarya
K V Arya
Introduction of:
network, max-flow problem
capacity, flow
Ford-Fulkerson method
pseudo code, residual networks, augmenting paths
cuts of networks
max-flow min-cut theorem
example of an execution
analysis, running time,
variations of the max-flow problem
Introduction network
Practical examples of a network
- liquids flowing through pipes
- parts through assembly lines
- current through electrical network
- information through communication network
- goods transported on the road
Introduction - network
Representation
v3
v1
v2
v4
v3
source
v2
v4
sink
v3
v1
v2
v4
v3
source
v2
v4
sink
Introduction - capacity
Representation
v1
8
3
6
v2
v4
6
12
c(u,v)=6
v2
v4
c(u,v)=12
v3
v1
Big pipe
v
Small pipe
Introduction - capacity
Representation
v1
8
3
6
v2
v4
If (u,v) E c(u,v) = 0
v2
v4
v1
6
0
0
0
v4
v3
v3
v2
v4
Introduction flow
Representation
v1
8
v1
3
6
v2
v4
6
6/12
6/6
f(u,v)=6
v2
v4
f(u,v)=6
v3
Maximum flow
Introduction flow
Representation
v1
8
3
6
v2
v1
v4
v3
v2
v4
Introduction flow
Representation
v1
8
3
6/6
v2
v1
6/6
v4
6/8
v3
v2
v4
Introduction flow
Representation
v1
8
3
6/6
v2
v1
6/6
v4
6/8
v3
v2
v4
Introduction flow
Representation
v1
3/8
3/6
3
6/6
v2
v1
6/6
v4
6/8
v3
v2
v4
Introduction flow
Representation
v1
3/8
3/6
3
6/6
v2
v1
6/6
v4
6/8
v3
v2
v4
Introduction flow
Representation
v1
5/8
2/3
3/6
3
6/6
v2
v1
6/6
v4
8/8
v3
v2
v4
Introduction cancellation
Representation
v1
5/8
2/3
3/6
3
6/6
v2
v1
6/6
v4
8/8
v3
v2
v4
Introduction cancellation
Representation
v1
6/8
3/3
4/6
S
6/6
v2
1/3
v4
5/6
8/8
u
10
v2
u
4
v3
v1
8/10
8/10
u
3/4
v4
5/10
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties:
1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)
2) Skew symmetry:
f(u,v) = 0
vV
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties:
1) Capacity constraint: For all u,v V : f(u,v) < c(u,v)
For all u,v V : f(u,v) = - f(v,u)
2) Skew symmetry:
10
16
11/
v3
8/1
v2
11/14
v4
Note:
15
/20
by skew symmetry
t
4/9
12/12
1/4
v1
7/7
4/4
f(u,v) = 0
vV
f (v3,v1) = - 12
u
8/10
u
3/4
5/10
f(u,v) = 5
4
f(v,u) = -5
3/3
v3
v1
Value of a Flow f:
Def:
|f| = v V f(s,v)
6/8
3/3
4/6
1/3
6/6
v2
5/6
v4
8/8
1 initialize flow f to 0
2 while there exits an augmenting path p
3
4 return f
8/1
3
v2
11/14
v4
4/4
v1
5
t
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
11
5
8
v2
v4
8/1
3
v2
11/14
v4
4/4
5
8
15
v2
3
11
11
11
v3
5
t
12
v1
15
/20
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
v4
8/1
3
v2
11/14
v4
4/4
5
8
15
t
11
11
v3
5
t
12
v1
15
/20
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
v2
3
11
v4
8/1
3
v2
11/14
v4
4/4
5
8
15
t
11
11
v3
5
t
12
v1
15
/20
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
v2
v4
11
Augmenting path
if (u,v) is on p
- cf(p) if (v,u) is on p
otherwise
8/1
3
v2
11/14
v4
4/4
5
8
15
t
11
11
v3
5
t
12
v1
15
/20
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
v2
3
11
v4
if (u,v) is on p
- cf(p) if (v,u) is on p
otherwise
8/1
3
v2
11/14
v4
4/4
-4/
8
v2
4/5
11
11
v3
4/4
5
t
12
v1
-4
/5
15
/20
4/9
v3
7/7
10
16
11/
12/12
1/4
v1
v4
11
4/5
-4/
15
if (u,v) is on p
- cf(p) if (v,u) is on p
otherwise
12/
1
New flow:
v2
11/14
v4
4/4
f: V x V R : f=f + fp
4/5
8
15
11
4/5
v3
4/4
/20
12
v1
11
19
0/9
v3
7/7
10
16
11/
12/12
1/4
v1
v2
v4
11
Lemma:
f : V x V R : f = f + fp
in G
fp(u,v) =
0
if (u,v) is on p
- cf(p) if (v,u) is on p
otherwise
Capacity constraint:
in G
Skew symmetry:
For all u,v V, we require f(u,v) = - f(v,u)
Proof:
(f + fp)(u ,v) = f (u ,v) + fp (u ,v) = - f (v ,u) fp (v ,u)
= - (f (v ,u) + fp (v ,u)) = - (f + fp) (v ,u)
in G
Flow conservation:
For all u V \ {s,t} :
f(u,v) = 0
vV
Proof:
u V {s ,t} (f + fp) (u ,v) = (f(u ,v) + fp (u ,v))
vV
= fv(u
,v) + fpv (uV ,v) = 0 + 0 = 0
V
vV
|f| = v
f(s,v)
V
Proof:
| (f + fp) | = (f + fp) (s ,v) = (f (s ,v) + fp (s ,v))
vV
vV
= f (s ,v) + fp (s ,v) = | f | + | fp |
vV
vV
in G
| (f + fp) | = | f | + | fp | > | f |
Lemma shows:
if an augmenting path can be found then the above flow
augmentation will result in a flow improvement.
Question: If we cannot find any more an augmenting path
is our flow then maximum?
Idea: The flow in G is maximum the residual Gf
contains no augmenting path.
v2
v4
11/14
S
S = {s,v1,v2) , T = {v3,v4,t}
t
0/9
12/
1
In the example:
19
/20
7/7
1/4
10
16
11/
S
12/12
v1
4/4
vT
12/
1
proof
19
/20
t
0/9
v3
7/7
10
16
11/
12/12
1/4
v1
v2
11/14
v4
4/4
< c (u, v)
u S v T
= c (S, T)
Hence, | f | < c (S, T)
v3
19
/20
7/7
u S v T
16
11/
12/12
0/9
= f (u, v)
v1
1/4
| f | = f (S, T)
10
Lemma:
12/
13
v2
11/14
v4
4/4
(2) (3):
residual network Gf
3/3
v3
v1
6/8
3/3
4/6
S
6/6
v2
2
t
1/3
5/6
v4
8/8
v1
3
6
v3
4
2
6
5
v2
v4
residual network Gf
v1
2
3
6
v3
4
2
6
5
v2
v4
original network G
3/3
v3
v1
6/8
3/3
4/6
1/3
6/6
v2
1
5/6
v4
8/8
(residual) network Gf
12
v1
v3
20
10
16
13
v2
14
v4
5
6
7
8
(residual) network Gf
v3
0/2
0
t
0/9
0/4
0/10
6
0/1
S
0/12
v1
0/1
v2
0/14
v4
0/4
5
6
7
8
(residual) network Gf
12
v1
v3
20
10
16
13
v2
14
v4
5
6
7
8
(residual) network Gf
12
v1
v3
20
10
16
13
v2
14
v4
5
6
7
8
(residual) network Gf
12
v1
v3
20
10
16
13
v2
14
v4
5
6
7
8
12
/20
13
v2
14
v4
temporary variable:
t
v3
10
16
/
2
1
12/12
cf (p) = 12
(residual) network Gf
12
v1
v3
12
10
12
13
v2
14
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
13
v2
14
v4
(residual) network Gf
12
v1
v3
12
10
12
13
v2
14
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
13
v2
14
v4
(residual) network Gf
12
v1
v3
12
10
12
13
v2
14
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
13
v2
14
v4
(residual) network Gf
12
v1
v3
12
10
12
13
v2
14
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
13
v2
14
v4
temporary variable:
cf (p) = 4
(residual) network Gf
12
v1
v3
12
10
12
13
v2
14
v4
5
6
7
8
12
/20
4/1
v2
4/14
v4
temporary variable:
t
v3
10
16
/
2
1
12/12
4/4
cf (p) = 4
(residual) network Gf
12
v1
v3
12
10
12
v2
10
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
4/1
v2
4/14
v4
4/4
(residual) network Gf
12
v1
v3
12
10
12
v2
10
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
4/1
v2
4/14
v4
4/4
(residual) network Gf
12
v1
v3
12
10
12
v2
10
v4
5
6
7
8
12
/20
t
v3
10
16
/
2
1
12/12
4/1
v2
4/14
v4
4/4
(residual) network Gf
12
v1
v3
12
10
12
v2
10
v4
5
6
7
8
12
/20
4/1
v2
4/14
v4
temporary variable:
t
v3
10
16
/
2
1
12/12
4/4
cf (p) = 7
(residual) network Gf
12
v1
v3
12
10
12
v2
10
v4
5
6
7
8
19
/20
11/
13
v2
11/14
v4
temporary variable:
t
10
16
/
2
1
12/12
7/7
v1
4/4
cf (p) = 7
(residual) network Gf
12
v1
v3
19
10
12
11
11
v2
v4
5
6
7
8
19
/20
t
10
16
/
2
1
12/12
7/7
v1
11/
13
v2
11/14
v4
4/4
(residual) network Gf
12
v1
v3
19
10
12
11
11
v2
v4
5
6
7
8
19
/20
t
12/12
7/7
6
2/1
10
v1
11/
13
v2
11/14
v4
4/4
Finally we have:
| f | = f (s, V) = 23
unning time
1
2
3
4
5
6
7
8
The running time depends on how the augmenting path p in line 4 is determined.
O(|E| |fmax|)
000
00 ,
1,0
00
, 00
v1
1, 0
00,
00 0
v2
1,0
0
,00
0
0
residual network Gf
1,0
00
, 00
s
1, 0
00 ,
000
v2
9
,9 9
9
9
9
1/
0
1,0
1,0
00
, 00
t
00
0,0
v1
00
1/1
0
0 0,
0
,
/1
1, 0
00,
000
v2
,9
99
99
residual network Gf
1/
1, 0
00
,00
s
1/
1,0
00 ,
000
v2
,9 9
99 9
1/
0
1,0
v1
t
00
0,0
99
9,9
9
0
/ 1,
00
0 0,
99 9
1
,99
9
v2
,9
99
99
v3
u2
v4
v3
u2
v4
f(s,u2) = 1
running time: O ( |V| |E| )
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from p to t
v3
u1
u2
v4
f(s,u2) = 3
running time: O ( |V| |E| )
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from p to t
u1
v3
u2
v4
if cf(p) = cf(u,v)
v3
u2
v4
Idea:
u1
v3
u2
v4
Idea:
(u,v) can become critical at most
O(V) times
v3
u1
u2
v4
Idea:
(u,v) can become critical at most
O(V) times
v3
u1
u2
v4
A cost function cost where each edge (u,v) has got a second
weight cost(u,v) and the min-cost max-flow problem
8
T
t1
supersource
s2
8
s4
t2
s3
supersink