2. Network flow problems
- 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
3. 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…
4. Introduction - network
Example: oil pipelineRepresentation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
S t
v1
v2
v3
v4source sink
5. Introduction – max-flow
problemRepresentation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
S t
v1
v2
v3
v4source 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?
Example: oil pipeline
6. Introduction - capacity
S t
v1
v2
v3
v4
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
u v
12
u v
6
c(u,v)=12
c(u,v)=6
Big pipe
Small pipe
8
3
6
8
6
6
3
3
Example: oil pipeline
7. Introduction - capacity
S t
v1
v2
v3
v4
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
8
3
6
8
6
6
3
3
Example: oil pipeline
v4
v2
v3
v4
If (u,v) E c(u,v) = 0
0
0
0
6
8. Introduction – flow
S t
v1
v2
v3
v4
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
u v
6/12
u v
6/6
f(u,v)=6
f(u,v)=6
Flow below capacity
Maximum flow
8
3
6
8
6
6
3
3
Example: oil pipeline
9. Introduction – flow
S t
v1
v2
v3
v4
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
8
3
6
8
6
6
3
3
Example: oil pipeline
10. Introduction – flow
S t
v1
v2
v3
v4
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
8
3
6
6/8
6/6
6/6
3
3
Example: oil pipeline
11. Introduction – flow
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
8
3
6
6/8
6/6
6/6
3
3
Example: oil pipeline
12. Introduction – flow
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
3/8
3/3
3/6
6/8
6/6
6/6
3
3
Example: oil pipeline
13. Introduction – flow
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
3/8
3/3
3/6
6/8
6/6
6/6
3
3
Example: oil pipeline
14. Introduction – flow
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
5/8
3/3
3/6
8/8
6/6
6/6
2/3
3
Example: oil pipeline
15. Introduction – cancellation
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
5/8
3/3
3/6
8/8
6/6
6/6
2/3
3
Example: oil pipeline
16. Introduction – cancellation
S t
v1
v2 v4
v3
Representation
Flow network: directed graph G=(V,E)
S t
v1
v2
v3
v4
6/8
3/3
4/6
8/8
5/6
6/6
3/3
1/3
u
v
10 4
u
v
8/10 4
u
v
8/10 3/4
u
v
5/10 4
Example: oil pipeline
17. Maximum Flow Problem: definitions
D
M
K
S
B
P
8
14
146
12
10
10
7
17
6
D
M
K
S
B
P
8
14
146
12
10
10
7
17
6
SOURCE:
Node with net outflow:
Production point
SINK:
Node with net inflow;
Consumption point
CAPACITY:
Maximum flow
on an edge
Efficient method to solve such problems: Ford-Fulkerson Method
18. 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: For all u,v V : f(u,v) = - f(v,u)
3) Flow conservation: For all u V {s,t} : f(u,v) = 0
v V
19. 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: For all u,v V : f(u,v) = - f(v,u)
3) Flow conservation: For all u V {s,t} : f(u,v) = 0
v V
S t
v1
v2
v3
v4
12/12
11/14
Flow network G = (V,E)
Note:
by skew
symmetry
f (v3,v1) = - 12
20. Net flow and value of a flow
Net Flow:
positive or negative value
of f(u,v)
Value of a Flow f:
Def:
|f| = f(s,v)v V
S t
v1
v2
v3
v4
6/8
3/3
4/6
8/8
5/6
6/6
3/3
1/3
u
v
8/10 3/4
u
v
5/10 4
f(u,v) = 5
f(v,u) = -5
21. The max-flow problem
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?
Formal definition of the max-flow problem:
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.
22. The Ford-Fulkerson method
a way how to find the max-flow
This method contains 3 important ideas:
1) residual networks
2) augmenting paths
3) cuts of flow networks
23. Ford-Fulkerson – pseudo code
1 initialize flow f to 0
2 while there exits an augmenting path p
3 do augment flow f along p
4 return f
24. Ford Fulkerson – residual
networks
S t
v1
v2
v3
v4
12/12
11/14
The residual network Gf of a given flow network G with a valid flow f
consists of the same vertices v V as in G which are linked with
residual edges (u,v) Ef that can admit more strictly positive net flow.
The residual capacity cf represents the weight of each edge Ef and is
the amount of additional net flow f(u,v) before exceeding the capacity
c(u,v)
Flow network G = (V,E)
cf(u,v) = c(u,v) – f(u,v)
S t
v1
v2
v3
v4
residual network Gf = (V,Ef)
25. Ford Fulkerson – residual
networks
S t
v1
v2
v3
v4
12/12
11/14
Flow network G = (V,E)
cf(u,v) = c(u,v) – f(u,v)
S t
v1
v2
v3
v4
residual network Gf = (V,Ef)
11
12
3
The residual network Gf of a given flow network G with a valid flow f
consists of the same vertices v V as in G which are linked with
residual edges (u,v) Ef that can admit more strictly positive net flow.
The residual capacity cf represents the weight of each edge Ef and is
the amount of additional net flow f(u,v) before exceeding the capacity
c(u,v)
26. Ford Fulkerson – augmenting
paths
S t
v1
v2
v3
v4
12/12
11/14
cf(p) = min{cf (u,v): (u,v) is on p}
Flow network G = (V,E) residual network Gf = (V,Ef)
Definition: An augmenting path p is a simple (free of any cycle) path
from s to t in the residual network Gf
Residual capacity of p
S t
v1
v2
v3
v4
12
3
11
27. Ford Fulkerson – augmenting
paths
S t
v1
v2
v3
v4
12/12
11/14
cf(p) = min{cf (u,v): (u,v) is on
p}
Flow network G = (V,E)
S t
v1
v2
v3
v4
12
3
residual network Gf = (V,Ef)
11
Definition: An augmenting path p is a simple (free of any cycle) path
from s to t in the residual network Gf
Residual capacity of p
Augmenting path
28. Ford Fulkerson – augmenting
paths
S t
v1
v2
v3
v4
12/12
11/14
Flow network G = (V,E)
S t
v1
v2
v3
v4
12
3
residual network Gf = (V,Ef)
11
We define a flow: fp: V x V R such as:
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p
0 otherwise
29. Ford Fulkerson – augmenting
paths
S t
v1
v2
v3
v4
12/12
11/14
Flow network G = (V,E)
S t
v1
v2
v3
v4
12
3
residual network Gf = (V,Ef)
11
Our virtual flow fp along the
augmenting path p in Gf
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p
0 otherwise
We define a flow: fp: V x V R such as:
30. Ford Fulkerson – augmenting the
flow
S t
v1
v2
v3
v4
12/12
11/14
Flow network G = (V,E)
S t
v1
v2
v3
v4
12
3
residual network Gf = (V,Ef)
11
Our virtual flow fp along the
augmenting path p in Gf
New flow: f´: V x V R : f´=f + fp
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p
0 otherwise
We define a flow: fp: V x V R such as:
31. Ford Fulkerson – new valid
flow
proof of capacity constraint
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)
Lemma:
f : V x V R : f = f + fp in
G
Capacity constraint:
For all u,v V, we require f(u,v) < c(u,v)
cf(p) if (u,v) is on p
fp(u,v) = - cf(p) if (v,u) is on p
0 otherwise
cf(p) = min{cf (u,v): (u,v) is on
p}
cf(u,v) = c(u,v) – f(u,v)
32. Ford Fulkerson – new valid
flow
proof of Skew symmetry
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)
Skew symmetry:
For all u,v V, we require f(u,v) = - f(v,u)
Lemma:
f : V x V R : f = f + fp in
G
33. Ford Fulkerson – new valid
flow
proof of flow conservation
Proof:
u V – {s ,t} (f + fp) (u ,v) = (f(u ,v) + fp (u ,v))
= f (u ,v) + fp (u ,v) = 0 + 0 = 0
Flow conservation:
For all u V {s,t} : f(u,v) = 0
v V
v Vv V
v Vv V
Lemma:
f : V x V R : f = f + fp in
G
34. Ford Fulkerson – new valid
flow
Proof:
| (f + fp) | = (f + fp) (s ,v) = (f (s ,v) + fp (s ,v))
= f (s ,v) + fp (s ,v) = | f | + | fp |
Lemma:
| (f + fp) | = | f | + | fp |
v Vv V
v Vv V
Value of a Flow f:
Def:
|f| =
f(s,v)
v V
35. Ford Fulkerson – new valid
flow
Lemma:
| (f + fp) | = | f | + | fp | > | f |
f : V x V R : f = f + fp in G
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.
36. Ford Fulkerson – cuts of flow
networks
New notion: cut (S,T) of a flow network
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.
Implicit summation notation: f (S, T) = f (u, v)
S t
v1
v2
v3
v4
12/1
2
11/1
4 TS
In the example:
S = {s,v1,v2) , T = {v3,v4,t}
Net flow f(S ,T) = f(v1,v3) + f(v2,v4) + f(v2,v3)
= 12 + 11 + (-0) = 23
Capacity c(S,T) = c(v1,v3) + c(v2,v4)
= 12 + 14 = 26
Practical example
u S v T
37. Ford Fulkerson – cuts of flow
networks
Lemma:
the value of a flow in a network is the net flow across any cut
of the network
f (S ,T) = | f
|
S t
v1
v2
v3
v4
12/1
2
11/1
4
proof
38. Ford Fulkerson – cuts of flow
networks
Assumption:
The value of any flow f in a flow network G is bounded from
above by the capacity of any cut of G
Lemma:
| f | < c (S, T)
| f | = f (S, T)
= f (u, v)
< c (u, v)
= c (S, T)
v Tu S
v Tu S S t
v1
v2
v3
v4
12/1
2
11/1
4
39. F. Fulkerson: Max-flow min-cut theorem
If f is a flow in a flow network G = (V,E) with source s and
sink t, then the following conditions are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf contains no augmenting paths.
3. | f | = c (S, T) for some cut (S, T) of G.
proof:
(1) (2):
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.
40. F. Fulkerson: Max-flow min-cut
theorem
If f is a flow in a flow network G = (V,E) with source s and
sink t, then the following conditions are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf contains no augmenting paths.
3. | f | = c (S, T) for some cut (S, T) of G.
proof:
(2) (3):
S t
v1
v2
v3
v4
6/8
3/3
4/6
8/8
5/6
6/6
3/3
1/3
S t
v1
v2
v3
v4
2
3
2
8
1
6
3
2
5
6 1
4
residual network Gforiginal flow network
G
41. F. Fulkerson: Max-flow min-cut
theorem
If f is a flow in a flow network G = (V,E) with source s and
sink t, then the following conditions are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf contains no augmenting paths.
3. | f | = c (S, T) for some cut (S, T) of G.
proof:
(2) (3): Define
S = {v V | path p from s to v in Gf }
T = V S (note t S according to (2))
S t
v1
v2
v3
v4
2
3
2
8
1
6
3
2
5
6 1
4
residual network Gf
42. F. Fulkerson: Max-flow min-cut
theorem
If f is a flow in a flow network G = (V,E) with source s and
sink t, then the following conditions are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf contains no augmenting paths.
3. | f | = c (S, T) for some cut (S, T) of G.
proof:
(2) (3): Define
S = {v V | path p from s to v in Gf }
T = V S (note t S according to (2))
for u S, v T: f (u, v) = c (u, v)
(otherwise (u, v) Ef and v S)
| f | = f (S, T) = c (S, T)
1
S t
v1
v2
v3
v4
6/8
3/3
4/6
8/8
5/6
6/6
3/3
1/3
original network G
43. F. Fulkerson: Max-flow min-cut
theorem
If f is a fow in a flow network G = (V,E) with source s and
sink t, then the following conditions are equivalent:
1. f is a maximum flow in G.
2. The residual network Gf contains no augmenting paths.
3. | f | = c (S, T) for some cut (S, T) of G.
proof:
(3) (1): as proofed before | f | = f (S, T) < c (S, T)
the statement of (3) : | f | = c (S, T) implies that f is a maximum flow
44. 1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t in the
residual network Gf
5 do cf (p) = min {cf (u, v) | (u, v) is in p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf (p)
8 f [v, u] = - f [u, v]
The basic Ford Fulkerson
algorithm
45. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
(residual) network Gf
46. The basic Ford Fulkerson algorithm
example of an execution
S t
v1
v2
v3
v4
0/12
0/14
(residual) network Gf
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
47. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network Gf
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
48. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network Gf
temporary variable:
cf (p) = 12
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
49. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network Gf
temporary variable:
cf (p) = 12
S t
v1
v2
v3
v4
12/1
2
14
new flow network
G
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
50. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
14
new flow network G
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
51. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network Gf
S t
v1
v2
v3
v4
12/1
2
14
new flow network
G
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
52. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network Gf
S t
v1
v2
v3
v4
12/1
2
14
new flow network
G
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
53. The basic Ford Fulkerson
algorithm
example of an execution
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
14
new flow network
G
temporary variable:
cf (p) = 4
S t
v1
v2
v3
v4
12
14
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
54. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
14
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
temporary variable:
cf (p) = 4
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
55. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
10
(residual) network Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
4
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
56. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
10
(residual) network Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
4
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
57. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
10
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
4
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
58. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
10
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
4
temporary variable:
cf (p) = 7
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
59. The basic Ford Fulkerson
algorithm
example of an execution
S t
v1
v2
v3
v4
12
10
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
4
temporary variable:
cf (p) = 7
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
60. The basic Ford Fulkerson
algorithm
example of an execution
(residual) network
Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
S t
v1
v2
v3
v4
12
3
11
1 for eachedge(u,v) E[G]
2 do f[u,v]=0
3 f [v, u] = 0
4 while thereexistsapathpfromstot
intheresidualnetworkG f
5 do cf(p)=min{c f(u,v)|(u,v) p}
6 for eachedge(u,v)inp
7 do f[u,v]=f[u,v]+c f(p)
8 f [v, u] = - f[u,v]
61. The basic Ford Fulkerson
algorithm
example of an execution
(residual) network Gf
S t
v1
v2
v3
v4
12/1
2
new flow network
G
S t
v1
v2
v3
v4
12
3
11
Finally we have:
| f | = f (s, V) = 23
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
62. Analysis of the Ford Fulkerson
algorithm
Running time
The running time depends on how the augmenting path p in line 4 is
determined.
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
63. Analysis of the Ford Fulkerson
algorithm
Running time (arbitrary choice of p)
O(|E|)
O(|E|
)
O(|E|
|fmax|)
running time: O ( |E| |fmax|
)
with fmax as maximum
flow
(1) The augmenting path is chosen arbitrarily and all capacities are
integers
1 for each edge (u, v) E [G]
2 do f [u, v] = 0
3 f [v, u] = 0
4 while there exists a path p from s to t
in the residual network Gf
5 do cf(p) = min{cf(u, v) | (u, v) p}
6 for each edge (u, v) in p
7 do f [u, v] = f [u, v] + cf(p)
8 f [v, u] = - f [u, v]
O(|E|
)
64. Analysis of the Ford Fulkerson
algorithm
Running time (arbitrary choice of p)
(1) The augmenting path is chosen arbitrarily and all capacities are
integers
Consequencies of an arbitrarily
choice:
Example if |f*| is large:
t
v2
v1
s
1
running time: O ( |E| |fmax|
)
with fmax as maximum
flow
65. Analysis of the Ford Fulkerson
algorithm
Running time (arbitrary choice of p)
(1) The augmenting path is chosen arbitrarily and all capacities are
integers
Consequencies of an arbitrarily
choice:
Example if |f*| is large:
t
v2
v1
s
1/1
t
v2
v1
s
1
residual network Gf
running time: O ( |E| |fmax|
)
with fmax as maximum
flow
66. Analysis of the Ford Fulkerson
algorithm
Running time (arbitrary choice of p)
(1) The augmenting path is chosen arbitrarily and all capacities are
integers
Consequencies of an arbitrarily
choice:
Example if |f*| is large:
t
v2
v1
s
1
t
v2
v1
s
1
residual network
Gf
running time: O ( |E| |fmax|
)
with fmax as maximum
flow
67. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
running time: O ( |V| |E|²
)
S t
u1
u2
v3
v4
4
4
Informal idea of the proof:
(1) for all vertices v V{s,t}:
the shortest path distance
f(s,v) in Gf increases
monotonically with each flow
augmentation
f (s,v) < f (s,v)
68. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
S t
u1
u2
v3
v4
4
4
Informal idea of the proof:
(1) for all vertices v V{s,t}:
the shortest path distance
f(s,v) in Gf increases
monotonically with each flow
augmentation
. f(s,v) < f (s,v)
f(s,u2) = 1
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
69. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
t
u1
u2
v3
v4
4
4
f(s,u2) = 3
Two flow augmentations later
S
Informal idea of the proof:
(1) for all vertices v V{s,t}:
the shortest path distance
f(s,v) in Gf increases
monotonically with each flow
augmentation
. f(s,v) < f (s,v)
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
70. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
S t
u1
u2
v3
v4
4
4
The total number of flow
augmentations performed by
the algorithm is at most 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
71. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
S t
u1
u2
v3
v4
4
4
Critical edges on the path p
Def: critical edge (u,v)
if cf(p) = cf(u,v)
At least one edge on p must be
critical.
How many times can (u,v) be
critical during an execution of
Edmonds-Karp algorithm?
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
72. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
S t
u1
u2
v3
v4
4
4
our example: edge (u2,v4)
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)
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
73. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
our example: edge (u2,v4) has
disappeared
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)
t
u1
u2
v3
v4
4
4
Two flow augmentations later
S
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
74. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
our example: edge (u2,v4)
reappeared but is now unreachable
from s
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)
t
u1
u2
v3
v4
4
2
After the third flow augmentation
S
2
(2) Edmonds-Karp algorithm
augmenting path is found by breath-first search and has to be a shortest path from
p to t
75. Analysis of the Ford Fulkerson
algorithm
Running time with Edmonds-Karp algorithm
running time: O ( |V| |E|²
)
Idea:
(u,v) can become critical at most
O(|V|) times
O(|E|) pairs of vertices exist in
Gf
All critical edges in O(|V| |E|)
O(|E|) for breath first search for
p
total 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
76. Different variants of the max-flow
problem
- The algorithm of Dinic (different implementations reaps
better running times than Edmonds-Karp): e.g. simultanous
saturation of augmenting paths of the same length O(|V|² |E|)
- A second capacity function lim for a lower limit of the flow
function f with lim(u,v) < f(u,v) < c(u,v)
- A cost function cost where each edge (u,v) has got a second
weight cost(u,v) and the min-cost max-flow problem
- Networks with multiple sources and sinks
78. Ford Fulkerson – cuts of flow
networks
Assumption:
the value of a flow in a network is the net flow across any cut
of the network
Lemma:
f (S ,T) = | f
|
f (S, T) = f (S, VS)
= f (S, V) – f (S, S)
= f (S, V) = f (s [Ss], V)
= f (s, V) + f (Ss, V)
= f (s, V) = | f |
Working with flows:
X,Y,Z V and X Y =
f (X, Y) = f (x, y)
f (X, X) = 0
f (X, Y) = - f (Y, X)
f (u, V) = 0 for all u V {s, t}
f (X Y, Z) = f (X, Z) + f (Y, Z)
f (Z, X Y) = f (Z, X) + f (Z, Y)
x X y Y
Proof: