Download presentation

Presentation is loading. Please wait.

1
**Maximum flow Main goals of the lecture:**

to understand how flow networks and maximum flow problem can be formalized; to understand the Ford-Fulkerson method and to be able to prove that it works correctly; to understand the Edmonds-Karp algorithm and the intuition behind the analysis of its worst-case running time. to be able to apply the Ford-Fulkerson method to solve the maximum-bipartite-matching problem.

2
Flow networks What if weights in a graph are maximum capacities of some flow of material? Pipe network to transport fluid (e.g., water, oil) Edges – pipes, vertices – junctions of pipes Data communication network Edges – network connections of different capacity, vertices – routers (do not produce or consume data just move it) Concepts (informally): Source vertex s (where material is produced) Sink vertex t (where material is consumed) For all other vertices – what goes in must go out Goal: maximum rate of material flow from source to sink

3
**Formalization How do we formalize flows?**

Graph G=(V,E) – a flow network Directed, each edge has capacity c(u,v) ³ 0 Two special vertices: source s, and sink t For any other vertex v, there is a path s®…®v®…®t Flow – a function f : V ´ V ® R Capacity constraint: For all u, v Î V: f(u,v) £ c(u,v) Skew symmetry: For all u, v Î V: f(u,v) = –f(v,u) Flow conservation: For all u Î V – {s, t}:

4
Cancellation of flows Do we want to have positive flows going in both directions between two vertices? No! such flows cancel (maybe partially) each other Skew symmetry – notational convenience 13 11 5 4 15 10 14 19 3 s t 9 a b c d 6 13 11 5 4 15 10 14 19 3 s t 9 a b c d 2 6

5
**Maximum flow What do we want to maximize? Value of the flow f:**

13 11 5 4 15 10 14 19 3 s t 9 a b c d 8 6 2 We want to find a flow of maximum value!

6
**Augmenting path Idea for the algorithm: If we have some flow,…**

…and can find a path p from s to t (augmenting path), such that there is a > 0, and for each edge (u,v) in p we can add a units of flow: f(u,v) + a £ c(u,v) Then just do it, to get a better flow! Augmenting path in this graph? 13 11 5 4 15 10 14 19 3 s t 9 a b c d 8 6 2

7
**The Ford-Fulkerson method**

Sketch of the method: Ford-Fulkerson(G,s,t) 01 initialize flow f to 0 everywhere 02 while there is an augmenting path p do 03 augment flow f along p 04 return f How do we find augmenting path? How much additional flow can we send through that path? Does the algorithm always find the maximum flow?

8
**Residual network How do we find augmenting path?**

It is any path in residual network: Residual capacities: cf(u,v) = c(u,v) – f(u,v) Residual network: Gf=(V,Ef), where Ef = {(u,v) Î V ´ V : cf(u,v) > 0} What happens when f(u,v) < 0 (and c(u,v) = 0)? Observation – edges in Ef are either edges in E or their reversals: |Ef| £ 2|E| 13 11 5 4 15 10 14 19 3 s t 9 a b c d 8 6 2 Compute residual network:

9
**Residual capacity of a path**

How much additional flow can we send through an augmenting path? Residual capacity of a path p in Gf: cf(p) = min{cf(u,v): (u,v) is in p} Doing augmentation: for all (u,v) in p, we just add this cf(p) to f(u,v) (and subtract it from f(v,u)) Resulting flow is a valid flow with a larger value. What is the residual capacity of the path (s,a,b,t)?

10
**Cuts Does it always find the maximum flow?**

A cut is a partition of V into S and T = V – S, such that s Î S and t Î T The net flow (f(S,T)) through the cut is the sum of flows f(u,v), where u Î S and v Î T The capacity (c(S,T)) of the cut sum of capacities c(u,v), where u Î S and v Î T Minimum cut – a cut with the smallest capacity of all cuts |f|= f(S,T) 13 11 5 4 15 10 14 19 3 s t 9 a b c d 8 6 1

11
**Correctness of Ford-Fulkerson**

Max-flow min-cut theorem: If f is the flow in G, the following conditions a re 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 We have to prove three parts: From this we have 1.Û2., which means that the Ford-Fulkerson method always correctly finds a maximum flow 1. 2. 3.

12
**Basic Ford-Fulkerson algorithm**

Running time: if capacities are in irrational numbers, the algorithm may not terminate. Otherwise, O(|E||f*|) where f* is the maximum flow found by the algorithm: while loop runs f* times, increasing f* by one each loop, finding an augmenting path using depth- first search or breadth-first search costs |E|.

13
**Execution of Ford-Fulkerson**

15
**An example of loop |f*| times**

Note: if finding an augmenting path uses breadth-first search, i.e., each augmenting path is a shortest path from s to t in the residue network, while loop runs at most O(|V||E|) times (in fact, each edge can become critical at most |V|/2-1 times), so the total cost is O(|V||E|2). Called Edmonds-Karp algorithm.

16
**Worst-case running time**

What is the worst-case running time of this method? Let’s assume integer flows. Each augmentation increases the value of the flow by some positive amount. Augmentation can be done in O(E). Total worst-case running time O(E|f*|), where f* is the max-flow found by the algorithm. Can we run into this worst-case? Lesson: how an augmenting path is chosen is very important!

17
**The Edmonds-Karp algorithm**

Find the augmenting path using breadth-first search. Breadth-first search gives the shortest path for graphs (Assuming the length of each edge is 1.) Time complexity of Edmonds-Karp algorithm is O(VE2). The proof is very hard and is not required here.

18
**Edmonds-Karp(G , s , t) for each edge (u,v) E[G] do f[u,v] = 0**

f[v,u] = 0 Gf= G p = BFS-shortest-path(Gf) while p exists do cf(p) = min { cf(u,v) : (u,v) is in p } for each edge (u,v) in p do f[u,v] = f[u,v] + cf(p) f[u,v]= - f[u,v] Gf= residual network(G,f) P = BFS-shortest-path(Gf)

19
Demo example

20
**the residual network Gf through the shortest path S«-- V1«-- V3«-- T **

The original flow network G Flow is augmented on the residual network Gf through the shortest path S«-- V1«-- V3«-- T with residual capacity of 12

21
The flow is updated on the flow network and the residual network is recalculated Flow is augmented on Gf through the shortest path S«-- V2«-- V4«-- T with residual capacity of 4

22
The flow is updated on the flow network and the residual network is recalculated Flow is augmented on Gf through the shortest path S«--V2«--V4«--V3«--T with residual capacity of 7

23
The flow is updated on the flow network and the residual network is recalculated There are no more paths from the source to the sink and so the minimal cut is found separating vertexes reachable from the seed from the remaing vertexes.

24
**Analysis of Edmonds-Karp algorithm**

Take shortest path (in terms of number of edges) as an augmenting path – Edmonds-Karp algorithm How do we find such a shortest path? Running time O(VE2), because the number of augmentations is O(VE) To prove this we need to prove that: The length of the shortest path does not decrease Each edge can become critical at most ~ V/2 times. Edge (u,v) on an augmenting path p is critical if it has the minimum residual capacity in the path: cf(u,v) = cf(p)

25
**Non-decreasing shortest paths**

Why does the length of a shortest path from s to any v does not decrease? Observation: Augmentation may add some edges to residual network or remove some. Only the added edges (“shortcuts”) may potentially decrease the length of a shortest path. Let’s supose (s,…,v) – the shortest decreased-length path and let’s derive a contradiction

26
**Number of augmentations**

Why each edge can become critical at most ~V/2 times? Scenario for edge (u,v): Critical the first time: (u,v) on an augmenting path Disappears from the network Reappears on the network: (v,u) has to be on an augmenting path We can show that in-between these events the distance from s to u increased by at least 2. This can happen at most V/2 times We have proved that the running time of Edmonds-Karp is O(VE2).

27
**Multiple sources or sinks**

What if we have more sources or sinks? Augment the graph to make it with one source and one sink! 13 11 5 4 10 9 s1 t1 s2 t2 s3 7 6 8 13 11 5 4 10 s t 9 s1 t1 s2 t2 s3 7 6 8

28
**Application of max-flow**

Maximum bipartite matching problem Matching in a graph is a subset M of edges such that each vertex has at most one edge of M incident on it. It puts vertices in pairs. We look for maximum matching in a bipartite graph, where V = L È R, L and R are disjoint and all edges go between L and R Dating agency example: L – women, R – men. An edge between vertices: they have a chance to be “compatible” (can be matched) Do as many matches between “compatible” persons as possible

29
**Maximum bipartite matching**

Matching in a undirected graph G=(V,E) A subset of edges ME, such that for all vertices vV, at most one edge of M is incident on v. Maximum matching M For any matching M′, |M|| M′|. Bipartite: V=LR where L and R are distinct and all the edges go between L and R. Practical application of bipartite matching: Matching a set L of machines with a set R of tasks to be executed simultaneously. The edge means that a machine can execute a task.

30
**Copyright © The McGraw-Hill Companies, Inc**

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

31
**Finding a maximum bipartite matching**

Construct a flow network G′=(V′,E′,C) from G=(V,E) as follows where =LR: V′=V{s,t}, introducing a source and a sink E′={(s,u): uL} E {(v,t): vR} For each edge, its capacity is unit 1. As a result, the maximum flow in G′ is a maximum matching in G.

32
**Copyright © The McGraw-Hill Companies, Inc**

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Similar presentations

OK

Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.

Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Open ppt on ipad with keynote Ppt on art of war game Ppt on south african cultures Ppt on forward rate agreement quote Ppt on team building and motivation Ppt on synthesis and degradation of purines and pyrimidines are what Ppt on revolution and rotation of the earth Ppt on market value added Ppt on tribal communities of india Ppt on sea level rise data