1 / 29

Flow networks

Flow networks. 2. 5. 1. How much flow can we push through from s to t ? (Numbers are capacities.). 4. 7. 3. 2. 5. 2. Flow networks. 5. 1. s. 4. 7. t. 3. 2. 5. Def:

criddick
Télécharger la présentation

Flow networks

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Flow networks 2 5 1 How much flow can we push through from s to t ? (Numbers are capacities.) 4 7 3 2 5

  2. 2 Flow networks 5 1 s 4 7 t 3 2 5 • Def: • A flow network is a directed graph G=(V,E) where edges have capacities c:E->R+. There are two specified vertices s (source) and t (sink). • A flow f:E->R must satisfy: • Capacity constraint: for every edge e: f(e) · c(e) • Flow conservation: • for every v in V-{s,t}: e out of v f(e) = e into v f(e) • The value of the flow is: e out of s f(e)

  3. Maximum flow problem Input: a flow network G=(V,E), with capacities c, the source s and sink t Output: a maximum-value flow Algorithm ? 2 5 1 s 4 7 t 3 2 5

  4. Maximum flow problem – Ford-Fulkerson “Def”: Given a flow f, an augmenting path is a path s=v1, v2, …, vk=t such that f(vi,vi+1) < c(vi,vi+1) for i=1,…,k-1 2 5 1 s 4 2 t 3 7 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  5. Maximum flow problem – Ford-Fulkerson “Def”: Given a flow f, an augmenting path is a path s=v1, v2, …, vk=t such that f(vi,vi+1) < c(vi,vi+1) for i=1,…,k-1 How to find augmenting paths ? 2 5 1 s 4 2 t 3 7 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  6. Maximum flow problem – Ford-Fulkerson “Def”: Given is G=(V,E), c, f. The residual graph has edges weighted by the residual capacities, i.e. cf(e) = c(e)-f(e) 2 5 1 s 4 2 t 3 7 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  7. Maximum flow problem – Ford-Fulkerson “Def”: Given is G=(V,E), c, f. The residual graph has edges weighted by the residual capacities, i.e. cf(e) = c(e)-f(e) Idea: Find an s-t path in the residual graph! 2 5 1 s 4 2 t 3 7 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  8. Maximum flow problem – Ford-Fulkerson Consider this input: 1000 1000 s 1 t 1000 1000 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  9. Maximum flow problem – Ford-Fulkerson Consider this input: Need to refine the definition of augmenting paths and residual graph. 1000 1000 s 1 t 1000 1000 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  10. Maximum flow problem – Ford-Fulkerson • Refined def: • Given is G=(V,E), c, f. The residual graph Gf=(V,E’) contains the following edges: • forward edge: if e 2 E and f(e) < c(e) then include e in E’ with weight • cf(e) = c(e)-f(e), • backward edge: if e=(u,v) 2 E with f(e)>0 then include (v,u) in E’ with weight • cf(v,u) = f(v,u). 1000 1000 s 1 t 1000 1000

  11. Maximum flow problem – Ford-Fulkerson 1000 1000 s 1 t 1000 1000

  12. Maximum flow problem – Ford-Fulkerson • Ford-Fulkerson ( G=(V,E), c, s, t ) • For every edge e let f(e)=0 • 2. Construct the residual graph Gf • While exists s-t path in Gf do • Let p be an s-t path in Gf • Let d=mine in p cf(e) • For every e on p do • If e is a forward edge then • f(e)+=d • else • f(reverse(e))-=d • Update Gf (construct new Gf) • Return f

  13. Maximum flow problem – Ford-Fulkerson • Ford-Fulkerson ( G=(V,E), c, s, t ) • For every edge e let f(e)=0 • 2. Construct the residual graph Gf • While exists s-t path in Gf do • Let p be an s-t path in Gf • Let d=mine in p cf(e) • For every e on p do • If e is a forward edge then • f(e)+=d • else • f(reverse(e))-=d • Update Gf (construct new Gf) • Return f Running time:

  14. Maximum flow problem – Ford-Fulkerson Lemma: Ford-Fulkerson works. 2 5 1 s 4 1 t 3 7 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  15. Maximum flow problem – Ford-Fulkerson Lemma: Ford-Fulkerson works. Def: Given G=(V,E), c. An s-t cut of G is a subset of vertices S s.t. s 2 S and t 2 SC. Its value is e out of S c(e) 2 5 1 s 4 7 t 3 2 5

  16. Maximum flow problem – Ford-Fulkerson Lemma: Ford-Fulkerson works. The Max-flow min-cut theorem: Let min-cut(G) be the minimal value of an s-t cut of G. Then: f is a maximum flow iff value(f)=min-cut(G) 2 5 1 s 4 7 t 3 2 5

  17. Improving Ford-Fulkerson Can find better paths to reduce the running time? 2 5 1 s 4 7 t 3 2 5 • Ford-Fulkerson ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augmenting path p do • Augment flow f along p • Return f

  18. Improving Ford-Fulkerson Can find better paths to reduce the running time? - many ways, will discuss one: BFS 2 5 1 s 4 7 t 3 2 5 • Edmonds-Karp ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augm. path p (check with BFS) do • Augment flow f along p • Return f

  19. Improving Ford-Fulkerson • Can find better paths to reduce the running time? • many ways, will discuss one: BFS • Thm: Edmonds-Karp takes O(|V||E|) iterations. • Running time of Edmonds-Karp: 2 5 1 s 4 7 t 3 2 5 • Edmonds-Karp ( G=(V,E), c, s, t ) • Initialize flow f to 0 • While exists augm. path p (check with BFS) do • Augment flow f along p • Return f

  20. Applications of Network Flows • multiple sources, multiple sinks s1 t1 t2 s2 t3 s3 t4

  21. Applications of Network Flows • how to find minimum cut 2 5 1 s 4 7 t 3 7 5

  22. Applications of Network Flows • maximum number of edge-disjoint s-t paths s t

  23. Applications of Network Flows • maximum bipartite matching

  24. Applications of Network Flows • maximum weighted (perfect) bipartite matching 7 5 2 3 4 4 1 6 3 8

  25. Introduction to Linear Programming Let’s write maximum flow as a math problem…

  26. Introduction to Linear Programming The Diet Problem – another example of LP Input: m types of food F1,…,Fm with unit costs b1,…,bm n types of nutrients N1,…,Nn with min. daily requirements c1,…,cn ai,j amount of nutrient Nj contained in one unit of food Fi Objective: get the required nutrients at minimum cost

  27. Introduction to Linear Programming A linear program looks like this: • Find x1, x2, …, xm which • maximize • c1x1 + c2x2 + … + cmxm • and satisfy these constraints: a1,1x1 + a1,2x2 + … + a1,mxm· b1 a2,1x1 + a2,2x2 + … + a2,mxm· b2 … an,1x1 + an,2x2 + … + an,mxm· bn

  28. Introduction to Linear Programming A linear program in compressed form: Given a vector c in Rm, a vector b in Rn and a matrix A in Rn x m, find a vector x in Rm which satisfies xAT· b and maximizes cxT.

  29. Introduction to Linear Programming A linear program in compressed form: Given a vector c in Rm, a vector b in Rn and a matrix A in Rn x m, find a vector x in Rm which satisfies xAT· b and maximizes cxT. Thm: Exists a polynomial-time algorithm solving linear programs. Caveat: Sometimes need integer programs (no algorithm for integer programs is likely to exist) !

More Related