Presentation is loading. Please wait.

Presentation is loading. Please wait.

10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network.

Similar presentations


Presentation on theme: "10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network."— Presentation transcript:

1 10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network Flow Finish bipartite matching Capacity-scaling algorithm

2 Marriage Theorem. [Frobenius 1917, Hall 1935] Let G = (L  R, E) be a bipartite graph with |L| = |R|. Then, G has a perfect matching iff |N(S)|  |S| for all subsets S  L. Pf.  This was the previous observation. Marriage Theorem 1 3 5 1' 3' 5' 2 4 2' 4' L R No perfect matching: S = { 2, 4, 5 } N(S) = { 2', 5' }.

3 Pf.  Suppose G does not have a perfect matching. n Formulate as a max flow problem with 1 constraints on edges from L to R and let (A, B) be min cut in G'. n Key property #1 of this graph: min-cut cannot use  edges.  So cap(A, B) = | L  B | + | R  A | n Key property #2: integral flow is still a matching – By max-flow min-cut, cap(A, B) < | L |. n Choose S = L  A. – Since min cut can't use  edges: N(S)  R  A. n |N(S )|  | R  A | = cap(A, B) - | L  B | < | L | - | L  B | = | S|. ▪ Proof of Marriage Theorem S = {2, 4, 5} L  B = {1, 3} R  A = {2', 5'} N(S) = {2', 5'} s 1 3 5 1' 3' 5' t 2 4 4' 1  2' 1 1 1 A  G' 

4 Which max flow algorithm to use for bipartite matching? n Generic augmenting path: O(m val(f*) ) = O(mn). n Capacity scaling: O(m 2 log C ) = O(m 2 ). n Shortest augmenting path (not covered in class): O(m n 1/2 ). Non-bipartite matching. n Structure of non-bipartite graphs is more complicated, but well-understood. [Tutte-Berge, Edmonds-Galai] n Blossom algorithm: O(n 4 ). [Edmonds 1965] n Best known: O(m n 1/2 ). [Micali-Vazirani 1980] n Recently: better algorithms for dense graphs, e.g. O(n 2.38 ) [Harvey, 2006] Bipartite Matching: Running Time

5 Exercise A bipartite graph is k-regular if |L|=|R| and every vertex (regardless of which side it is on) has exactly k neighbors Prove or disprove: every k-regular bipartite graph has a perfect matching

6 Faster algorithms when capacities are large

7 1 X X X 1 0 1 Ford-Fulkerson: Exponential Number of Augmentations Q. Is generic Ford-Fulkerson algorithm polynomial in input size? A. No. If max capacity is C, then algorithm can take C iterations. Intuition: we’re choosing the wrong paths! s 1 2 t C C 00 00 0 C C 1 s 1 2 t C C 1 00 00 0 X C C X X X 1 1 1 X X 1 1 m, n, and log C

8 Choosing Good Augmenting Paths Use care when selecting augmenting paths. n Some choices lead to exponential algorithms. n Clever choices lead to polynomial algorithms. n If capacities are irrational, algorithm not guaranteed to terminate! Goal: choose augmenting paths so that: n Can find augmenting paths efficiently. n Few iterations. Choose augmenting paths with: [Edmonds-Karp 1972, Dinitz 1970] n Max bottleneck capacity. n Sufficiently large bottleneck capacity. n Fewest number of edges.

9 Capacity Scaling Intuition. Choosing path with highest bottleneck capacity increases flow by max possible amount. n Don't worry about finding exact highest bottleneck path. n Maintain scaling parameter . n G f (  ) = subgraph of the residual graph with only arcs ofcapacity at least . 110 s 4 2 t 1 170 102 122 GfGf 110 s 4 2 t 170 102 122 G f (100)

10 Capacity Scaling Scaling-Max-Flow(G, s, t, c) { foreach e  E f(e)  0   smallest power of 2 greater than or equal to C G f  residual graph while (   1) { G f (  )   -residual graph while (there exists augmenting path P in G f (  )) { f  augment(f, c, P) // augment flow by   update G f (  ) }    / 2 } return f } Scaling-Max-Flow(G, s, t, c) { foreach e  E f(e)  0   smallest power of 2 greater than or equal to C G f  residual graph while (   1) { G f (  )   -residual graph while (there exists augmenting path P in G f (  )) { f  augment(f, c, P) // augment flow by   update G f (  ) }    / 2 } return f }

11 Capacity Scaling: Correctness Assumption. All edge capacities are integers between 1 and C. Integrality invariant. All flow and residual capacity values are integral. Correctness. If the algorithm terminates, then f is a max flow. Pf. n By integrality invariant, when  = 1  G f (  ) = G f. n Upon termination of  = 1 phase, there are no augmenting paths. ▪

12 Capacity Scaling: Running Time Lemma 1. The outer while loop repeats 1 +  log 2 C  times. Pf. Initially C   < 2C.  decreases by a factor of 2 each iteration. ▪ Lemma 2. Let f be the flow at the end of a  -scaling phase. Then the value of the maximum flow f* is at most v(f) + m . (Sanity check: |v(f*) – v(f)|  m , and  shrinks, so v(f) converges towards v(f*) ) Lemma 3. There are at most 2m augmentations per scaling phase. n Let f be the flow at the end of the previous scaling phase. n Lemma 2  v(f*)  v(f) + m (2  ). n Each augmentation in a  -phase increases v(f) by at least . ▪ Theorem. The scaling max-flow algorithm finds a max flow in O(m log C) augmentations. It can be implemented to run in O(m 2 log C) time. ▪ proof on next slide (Why?)

13 Capacity Scaling: Running Time Lemma 2. Let f be the flow at the end of a  -scaling phase. Then value of the maximum flow is at most v(f) + m . Pf. (almost identical to proof of max-flow min-cut theorem) n We show that at the end of a  -phase, there exists a cut (A, B) such that cap(A, B)  v(f) + m . n Choose A to be the set of nodes reachable from s in G f (  ). n By definition of A, s  A. n By definition of f, t  A. So v(f*)-v(f) ≤ cap(A,B) – v(f) ≤ m  original network s t A B

14 Best Known Algorithms For Max Flow Reminder: The scaling max-flow algorithm runs in O(m 2 log C) time. Currently there are algorithms that run in time O(mn log n) O(n 3 ) O(min(n 2/3, m 1/2 ) m log n log C) Active topic of research: Flow algorithms for specific types of graphs Special cases (bipartite matching, etc) Multi-commodity flow …

15 What you should know about max flow How Ford-Fulkerson works How to use it to find min cuts How to use it to solve other problems (more examples coming) max matching project selection edge-disjoint paths vertex-disjoint paths … To study: Review lecture notes/ textbook Solved exercises in book Homework problems Homework exercises Solve lots of problems!


Download ppt "10/11/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 21 Network."

Similar presentations


Ads by Google