the ford-fulkerson algorithm
DESCRIPTION
The Ford-Fulkerson Algorithm. aka The Labeling Algorithm. Ford-Fulkerson Algorithm. begin x := 0; label node t; while t is labeled do begin unlabel all nodes; pred(j) := 0 for all j in N; label s; LIST := {s}; while LIST is not empty and t is not labeled do - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/1.jpg)
The Ford-Fulkerson Algorithm
aka The Labeling Algorithm
![Page 2: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/2.jpg)
Ford-Fulkerson Algorithmbegin x := 0; label node t; while t is labeled do begin unlabel all nodes; pred(j) := 0 for all j in N; label s; LIST := {s}; while LIST is not empty and t is not labeled do begin remove a node i from LIST; for all {j in N: (i,j) in A and rij > 0} do if j is unlabeled then pred(j) := i, label j, add j to LIST; end; if t is labeled then augment flow on path from s to t end;end;
![Page 3: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/3.jpg)
Labeling Algorithm Example
s t1
2 4
3
(0,2)
(0,6)
5(0,5)
6
(0,5) (0,4)
(0,4)
(0,7)
![Page 4: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/4.jpg)
The Residual Network G(x)
s t1
2 4
3 5
6
5
0
0
6
2
0
5
0
40
4
0
07
![Page 5: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/5.jpg)
Iteration 1: LIST = {1}, Labeled = {1}
s t1
2 4
3 5
6
5
0
0
6
2
0
5
0
40
4
0
70
i = 1
![Page 6: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/6.jpg)
Iteration 1: LIST = {1}, Labeled = {1}
• i = 1• LIST = {}• Arc (1,2)
– pred(2) =1– label 2– LIST = {2}
• Arc (1,3) – pred (3) = 1– label 3– LIST = {2, 3}
![Page 7: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/7.jpg)
Iteration 1: LIST = {2,3}, Labeled= {1,2,3}
s t1
2 4
3 5
6
5
0
0
6
2
0
5
0
40
4
0
07
pred(2) = 1
pred(3) = 1
![Page 8: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/8.jpg)
Iteration 1: LIST = {2,3}, Labeled = {1,2,3}
• i = 2• LIST = {3}• Arc (2,4)
– pred(4) =2– label 4– LIST = {3,4}
• Arc (2,5) – pred (5) = 2– label 5– LIST = {3,4,5}
• Arc (2,1)– residual capacity
of (2,1) = 0
![Page 9: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/9.jpg)
Iteration 1: LIST = {3,4,5}, Labeled= {1,2,3,4,5}
s t1
2 4
3 5
6
5
0
0
6
2
0
5
0
40
4
0
07
pred(2) = 1
pred(3) = 1 pred(5) = 2
pred(4) = 2
![Page 10: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/10.jpg)
Iteration 1: LIST = {3,4,5}, Labeled = {1,2,3,4,5}
• i = 3• LIST = {4,5}• Arc (3,5)
– 5 is already labeled
• Arc (3,1) – residual capacity of (3,1) = 0
![Page 11: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/11.jpg)
Iteration 1: LIST = {4,5}, Labeled = {1,2,3,4,5}
• i = 4• LIST = {5}• Arc (4,2)
– residual capacity of (4,2) = 0• Arc (4,6)
– pred(6) =4– label 6– LIST = {5,6}
![Page 12: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/12.jpg)
Iteration 1: LIST = {5,6}, Labeled= {1,2,3,4,5,6}
s t1
2 4
3 5
6
5
0
0
6
2
0
5
0
40
4
0
07
pred(2) = 1
pred(3) = 1 pred(5) = 2
pred(4) = 2
pred(6) = 4
![Page 13: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/13.jpg)
Iteration 1: The sink is labeled
• Use pred labels to trace back from the sink to the source to find path P– P = 1 -> 2 -> 4 -> 6
= min {rij: (i,j) in P) = 2• Send 2 units of flow from to s to t
along path P
![Page 14: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/14.jpg)
Flow x After Iteration 1
s t1
2 4
3
(2,2)
(0,6)
5(0,5)
6
(2,5) (2,4)
(0,4)
(0,7)
v = 2
![Page 15: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/15.jpg)
The Residual Network G(x)
s t1
2 4
3 5
6
3
2
0
6
0
2
5
0
40
2
2
07
![Page 16: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/16.jpg)
Iteration 2: LIST = {1}, Labeled = {1}• i = 1• LIST = {}• Arc (1,2)
– pred(2) =1– label 2– LIST = {2}
• Arc (1,3) – pred (3) = 1– label 3– LIST = {2, 3}
![Page 17: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/17.jpg)
Iteration 2: LIST = {2,3}, Labeled={1,2,3}
s t1
2 4
3 5
6
3
2
0
6
0
2
5
0
40
2
2
07
p=1
p=1
![Page 18: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/18.jpg)
Iteration 2: LIST = {2,3}, Labeled = {1,2,3}
• i = 2• LIST = {3}• Arc (2,4)
– residual cap (2,4) = 0
• Arc (2,5) – pred (5) = 2– label 5– LIST = {3,5}
• Arc (2,1)– residual capacity
of (2,1) = 0
![Page 19: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/19.jpg)
Iteration 2: LIST = {3,5}, Labeled={1,2,3,5}
s t1
2 4
3 5
6
3
2
0
6
0
2
5
0
40
2
2
07
p=1
p=1 p=2
![Page 20: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/20.jpg)
Iteration 2: LIST = {3,5}, Labeled = {1,2,3,5}
• i = 3• LIST = {5}• Arc (3,5)
– 5 is already labeled
• Arc (3,1) – residual
capacity of (3,1) = 0
• i = 5• LIST = {}• Arc (5,2)
– residual cap = 0
• Arc (5,3)– residual cap = 0
• Arc (5,6) – pred(6) = 5– label 6– LIST = {6}
![Page 21: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/21.jpg)
Iteration 2: LIST = {6}, Labeled={1,2,3,5,6}
s t1
2 4
3 5
6
3
2
0
6
0
2
5
0
40
2
2
07
p=1
p=1 p=2
p=5
![Page 22: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/22.jpg)
Iteration 2: The sink is labeled
• Use pred labels to trace back from the sink to the source to find path P– P = 1 -> 2 -> 5 -> 6
= min {rij: (i,j) in P) = 3• Send 3 units of flow from to s to t
along path P
![Page 23: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/23.jpg)
Flow x After Iteration 2
s t1
2 4
3
(2,2)
(0,6)
5(0,5)
6
(5,5) (2,4)
(3,4)
(3,7)
v = 5
![Page 24: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/24.jpg)
The Residual Network G(x)
s t1
2 4
3 5
6
0
5
0
6
0
2
5
0
13
2
2
04
![Page 25: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/25.jpg)
Iteration 3: LIST = {1}, Labeled = {1}• i = 1• LIST = {}• Arc (1,2)
– residual capacity = 0• Arc (1,3)
– pred (3) = 1– label 3– LIST = {3}
![Page 26: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/26.jpg)
Iteration 3: List = {3}, Labeled = {1,3}
s t1
2 4
3 5
6
0
5
0
6
0
2
5
0
13
2
2
04
p=1
![Page 27: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/27.jpg)
Iteration 3: LIST = {3}, Labeled =
{1,3}• i = 3• LIST = {}• Arc (3,1)
– residual capacity = 0• Arc (3,5)
– pred (5) = 3– label 5– LIST = {5}
![Page 28: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/28.jpg)
Iteration 3: List = {5}, Labeled = {1,3,5}
s t1
2 4
3 5
6
0
5
0
6
0
2
5
0
13
2
2
04
p=1 p=2
![Page 29: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/29.jpg)
Iteration 3: LIST = {5}, Labeled =
{1,3,5}• i = 5, LIST = {}• Arc (5,2)
– pred(2) = 5– label 2– LIST = {2}
• Arc (5,3): residual capacity = 0• Arc (5,6)
– pred (6) = 5– label 6– LIST = {2,6}
![Page 30: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/30.jpg)
Iteration 3: List = {2,6}, Labeled = {1,2,3,5,6}
s t1
2 4
3 5
6
0
5
0
6
0
2
5
0
13
2
2
04
p=1 p=2
p=5
p=5
![Page 31: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/31.jpg)
Iteration 3: The sink is labeled
• Use pred labels to trace back from the sink to the source to find path P– P = 1 -> 3 -> 5 -> 6
= min {rij: (i,j) in P) = 4• Send 4 units of flow from to s to t
along path P
![Page 32: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/32.jpg)
Flow x After Iteration 3
s t1
2 4
3
(2,2)
(4,6)
5(4,5)
6
(5,5) (2,4)
(3,4)
(7,7)
v = 9
![Page 33: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/33.jpg)
The Residual Network G(x)
s t1
2 4
3 5
6
0
5
4
2
0
2
1
4
13
2
2
70
![Page 34: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/34.jpg)
Iteration 4: LIST = {1}, Labeled = {1}• i = 1• LIST = {}• Arc (1,2)
– residual capacity = 0• Arc (1,3)
– pred (3) = 1– label 3– LIST = {3}
![Page 35: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/35.jpg)
Iteration 4: List = {3}, Labeled = {1,3}
s t1
2 4
3 5
6
0
5
4
2
0
2
1
4
13
2
2
70
p=1
![Page 36: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/36.jpg)
Iteration 4: LIST = {3}, Labeled =
{1,3}• i = 3• LIST = {}• Arc (3,1)
– 1 is labeled• Arc (3,5)
– pred (5) = 3– label 5– LIST = {5}
![Page 37: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/37.jpg)
Iteration 4: List = {5}, Labeled = {1,3,5}
s t1
2 4
3 5
6
0
5
4
2
0
2
1
4
13
2
2
70
p=1 p=3
![Page 38: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/38.jpg)
Iteration 4: LIST = {5}, Labeled =
{1,3,5}• i = 5• LIST = {}• Arc (5,2)
– pred(2) = 5– label 2– LIST = {2}
• Arc (5,6) – residual capacity = 0
![Page 39: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/39.jpg)
Iteration 4: List = {2}, Labeled = {1,2,3,5}
s t1
2 4
3 5
6
0
5
4
2
0
2
1
4
13
2
2
70
p=1 p=3
p=5
![Page 40: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/40.jpg)
Iteration 4: LIST = {2}, Labeled =
{1,2,3,5}• i = 2 LIST = {}• Arc (2,1)
– 1 is already labeled
• Arc(2,4)– residual capacity = 0
• Arc (2,5) – 5 is already labeled
![Page 41: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/41.jpg)
Iteration 4: List = {}
• The sink is not labeled• Algorithm ends with optimal flow x
![Page 42: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/42.jpg)
Correctness
• At the end of each iteration, the algorithm either augments the flow or terminates because it can’t label the sink.
• Let S be the set of labeled nodes when the algorithm terminates. Let T = N \ S.
• We need to show that when the algorithm terminates v = u[S,T] which implies x is a maximum flow.
![Page 43: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/43.jpg)
Correctness: arcs in (S,T)
• rij = 0• rij = uij - xij + xji• 0 = uij – xij + xji• xij = uij + xji
Since xji must be at least zero and 0 xij uij,it follows that xij = uij.
i js
![Page 44: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/44.jpg)
Correctness: arcs in (T,S)
• Suppose xij > 0• rji = uji – xji + xij• Implies rji > 0 (uji xji)
i j s
• Implies s can reach i in residual network which means i should have been labeled.
• Thus, xij = 0
![Page 45: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/45.jpg)
Correctness
].,[
thisshowedjust We0
flow feasible a is x since
),(),(
),(),(),(),(
TSu
v
TSjiij
STjiij
TSjiij
u
xx
This means x is a maximum flow by Property 6.1.
Thus, the flows on the forward arcs in [S,T] are at the upper bound and there is no flow on any of the backwards arcs.
![Page 46: The Ford-Fulkerson Algorithm](https://reader036.vdocuments.us/reader036/viewer/2022070401/56813629550346895d9da2ea/html5/thumbnails/46.jpg)
Complexity
• Let U = max {(i,j) in A} uij.• If S = {s} and T = N\{s}, then u[S,T] is
at most nU.• The maximum flow is at most nU.• Iteration of the inner while loop is O(m):
– Each arc is inspected at most once– Finding is O(n)– Updating the flow on P is O(n)
• Complexity is O(nU x m) = O(nmU).