Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.

Slides:



Advertisements
Similar presentations
COMP 482: Design and Analysis of Algorithms
Advertisements

Lecture 7. Network Flows We consider a network with directed edges. Every edge has a capacity. If there is an edge from i to j, there is an edge from.
15.082J & 6.855J & ESD.78J October 14, 2010 Maximum Flows 2.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
EMIS 8374 Vertex Connectivity Updated 20 March 2008.
Chapter 6 Maximum Flow Problems Flows and Cuts Augmenting Path Algorithm.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
Max Flow: Shortest Augmenting Path
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
Advanced Algorithms Piyush Kumar (Lecture 2: Max Flows) Welcome to COT5405 Slides based on Kevin Wayne’s slides.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
7.7 Extensions to Max Flow. 2 Circulation with Demands Circulation with demands. n Directed graph G = (V, E). n Edge capacities c(e), e  E. n Node supply.
The max flow problem
Maximum Flows Lecture 4: Jan 19. Network transmission Given a directed graph G A source node s A sink node t Goal: To send as much information from s.
Applications of Network Flow Problem. 7.5 Bipartite Matching.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Advanced Algorithms Piyush Kumar (Lecture 5: Weighted Matching) Welcome to COT5405 Based on Kevin Wayne’s slides.
Advanced Algorithms Piyush Kumar (Lecture 4: MaxFlow MinCut Applications) Welcome to COT5405.
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 22 Network.
1 Linear Programming & Flows Instructor: yedeshi
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
Maximum Flow Problem (Thanks to Jim Orlin & MIT OCW)
Chapter 7 April 28 Network Flow.
15.082J and 6.855J March 4, 2003 Introduction to Maximum Flows.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
and 6.855J March 6, 2003 Maximum Flows 2. 2 Network Reliability u Communication Network u What is the maximum number of arc disjoint paths from.
Taken from Kevin Wayne’s slides (Princeton University) COSC 3101A - Design and Analysis of Algorithms 13 Maximum Flow.
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.
Algorithm Design and Analysis (ADA)
Chapter 7 May 3 Ford-Fulkerson algorithm Step-by-step walk through of an example Worst-case number of augmentations Edmunds-Karp modification Time complexity.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
CSCI 256 Data Structures and Algorithm Analysis Lecture 20 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 23.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Maximum Flows CONTENTS Introduction to Maximum Flows (Section 6.1) Introduction to Minimum Cuts (Section 6.1) Applications of Maximum Flows (Section.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Algorithm Design and Analysis
Lectures on Network Flows
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
Chapter 5. Optimal Matchings
Edmunds-Karp Algorithm: Choosing Good Augmenting Paths
COMP 382: Reasoning about Algorithms
Instructor: Shengyu Zhang
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Network Flow and Connectivity in Wireless Sensor Networks
Richard Anderson Lecture 23 Network Flow
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
Algorithms (2IL15) – Lecture 7
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
EE5900 Advanced Embedded System For Smart Infrastructure
and 6.855J March 6, 2003 Maximum Flows 2
Richard Anderson Lecture 22 Network Flow
Lecture 22 Network Flow, Part 2
Presentation transcript:

Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19

2 Min s-t cut problem. Find an s-t cut of minimum capacity. Minimum Cut Problem s t A Capacity = = 28

3 Def. An s-t flow is a function that satisfies: n For each e  E: (capacity) n For each v  V – {s, t}: (conservation) Def. The value of a flow f is: Flows capacity flow s t Value = 24 4

4 Max flow problem. Find s-t flow of maximum value. Maximum Flow Problem capacity flow s t Value = 28

5 Augmenting Path Algorithm Augment(f, c, P) { b  bottleneck(P) foreach e  P { if (e  E) f(e)  f(e) + b else f(e R )  f(e) - b } return f } Ford-Fulkerson(G, s, t, c) { foreach e  E f(e)  0 G f  residual graph while (there exists augmenting path P) { f  Augment(f, c, P) update G f } return f } forward edge reverse edge

6 Running Time Assumption. All capacities are integers between 1 and C. Invariant. Every flow value f(e) and every residual capacities c f (e) remains an integer throughout the algorithm. Theorem. The algorithm terminates in at most v(f*)  nC iterations. Pf. Each augmentation increase value by at least 1. ▪ Corollary. If C = 1, Ford-Fulkerson runs in O(mn) time. Integrality theorem. If all capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer. Pf. Since algorithm terminates, theorem follows from invariant. ▪

Recap: Mobile computing Consider a set of mobile computing clients in a certain town who each needed to be connected to one of several base stations. We’ll suppose there are n clients, with the position of each client specified by its (x,y) coordinates. There are also k base stations, each of them specified by its (x,y) coordinates as well. For each client, we want to connect it to exactly one of the base stations. We have a range parameter r—a client can only be connected to a base station that is within distance r. There is also a load parameter L—no more than L clients can be connected to a single base station. Your goal is to design a polynomial-time algorithm for the following problem. Given the positions of the clients and base stations as well as the range and load parameters, find the maximum number of clients that can be connected simultaneously to a base station. 7

7.3 Choosing Good Augmenting Paths

9 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. s 1 2 t C C C C 1 s 1 2 t C C X 1 C C X X X X X 1 1 X X X m, n, and log C

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

11 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 Let G f (  ) be the subgraph of the residual graph consisting of only arcs with capacity at least . 110 s 4 2 t GfGf 110 s 4 2 t G f (100)

12 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) update G f (  ) }    / 2 } return f }

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

14 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 is at most v(f) + m . 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 L2  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

15 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. original network s t A B

7.5 Bipartite Matching

17 Matching. n Input: undirected graph G = (V, E). n M  E is a matching if each node appears in at most edge in M. n Max matching: find a max cardinality matching. Matching

18 Bipartite Matching Bipartite matching. n Input: undirected, bipartite graph G = (L  R, E). n M  E is a matching if each node appears in at most one edge in M. n Max matching: find a max cardinality matching ' 3' 5' 2 4 2' 4' matching 1-2', 3-1', 4-5' RL

19 Bipartite Matching Bipartite matching. n Input: undirected, bipartite graph G = (L  R, E). n M  E is a matching if each node appears in at most edge in M. n Max matching: find a max cardinality matching ' 3' 5' 2 4 2' 4' RL max matching 1-1', 2-2', 3-3' 4-4'

20 Max flow formulation. n Create digraph G' = (L  R  {s, t}, E' ). n Direct all edges from L to R, and assign unit capacity. n Add source s, and unit capacity edges from s to each node in L. n Add sink t, and unit capacity edges from each node in R to t. Bipartite Matching s ' 3' 5' t 2 4 2' 4' RL G'

21 Theorem. Max cardinality matching in G = value of max flow in G'. Pf.  n Given max matching M of cardinality k. n Consider flow f that sends 1 unit along each of k paths. n f is a flow, and has cardinality k. ▪ Bipartite Matching: Proof of Correctness s ' 3' 5' t 2 4 2' 4' ' 3' 5' 2 4 2' 4' G' G

22 Theorem. Max cardinality matching in G = value of max flow in G'. Pf.  n Let f be a max flow in G' of value k. n Integrality theorem  k is integral and can assume f is 0-1. n Consider M = set of edges from L to R with f(e) = 1. – each node in L and R participates in at most one edge in M – |M| = k: consider cut (L  s, R  t) ▪ Bipartite Matching: Proof of Correctness ' 3' 5' 2 4 2' 4' G s ' 3' 5' t 2 4 2' 4' 11 1 G'

23 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: 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] Bipartite Matching: Running Time

24 Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t, find the max number of edge-disjoint s-t paths. Def. Two paths are edge-disjoint if they have no edge in common. Ex: communication networks. s Q1: Edge Disjoint Paths t

25 Disjoint path problem. Given a digraph G = (V, E) and two nodes s and t, find the max number of edge-disjoint s-t paths. Def. Two paths are edge-disjoint if they have no edge in common. Ex: communication networks. s Edge Disjoint Paths t

26 Max flow formulation: assign unit capacity to every edge. Theorem. Max number edge-disjoint s-t paths equals max flow value. Pf.  n Suppose there are k edge-disjoint paths P 1,..., P k. n Set f(e) = 1 if e participates in some path P i ; else set f(e) = 0. n Since paths are edge-disjoint, f is a flow of value k. ▪ Answer: Edge Disjoint Paths st

27 Max flow formulation: assign unit capacity to every edge. Theorem. Max number edge-disjoint s-t paths equals max flow value. Pf.  n Suppose max flow value is k. n Integrality theorem  there exists 0-1 flow f of value k. n Consider edge (s, u) with f(s, u) = 1. – by conservation, there exists an edge (u, v) with f(u, v) = 1 – continue until reach t, always choosing a new edge n Produces k (not necessarily simple) edge-disjoint paths. ▪ Edge Disjoint Paths st can eliminate cycles to get simple paths if desired

28 Network connectivity. Given a digraph G = (V, E) and two nodes s and t, find min number of edges whose removal disconnects t from s. Def. A set of edges F  E disconnects t from s if all s-t paths uses at least on edge in F. Network Connectivity s t

29 Edge Disjoint Paths and Network Connectivity Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is equal to the min number of edges whose removal disconnects t from s. Pf.  n Suppose the removal of F  E disconnects t from s, and |F| = k. n All s-t paths use at least one edge of F. Hence, the number of edge- disjoint paths is at most k. ▪ s t s t

30 Disjoint Paths and Network Connectivity Theorem. [Menger 1927] The max number of edge-disjoint s-t paths is equal to the min number of edges whose removal disconnects t from s. Pf.  n Suppose max number of edge-disjoint paths is k. n Then max flow value is k. n Max-flow min-cut  cut (A, B) of capacity k. n Let F be set of edges going from A to B. n |F| = k and disconnects t from s. ▪ s t s t A

31 Q2: Project Selection Projects with prerequisites. n Set P of possible projects. Project v has associated revenue p v. – some projects generate money: create interactive e-commerce interface, redesign web page – others cost money: upgrade computers, get site license n Set of prerequisites E. If (v, w)  E, can't do project v and unless also do project w. n A subset of projects A  P is feasible if the prerequisite of every project in A also belongs to A. Project selection. Choose a feasible subset of projects to maximize revenue. can be positive or negative

32 Answer: Project Selection: Prerequisite Graph Prerequisite graph. n Include an edge from v to w if can't do v without also doing w. n {v, w, x} is feasible subset of projects. n {v, x} is infeasible subset of projects. v w x v w x feasibleinfeasible

33 Min cut formulation. n Assign capacity  to all prerequisite edge. n Add edge (s, v) with capacity -p v if p v > 0. n Add edge (v, t) with capacity -p v if p v < 0. n For notational convenience, define p s = p t = 0. st -p w u v w x yz Project Selection: Min Cut Formulation  pvpv -p x      pypy pupu -p z 

34 Claim. (A, B) is min cut iff A  { s } is optimal set of projects. n Infinite capacity edges ensure A  { s } is feasible. n Max revenue because: s t -p w u v w x yz Project Selection: Min Cut Formulation pvpv -p x pypy pupu    A

35 Open-pit mining. (studied since early 1960s) n Blocks of earth are extracted from surface to retrieve ore. n Each block v has net value p v = value of ore - processing cost. n Can't remove block v before w or x. Open Pit Mining v xw