1 / 33

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:

frankwood
Download Presentation

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) - e into 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 Input: a flow network G=(V,E), with capacities c, the source s and sink t Output: a maximum-value flow Algorithm ? 2 5 5 s 4 7 t 3 6 5

  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 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 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

  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) 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 “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

  9. 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

  10. 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

  11. 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(u,v). 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 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

  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. Maximum flow problem – Ford-Fulkerson Lemma: Ford-Fulkerson works. 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? 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

  19. Improving Ford-Fulkerson • Can find better paths to reduce the running time? • many ways, will discuss two: • Scaling paths • BFS 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

  20. Improving Ford-Fulkerson • Can find better paths to reduce the running time? • many ways, will discuss two: • Scaling paths 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

  21. Improving Ford-Fulkerson • Can find better paths to reduce the running time? • many ways, will discuss two: • Scaling paths • 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

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

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

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

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

  26. Applications of Network Flows • maximum bipartite matching

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

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

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

  30. Introduction to Linear Programming • Consider the Diet problem: • n food items, m nutrients • for every nutrient: the daily quota bj • for each item: cost per pound ci • for every item and nutrient: how much of the nutrient in a pound of item: ai,j

  31. Introduction to Linear Programming A linear program looks like this: • Find x1, x2, …, xn which • minimize • c1x1 + c2x2 + … + cnxn • and satisfy these constraints: a1,1x1 + a2,1x2 + … + an,1xn >= b1 a1,2x1 + a2,2x2 + … + an,2xn >= b2 … a1,mx1 + a2,mx2 + … + am,nxn >= bm

  32. Introduction to Linear Programming A linear program in compressed form: Given a vector c in Rn, a vector b in Rm and a matrix A in Rm x n, find a vector x in Rn which satisfies xA >= 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) !

  33. Vertex Cover via LP Given is a graph G=(V,E) and a number k. A vertex cover is a subset C of V such that every edge has an endpoint in C. The Vertex Cover problem asks if there is a vertex cover of size k.

More Related