1 / 43

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner. Flow networks. What if weights in a graph are maximum capacities of some flow of material? Pipe network to transport fluid/gas (e.g., water, oil, natural gas, CO 2 ) Edges – pipes Vertices – junctions of pipes

telyn
Download Presentation

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

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. Design & Analysis of Algorithms COMP 482 / ELEC 420John Greiner

  2. Flow networks What if weights in a graph are maximum capacities of some flow of material? • Pipe network to transport fluid/gas (e.g., water, oil, natural gas, CO2) • 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) • Also used in resource planning, economics, ecosystem network analysis To do: [CLRS] 26 #7

  3. Flow Network Definitions Directed graph G=(V,E) One source and one sink. 13 a b 15 19 5 10 s e t 4 9 5 14 3 c d 11 Each edge has capacity c(u,v)  0. Each vertex is on some path from s to t.

  4. Flow Definitions How much is currently flowing – f : V V ®  2/13 a b 3/15 3/19 Must satisfy 3 properties: • Capacity constraint: u,v  V:f(u,v)  c(u,v) • Skew symmetry: u,v  V:f(u,v) = –f(v,u) • Flow conservation: u  V–{s,t}: f(u,V) = f(V,u) = 0 What goes in must go out. 1/5 0/10 s e t 1/4 0/9 1/5 2/14 2/3 c d Total value of flow f: |f| = f(s,V) = f(V,t) 3/11

  5. Example flows Valid or invalid? Why? 0/13 1/13 2/13 a a a b b b 1/15 2/15 0/15 1/19 1/19 0/19 1/5 0/5 0/5 1/10 0/10 2/10 s s s e e e t t t 0/4 1/4 0/4 1/9 0/9 0/9 0/5 0/5 1/5 1/14 4/14 0/14 1/3 0/3 5/3 c c c d d d 0/11 5/11 1/11

  6. Maximize the flow 13 a b 15 19 5 10 s e t 4 9 5 14 3 c d 11

  7. Maximum flow: Algorithm idea • If we have some flow, … • …and can find an augmenting path can add a constant amount of flow along path: a>0,  (u,v)p, f(u,v) + a £c(u,v) • Then just do it, to get a better flow! 2/13 a b 3/15 2/19 1/5 p 1/10 s e t 1/4 0/9 s t 1/5 1/14 2/3 c d 3/11

  8. Ford-Fulkerson method Ford-Fulkerson(G,s,t) 1 initialize flow f to 0 everywhere 2 while there is an augmenting path p do 3 augment flow f along p 4 return f • How do we find/choose an augmenting path? • How much additional flow can we send through that path? • Does the algorithm always find the maximum flow?

  9. Augmenting Augmenting path – any path in the residual network: • Residual network: Gf=(V,Ef) Ef = {(u,v) Î V V : cf(u,v) > 0} • Residual capacities: cf(u,v) = c(u,v) – f(u,v) • Residual capacity of path p: 2/13 a b 3/15 2/19 1/5 ? 1/10 s e t 1/4 0/9 Residual ? 1/5 1/14 2/3 c d 3/11 Residual capacity of path (s,c,d,t)? Observe – Edges in Ef are either edges in E or their reversals: |Ef|  2|E|.

  10. Ford-Fulkerson method, with details Algorithms based on this method differ in how they choose p. Ford-Fulkerson(G,s,t) 1 for each edge (u,v)G.E do 2 f(u,v) = f(v,u) = 0 3 while path p from s to t in residual network Gfdo 4 cf = min{cf(u,v): (u,v)p} 5 for each edge (u,v) in p do 6 f(u,v) = f(u,v) + cf 7 f(v,u)=-f(u,v) 8 return f

  11. Does it always find a maximum flow? Cut–a partition of V into S,T such that sÎS, tÎT Minimum cut– a cut with minimum capacity S T 2/13 |f| = f(S,T) a b 3/15 2/19 1/5 1/10 s e t 1/4 0/9 1/5 1/14 2/3 c d 3/11

  12. Does it always find a maximum flow? 1. We will prove three parts: From this we have 2.1., which means that the Ford-Fulkerson method always correctly finds a maximum flow. 3. 2. Max-flow min-cut theorem: The following are equivalent statements: • f is a maximum flow in G. • The residual network Gf contains no augmenting paths. • |f| = c(S,T), for some cut (S,T) of G.

  13. What is the worst-case running time? 100 a 100 s 1 t 100 100 b • Augmentation = ? • How many augmentations? • Let’s assume integer flows. • Each increases the value of the flow by some integer. • O(|f*|), where f* is the max-flow. • Total worst-case = O(E|f*|). • How an augmenting path is chosen is very important! O(E)

  14. Edmonds-Karp Algorithm Use shortest augmenting path (in #edges). Run algorithm on our example: 13 a b 15 19 5 10 s e t 4 9 5 14 3 c d 11

  15. Edmonds-Karp algorithm analysis: 1 Augmentation = O(E) – Breadth-first search Will prove: #augmentations = O(VE). Let d(v) be distance from s to v in residual network. Will prove: Every |E| iterations, d(t) increases by 1. d(t) can increase at most |V| times  O(VE) iterations Total = O(VE2)

  16. Edmonds-Karp algorithm analysis: 2 0 1 2 3 Will prove: Every |E| iterations, d(t) increases by 1. Consider the residual network in levels according to d(v): As long as d(t) doesn't change, the paths found will only use forward edges. • Each iteration saturates & removes at least 1 forward edge, and adds only backward edges (so no distance ever drops). • After removing |E| - d(t) +1 forward edges, t will be disconnected from s. So, within |E| iterations, either • t is disconnected, & algorithm terminates, or • A non-forward edge used, & d(t) increased. 11 a b 12 2 17 3 4 1 2 9 s e t 3 9 1 2/13 1 2 1 4 a b 1 3/15 2/19 1 3 13 1/5 c d 1/10 s e t 1/4 0/9 8 1/5 1/14 2/3 c d 3/11

  17. Antiparallel edges Allow: Flows cancel. Residual (multi)graph can have parallel edges. Disallow: 5 9 5 9 5

  18. What if we have multiple sources or sinks? 13 s1 t1 13 s1 t1 11 7 ¥ 11 ¥ 7 4 5 10 4 5 10 ¥ 11 ¥ s s2 t2 t 11 s2 t2 4 8 4 8  6 6 s3 s3

  19. Maximum Flow: Another Algorithm Idea 13 a b 15 19 10 4 9 5 s t 14 3 c d 11 Greedily fill outgoing edges to capacity. Later edges’ capacity constraints can lead us to reduce those flows.

  20. Push-Relabel Example – Goldberg & Tarjan (1986) s 15/15 14/14 0/5 0/13 0/10 0/11 0/3 d a b c t 0/4 0/9 0/19

  21. Relabel a s 0/14 0/15 0/5 a 0/4 0/13 0/10 0/11 0/3 d b c t 0/9 0/19

  22. Push Preflow from a to b & c s 15/15 14/14 0/5 a 2/4 13/13 0/10 0/11 0/3 d b c t 0/9 0/19

  23. Relabel b s 15/15 14/14 0/5 13/13 a b 0/9 2/4 0/11 0/3 d c t 0/10 0/19

  24. Push Preflow from b s 15/15 14/14 0/5 13/13 a b 0/9 2/4 0/11 0/3 d c t 0/10 13/19

  25. Relabel c s 15/15 14/14 0/5 13/13 a b c 0/10 0/11 0/3 d t 0/9 2/4 13/19

  26. Push Preflow from c to d s 15/15 14/14 0/5 13/13 a b c 0/10 11/11 0/3 d t 0/9 2/4 13/19

  27. Relabel c s 15/15 14/14 c 2/4 0/10 11/11 13/13 a b 0/5 0/3 d t 0/9 13/19

  28. Push Preflow from c to a s 15/15 14/14 c 0/4 0/10 11/11 13/13 a b 0/5 0/3 d t 0/9 13/19

  29. Relabel a & Push Preflow from a to c s 14/14 15/15 a 2/4 c 13/13 0/10 11/11 b 0/5 0/3 d t 0/9 13/19

  30. Relabel & Push c, Relabel & Push a, Relabel & Push c 14/14 s c 6 0/4 15/15 a 5 0/10 11/11 13/13 b 1 0/5 0/3 d t 0 0/9 13/19

  31. Relabela & Push Preflow from a to s a 7 13/15 0/4 s c 6 14/14 13/13 0/10 11/11 b 1 0/5 0/3 d t 0 0/9 13/19

  32. Relabel c & Push Preflow from c to s 0/4 a c 7 13/15 s 6 11/14 13/13 0/10 11/11 b 1 0/5 0/3 d t 0 0/9 13/19

  33. Relabel d & Push Preflow from d to t 0/4 a c 7 13/15 s 6 11/14 13/13 0/10 11/11 0/5 b d 1 0/9 3/3 13/19 t 0

  34. Relabel d & Push Preflow from d to b 0/4 a c 7 13/15 s 6 11/14 13/13 0/10 11/11 d 2 5/5 3/3 b 0/9 1 13/19 t 0

  35. Push Preflow from b to t 0/4 a c 7 13/15 s 6 11/14 13/13 0/10 11/11 d 2 5/5 3/3 b 0/9 1 18/19 t 0

  36. Relabel d & Push Preflow from d to c d 8 8/11 0/4 a c 7 13/15 s 6 5/5 11/14 13/13 0/10 0/9 3/3 b 1 18/19 t 0

  37. Push Preflow from c to s d 8 8/11 0/4 a c 7 13/15 s 6 5/5 8/14 13/13 0/10 0/9 3/3 b 1 18/19 t 0

  38. Correctness Overview d 8 8/11 0/4 a c 7 13/15 s 6 13/13 0/10 5/5 0/9 3/3 8/14 b 1 18/19 t 0 Is this a flow? Is it maximum? – What is the residual graph?

  39. Correctness Depends on Height Invariant Invariant: Residual edges go down in height by at most one. But, height(s) – height(t) = |V|, longer than any s-t path.

  40. Running Time Overview Max height = . Overall algorithm is . • Requires amortized analysis. • See text & homework. Choosing operation order wisely, can reduce to .

  41. Two Other Approaches Blocking flows: • Each s-t path in blocking flow contains a saturated edge. • Dinitz/Dinic (1970) O(VE log V) • Goldberg & Rao (1997) O(min(V2/3,E1/2) E log(V2/E) log (max(u,v)E c(u,v))) Combinatorial game: • Cheriyan, Hagerup (1989) O(VE + V2 log2 V) expected • King, Rao, & Tarjan (1994) O(VE logE/(V log V) V)

  42. An Application of Max-Flow Bipartite: V = L+R E  L×R A maximum E.g., dating agency 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. E.g.?

  43. Maximum Bipartite Matching • How can we reformulate as a max-flow problem? • What is the running time, using Edmonds-Karp? V = L+R E  L×R

More Related