Ford-Fulkerson Algorithm
Overview
� Network flows on directed acyclic graphs
� Ford-Fulkerson Algorithm
-Residual networks
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
Network flows on directed acyclic graphsNetwork flows on directed acyclic graphs
� DAG is a directed graph with no cycles.
� Flow network:– Flow network G = (V,E) is a directed graph in which each edge (u,v) ∈∈∈∈ EEEE
hashashashas aaaa nonnegativenonnegativenonnegativenonnegative capacitycapacitycapacitycapacity c(c(c(c(u,vu,vu,vu,v)))) >=>=>=>= 0000....– IfIfIfIf ((((u,vu,vu,vu,v)))) ∉∉∉∉ E , we assume that c(u,v) = 0.
� Distinguished vertices: source s,s, and sink tt.– Source: produces the material at a steady rate .
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
– Source: produces the material at a steady rate .
– Sink: consumes the material at a steady rate.
� Objective : compute how much material can flow through thenetwork
Flow: A flow in G is a real-valued function f : V × V → R that satisfies three properties:
� 1. Capacity constraint : For all u,v ∈∈∈∈ V, we require f(u,v) ≤ c(u,v).– The net flow from one vertex to another must not exceed the given capacity.
� 2. Skew symmetry : For all u,v ∈ ∈ ∈ ∈ V, we require f(u,v) = -f(v,u).
� The net flow from a vertex u to a vertex v is the negative of the net flow in the other direction
� 3. Flow conservation : For all u ∈∈∈∈ V - {s,t}, we require
Network Network PropertiesProperties
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
� 3. Flow conservation : For all u ∈∈∈∈ V - {s,t}, we require
∑ f(u,v) = 0.
v ∈ ∈ ∈ ∈ V
The quantity f(u,v),which can be positive or negative , is called the net flow from vertex u to v.
The value of the flow is defined as | f | = ∑ f(s,v) that is the total net
v ∈∈∈∈ V
Flow out of the source.
Residual Capacity
� Given a flow f in network G = (V, E).
� Consider a pair of vertices u, v ∈∈∈∈ V.
� Residual capacity: – The amount of additional flow we can push directly from u to v.
– cf (u, v) = c(u, v) −−−− f (u, v)
v
u16/ 11
5
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
– cf (u, v) = c(u, v) −−−− f (u, v)≥ 0 (since f (u, v) ≤ c(u, v))
� Example:– c(u,v) = 16, f(u,v) = 5 ���� cf (u, v) = 11
Residual Network
� Residual network: Gf = (V, Ef ),
Ef = {(u, v) ∈∈∈∈ V × V : cf (u, v) > 0} .
� Each edge of the residual network can admit a positive flow.
� Given flows f1 and f2, the flow sum
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
� Given flows f1 and f2, the flow sum f1 + f2 is
– (f1 + f2)(u, v) = f1(u, v) + f2(u, v) for all u, v ∈∈∈∈ V.
Flow Networks: Simple Example
s t
a4
1
2
s t
a4
2
000
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
53
1
originalresidual
s
b
t5
3
10
00
0
Example p.2
s
b
t
a
5
4
2
0
1
0
01
1
1 s
b
t
a
5
3
2
0
0
0
11
1
2
Step 2: path {s,a,t}
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
a
3
3
0
0
0
2
11
3
2
Step 1: path {s,a,b,t}Step 2: path {s,a,t}
Step 3:Path {s,b,t}
Example: p.3
s t
a
3
3
0
01
12s t
a
2
2
1
02
02
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
b
30
23
b
20
33
Step 3 Step 4
Example: Max-Flow Min-Cut
s t
a4
1
2
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
5 3
1
Ford-Fulkerson Algorithm
� The Ford_Fulkerson method is iterative,
� Starts with f(u,v) for (u,v) ∈∈∈∈ V, initial flow of value 0.
� The method is based on the augmenting path
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
� The method is based on the augmenting path– a path from s to t along which we can push more flow and
then augment flow along this path.
Ford-Fulkerson Algorithm
Ford-Fulkerson(G, s, t) ; G = (V, E) 1 for each edge (u,v) in E 2 f(u,v) = f(v,u) = 0 3 while ∃∃∃∃ path p from s to t in residual network Gf4 do cf (p) = min{cf (u, v) : (u, v) is in p}
5 for each edge (u,v) on p
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
5 for each edge (u,v) on p 6 f(u,v) = f(u,v) + cf (p) 7 f(v,u) = -f(u,v)
� Running time for this algorithms is O(E * |f*|) where f* is the maximum flow found by algorithm.
� First three Lines take time θ(E).
Complexity: Ford-Fulkerson Algorithm
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
� First three Lines take time θ(E).
� The while loop of last five lines is executed at most |f*| times, since the flow value increases by at least one unit in each iteration.
s t
v1 v2
v4v313
16
12
20
14
4
104
9
7
Example:
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
v4v3 4
s t
v1 v2
v4v313
4/16
4/12
20
4/14
4/4
104
4/9
7
s t
v1 v2
v4v313
12
8
20
10
4
104
5
474
4
4
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
4
s t
v1 v2
v4v313
11/16 7/20
11/14
4/4
7/104
4/9
7/7
4/12
s t
v1 v2
v4v313
5
8
13
3
4
311
5
4711
11
4
7
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
11
s t
v1 v2
v4v38/13
11/16 15/20
11/14
4/4
101/4
4/9
7/7
12/12
s t
v1 v2
v4v3
8
5
12
5
3
4
113
5
471115
5
11
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
11
s
v1 v2
v4v312/13
11/16
11/14
4/4
101/4 9
7/7
12/12
t
19/20
s t
v1 v25
121
113
9
711 19
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s t
v4v3
1 3 4
117
11 19
12
11
Reference
� Class Notes from Dr. Istvan Jonyer of
Oklahoma State University
� Class Notes from UTexas CSE 5311 of 2004,
made by Hiren Patel, Ujjval Patel
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
Backup: simple network
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
Consider the network G=(V,E) shown in the figure below. Each
edge (u,v) ∈∈∈∈ E in the network is labeled with its capacity c(u,v).
s
b
t
a
5
4
3
1
2
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
b3
s
b
t
a
5
4
3
1
2
Flow: 1
1
11
Residual graph
s
b
t
a
5
4
2
1
1
1
1
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
a
5
1/4
1/3
1/1
2/2
Residual graph
s
b
t
a
5
3
2
1
2
1
1
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
a
1/5
2/4
1/3
0/1
2/2
s
b
t
a
4
2
2
1
2
1 1
2
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t
a
3/5
2/4
3/3
1
2/2
a2
22
CS 4407, Algorithms , University College Cork,, Gregory M. Provan
s
b
t2
3
1
3
2
Max Flow : 5