Documentos de Académico
Documentos de Profesional
Documentos de Cultura
K V Arya
Introduction network
Practical examples of a network
- liquids flowing through pipes - parts through assembly lines - current through electrical network
Introduction - network
Representation
Flow network: directed graph G=(V,E)
v1 v3 v1 v3
v2
v4
source
v2
v4
sink
v2
v4
source
v2
v4
sink
Informal definition of the max-flow problem: What is the greatest rate at which material can be shipped from the source to the sink without violating any capacity contraints?
Introduction - capacity
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6
t 8
v2
6 12
v4
v2
v4
c(u,v)=12
6
Big pipe
v
c(u,v)=6
Small pipe
Introduction - capacity
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6
t 8
v2
v4
v2
v4
If (u,v)
v2
E
6
c(u,v) = 0
v4
0
0 v4 0 v3
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6
t 8
v2
6 6/12
v4
v2
v4
f(u,v)=6
6/6
f(u,v)=6
Maximum flow
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6
t 8
v2
v4
v2
v4
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6/6
t 6/8
v2
6/6
v4
v2
v4
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3 v1 v3 v1 6 S v3
8
S 3 6/6
t 6/8
v2
6/6
v4
v2
v4
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3/3 v1 v3 v1 3/6 S v3
3/8
S 3 6/6
t 6/8
v2
6/6
v4
v2
v4
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3/3 v1 v3 v1 3/6 S v3
3/8
S 3 6/6
t 6/8
v2
6/6
v4
v2
v4
Introduction flow
Representation
Flow network: directed graph G=(V,E)
3/3 v1 v3 v1 3/6 S v3
5/8
S 3 6/6
2/3
t 8/8
v2
6/6
v4
v2
v4
Introduction cancellation
Representation
Flow network: directed graph G=(V,E)
3/3 v1 v3 v1 3/6 S v3
5/8
S 3 6/6
2/3
t 8/8
v2
6/6
v4
v2
v4
Introduction cancellation
Representation
Flow network: directed graph G=(V,E)
3/3 v1 v3 v1 4/6 S v3
6/8
S
3/3
t 1/3 8/8
6/6
v2
5/6
v4
v2
v4
u 10 4 8/10
u 4 8/10
u 3/4 5/10
u 4
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties: V : f(u,v) < c(u,v) V : f(u,v) = - f(v,u) V \ {s,t} :
v V
1) Capacity constraint: For all u,v 2) Skew symmetry: For all u,v
f(u,v) = 0
Flow properties
Flow in G = (V,E): f: V x V R with 3 properties: V : f(u,v) < c(u,v) V : f(u,v) = - f(v,u) V \ {s,t} :
v V
1) Capacity constraint: For all u,v 2) Skew symmetry: For all u,v
f(u,v) = 0
v1
12/12
v3
f (v3,v1) = - 12
v2
11/14
v4
f(u,v) = 5
f(v,u) = -5
8/10
3/3 v1 v3
6/8
S
3/3
4/6
1/3
6/6
v2
5/6
v4
8/8
What is the greatest rate at which material can be shipped from the source to the sink without violating any capacity contraints?
The max-flow problem is to find a valid flow for a given weighted directed graph G, that has the maximum value over all valid flows.
2) augmenting paths
3) cuts of flow networks
1 initialize flow f to 0
4 return f
12/12
v3
v2
11/14
v4
v2
v4
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
Augmenting path
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p 0 Flow network G = (V,E)
v1
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p 0 Flow network G = (V,E)
v1
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p 0 Flow network G = (V,E)
v1
12/12
v3
12
v3
v2
11/14
v4
v2
3 11
v4
New flow:
f: V x V
R : f=f + fp
Capacity constraint:
For all u,v Proof:
fp (u ,v) < cf (u ,v) = c (u ,v) f (u ,v) (f + fp) (u ,v) = f (u ,v) + fp (u ,v) < c (u ,v)
Skew symmetry:
For all u,v 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) V, we require f(u,v) = - f(v,u)
Flow conservation:
For all u Proof: u V {s ,t}
v V
V \ {s,t} :
v V
f(u,v) = 0
Value of a Flow f:
Def: Proof: | (f + fp) | = v V(f + fp) (s ,v) = v V (s ,v) + fp (s ,v)) (f |f| =
v V
f(s,v)
=
v V
f (s ,v) +
v
fp (s ,v) = | f | + | fp |
| (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 contains no augmenting path. the residual Gf
A cut (S,T) of a flow network G=(V,E) is a partiton of V into S and T = V \ S such that s S and t T.
Practical example
v1
12/12
v3
v2
11/14
v4
the value of a flow in a network is the net flow across any cut of the network f (S ,T) = | f |
12/12
v1
v3
v2
11/14
v4
proof
12/12
v3
c (u, v)
v2
u S v T
= c (S, T)
Hence, | f | < c (S, T)
11/14
v4
We assume for the sake of contradiction that f is a maximum flow in G but that there still exists an augmenting path p in Gf. Then as we know from above, we can augment the flow in G according to the formula: f = f + fp. That would create a flow f that is strictly greater than the former flow f which is in contradiction to our assumption that f is a maximum flow.
(2)
(3):
6/8
3/3
v1 3/3 v3
(2)
(3): Define
path p from s to v in Gf } S according to (2))
2 6 S
3
v1 3 1 2 6 v2 1 5
v3 2 4 t 8
S = {v V |
T = V \ S (note t
v4
(2)
(3): Define
v1
3/3
v3 3/3 4/6 6/8 S 1/3 6/6 v2 1 5/6 v4 8/8
S = {v V |
T = V \ S (note t
(3)
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
0/12
v3
1 2 3 4
t
v2
0/14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
temporary variable: cf (p) = 12
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
temporary variable:
12/12
v3
cf (p) = 12
v2
14
v4
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
14
v4
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
14
v4
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
14
v4
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
temporary variable:
cf (p) = 4
v2
14
v4
12
v3
1 2 3 4
t
v2
14
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
temporary variable:
12/12
v3
cf (p) = 4
v2
4/14
v4
12
v3
1 2 3 4
t
4
v2
10
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
4/14
v4
12
v3
1 2 3 4
t
4
v2
10
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
4/14
v4
12
v3
1 2 3 4
t
4
v2
10
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
v2
4/14
v4
12
v3
1 2 3 4
t
4
v2
10
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
temporary variable:
12/12
v3
cf (p) = 7
v2
4/14
v4
12
v3
1 2 3 4
t
4
v2
10
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
temporary variable:
12/12
v3
cf (p) = 7
v2
11/14
v4
12
v3
1 2 3 4
t
11
v2
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network G f do cf(p) = min{c f(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + c f(p) f [v, u] = - f [u, v]
12/12
v3
v2
11/14
v4
12
v3
1 2 3 4
t
11
v2
v4
5 6 7 8
for each edge (u, v) E [G] do f [u, v] = 0 f [v, u] = 0 while there exists a path p from s to t in the residual network Gf do cf(p) = min{cf(u, v) | (u, v) p} for each edge (u, v) in p do f [u, v] = f [u, v] + cf(p) f [v, u] = - f [u, v]
12/12
v3
Finally we have:
S t
| f | = f (s, V) = 23
v2
11/14
v4
The running time depends on how the augmenting path p in line 4 is determined.
O(|E| |fmax|)
v2
residual network Gf
v1
v2
v2
residual network Gf
v1
v2
v2
v3
the shortest path distance f(s,v) in Gf increases monotonically with each flow augmentation
f (s,v) < f
u2
(s,v)
v4
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
the shortest path distance f(s,v) in Gf increases monotonically with each flow augmentation
. f(s,v) <
f
u2
(s,v)
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
the shortest path distance f(s,v) in Gf increases monotonically with each flow augmentation
. f(s,v) <
f
u2
(s,v)
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
The total number of flow augmentations performed by the algorithm is at most O(|V| |E|)
S
u1
v3
u2
v4
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
u2
v4
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
Idea: (u,v) can become critical at most O(V) times (After beeing critical it dissappears in Gf and can only reappear after net flow is decreased)
S
u1
v3
u2
v4
our example: edge (u2,v4) 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
Idea: (u,v) can become critical at most O(V) times (After beeing critical it dissappears in Gf and can only reappear after net flow is decreased)
S
v3
u2
v4
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
Idea: (u,v) can become critical at most O(V) times (After beeing critical it disappears in Gf and can only reappear after net flow is decreased)
S
v3
2
u2 v4
our example: edge (u2,v4) reappeared but is now unreachable from s 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
If augmenting path is found by breath-first search and has to be a shortest path from p to t then it become E-K algorithm
s2
t1 T
supersource
S s3 t2
supersink
s4