 Download Presentation Flow networks

# Flow networks

Télécharger la présentation ## Flow networks

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

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

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

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

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

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

10. Maximum flow problem – Ford-Fulkerson

11. Maximum flow problem – Ford-Fulkerson Lemma: Ford-Fulkerson works. 2 5 1 s 4 7 t 3 2 5

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

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

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

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

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

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

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

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

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

21. Applications of Network Flows • maximum bipartite matching

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

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

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

25. 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) !