flow networks ford-fulkerson method edmonds-karp algorithm...
TRANSCRIPT
![Page 1: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/1.jpg)
CS 5633 Analysis of Algorithms Chapter 26: Slide – 1
Maximum Flow
Flow NetworksFord-Fulkerson MethodEdmonds-Karp AlgorithmPush-Relabel Algorithms
![Page 2: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/2.jpg)
Flow Networks
⊲ flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 2
A flow network is a directed graph where:Each edge (u, v) has a capacity c(u, v) ≥ 0.If (u, v) is not an edge, then c(u, v) = 0.There is a source vertex s and a sink vertex t.A flow f(u, v) satisfies the following constraints:
for all (u, v) ∈ V × V , 0 ≤ f(u, v) ≤ c(u, v)
for all (u, v) ∈ V × V , f(u, v) = 0 ∨ f(v, u) = 0
for all u ∈ V −{s, t},∑
v∈V
f(v, u) =∑
v∈V
f(u, v)
![Page 3: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/3.jpg)
Example Flow Network
flow networks
⊲ example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 3
![Page 4: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/4.jpg)
Maximum Flow
flow networks
example
⊲ flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 4
We want to maximize the flow F from s to t:
F =∑
v∈V
f(s, v) =∑
v∈V
f(v, t)
Algorithms for maximum flow can be used forliquids flowing through pipes,parts through assembly lines,current through electrical networks,information through communication networks,the maximum matching in a bipartite graph,and the minimum-size cut of a graph.
![Page 5: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/5.jpg)
Multiple Sources and Sinks
flow networks
example
flow networks
⊲multiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 5
![Page 6: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/6.jpg)
Ford-Fulkerson Method
flow networks
example
flow networksmultiplesources/sinks
⊲ ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 6
Let f(·, ·) be a flow. Define residual capacity cf
cf(u, v) = c(u, v)− f(u, v) + f(v, u)
Define residual edges Ef to be the edges withpositive residual capacity.
Ef = {(u, v) ∈ V × V : cf(u, v) > 0}
![Page 7: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/7.jpg)
Ford-Fulkerson Algorithm
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
⊲ ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 7
Ford-Fulkerson(G, s, t)for each edge (u, v) ∈ G.E
f [u, v] ← 0while ( there is a path p from s to t in Gf )
x ← min{cf(u, v) : (u, v) ∈ p}for each edge (u, v) ∈ p
y ← f [u, v]− f [v, u] + x
f [u, v] ← max(0, y)f [v, u] ← max(0,−y)
A maximum flow is found because every path froms to t is at full capacity.
![Page 8: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/8.jpg)
Ford-Fulkerson Example
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
⊲ ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 8
![Page 9: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/9.jpg)
Ford-Fulkerson Example Continued
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
⊲ ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 9
![Page 10: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/10.jpg)
Ford-Fulkerson and Minimum Cuts
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
⊲ minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 10
A cut (S, T ) of a flow network partitions V intovertices S and T = V − S s.t. s ∈ S and t ∈ T .
The capacity c(S, T ) of a cut (S, T ) is:∑
u∈S
∑
v∈T
c(u, v)
f(·, ·) is a maximum flow iff there is a cut (S, T ),where there is no flow from T to S, andthe flow from S to T = c(S, T ).In this case, (S, T ) is a minimum cut.Choose S = vertices reachable from s in Gf
![Page 11: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/11.jpg)
Edmonds-Karp Algorithm
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
⊲ edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 11
The Edmonds-Karp algorithm modifiesFord-Fulkerson by finding the shortest augmentingpath (as found by BFS).
Running time is O(V E2).
![Page 12: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/12.jpg)
Edmonds-Karp Residual Path Lengths
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
⊲ edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 12
Lemma: Residual path lengths do not decrease.
Suppose the distance from s to v decreased afteran iteration.
Let v be the closest vertex where this happens.
Some vertex u became adjacent to v
(otherwise v could not be closer).
This implies (v, u) is on augmenting path,but this implies u is farther from s than v.
A contradiction, so distances do not decrease.
![Page 13: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/13.jpg)
Edmonds-Karp Critical Edges
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
⊲ edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 13
Lemma: Each edge is critical O(V ) times.
Some cf(u, v) is minimum on an augmenting path.
This implies (u, v) removed from residual edges.
For (u, v) to reappear as a residual edge,(v, u) must be on augmenting path.
Because distance to v cannot decrease,distance to u must have increased.
Thie implies each edge can be minimal O(V )times.
![Page 14: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/14.jpg)
Maximum Bipartite Matching
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
⊲bipartitematching 1
bipartite matching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 14
An undirected graph G is a bipartite graph ifV = L∪ R and all edges are between L and R
(no edges within L or within R).
A matching is a subset of edges M ∈ E s.t. notwo edges share a vertex.
A maximum matching is a matching withmaximum cardinality.
![Page 15: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/15.jpg)
Example
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
⊲bipartitematching 2
bipartite matching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 15
![Page 16: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/16.jpg)
An Application
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
⊲bipartitematching 3
bipartite matching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 16
Suppose you have:a set of workers L,a set of jobs R, anda set of edges from L to R indicating whichworkers can do which jobs.
Suppose we can only assign one worker to one job,and we want to maximize the number ofworkers/jobs that are assigned.
The solution to this problem is a maximumbipartite matching.
![Page 17: Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm ...bylander/cs5633/notes/maximum-flow.pdf · Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms](https://reader030.vdocument.in/reader030/viewer/2022020214/5ab30c267f8b9ad9788dbeb4/html5/thumbnails/17.jpg)
Conversion to Maximum Flow
flow networks
example
flow networksmultiplesources/sinks
ford-fulkerson 1
ford-fulkerson 2
ford-fulkerson 3
ford-fulkerson 4
minimum cut
edmonds-karp 1
edmonds-karp 2
edmonds-karp 3
bipartite matching 1
bipartite matching 2
bipartite matching 3
⊲bipartitematching 4
CS 5633 Analysis of Algorithms Chapter 26: Slide – 17
Create a directed graph G′ with V ′ = V ∪ {s, t}
Add an edge from s to each vertex in L.
For each edge (l, r) ∈ E,add a directed edge (l, r) to G′.
Add an edge from each vertex in R to t.
All edges have a capacity of 1.
A maximum flow found by Ford-Fulkerson is amaximum matching for G.