Taken from Kevin Wayne’s slides (Princeton University) COSC 3101A - Design and Analysis of Algorithms 13 Maximum Flow.

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.
Bioinformatics III1 We will present an algorithm that originated by Ford and Fulkerson (1962). Idea: increase the flow in a network iteratively until it.
Chapter 6 Maximum Flow Problems Flows and Cuts Augmenting Path Algorithm.
Max Flow: Shortest Augmenting Path
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
1 Maximum Flow w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
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.
Chapter 7 Maximum Flows: Polynomial Algorithms
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.
Computational Methods for Management and Economics Carla Gomes Module 9a Network Models Terminology (Slides adapted from J.Orlin’s)
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.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Chapter 26 Maximum Flow How do we transport the maximum amount data from source to sink? Some of these slides are adapted from Lecture Notes of Kevin.
Graph Theory Chapter 6 from Johnsonbaugh Article(6.1, 6.2)
Maximum Flow Chapter 26.
Lecture 5: Network Flow Algorithms Single-Source Shortest-Path (SSSP) (Dijkstra's Algorithm) Max Flow - Min Cut (Ford-Fulkerson) Job Sequencing.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
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)
Overview of Graph Theory. Some applications of Graph Theory Models for communications and electrical networks Models for computer architectures Network.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
Chapter 7 April 28 Network Flow.
15.082J & 6.855J & ESD.78J October 7, 2010 Introduction to Maximum Flows.
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.
Shortest Path Algorithm 2 Prof. Sin-Min Lee Department of Computer Science.
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.
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.
CSCE 3110 Data Structures & Algorithm Analysis Graphs (I) Reading: Chap.9, Weiss.
1 Network Flow CSC401 – Analysis of Algorithms Chapter 8 Network Flow Objectives: Flow networks –Flow –Cut Maximum flow –Augmenting path –Maximum flow.
Fall 2003Maximum Flow1 w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2 
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
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)
Maximum Flow Chapter 26.
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Maximum Flow 9/13/2018 6:12 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Edmunds-Karp Algorithm: Choosing Good Augmenting Paths
Max Flow – Min Cut Problem
COMP 382: Reasoning about Algorithms
Instructor: Shengyu Zhang
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Network Flow and applications
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Network Flow and Connectivity in Wireless Sensor Networks
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
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
Maximum Flow c v 3/3 4/6 1/1 4/7 t s 3/3 w 1/9 3/5 1/1 3/5 u z 2/2
Presentation transcript:

Taken from Kevin Wayne’s slides (Princeton University) COSC 3101A - Design and Analysis of Algorithms 13 Maximum Flow

2 Contents Contents. n Maximum flow problem. n Minimum cut problem. n Max-flow min-cut theorem. n Augmenting path algorithm. n Capacity-scaling. n Shortest augmenting path.

3 n Network reliability. n Security of statistical data. n Distributed computing. n Egalitarian stable matching. n Distributed computing. n Many many more... Maximum Flow and Minimum Cut Max flow and min cut. n Two very rich algorithmic problems. n Cornerstone problem in combinatorial optimization. n Beautiful mathematical duality. Nontrivial applications / reductions. n Network connectivity. n Bipartite matching. n Data mining. n Open-pit mining. n Airline scheduling. n Image processing. n Project selection. n Baseball elimination.

4 Max flow network: G = (V, E, s, t, u). n (V, E) = directed graph, no parallel arcs. n Two distinguished nodes: s = source, t = sink. n u(e) = capacity of arc e. Max Flow Network Capacity s t

5 An s-t flow is a function f: E   that satisfies: n For each e  E: 0  f(e)  u(e) (capacity) n For each v  V – {s, t}: (conservation) Flows s t Capacity Flow

6 An s-t flow is a function f: E   that satisfies: n For each e  E: 0  f(e)  u(e) (capacity) n For each v  V – {s, t}: (conservation) MAX FLOW: find s-t flow that maximizes net flow out of the source. Flows s t Value = Capacity Flow

7 An s-t flow is a function f: E   that satisfies: n For each e  E: 0  f(e)  u(e) (capacity) n For each v  V – {s, t}: (conservation) MAX FLOW: find s-t flow that maximizes net flow out of the source. Flows s t Value = Capacity Flow

8 An s-t flow is a function f: E   that satisfies: n For each e  E: 0  f(e)  u(e) (capacity) n For each v  V – {s, t}: (conservation) MAX FLOW: find s-t flow that maximizes net flow out of the source. Flows s t Value = Capacity Flow

9 Networks communication Network telephone exchanges, computers, satellites NodesArcs cables, fiber optics, microwave relays Flow voice, video, packets circuits gates, registers, processors wirescurrent mechanicaljointsrods, beams, springsheat, energy hydraulic reservoirs, pumping stations, lakes pipelinesfluid, oil financialstocks, currencytransactionsmoney transportation airports, rail yards, street intersections highways, railbeds, airway routes freight, vehicles, passengers chemicalsitesbondsenergy

10 An s-t cut is a node partition (S, T) such that s  S, t  T. n The capacity of an s-t cut (S, T) is: Min s-t cut: find an s-t cut of minimum capacity. Cuts s t Capacity = 30

11 An s-t cut is a node partition (S, T) such that s  S, t  T. n The capacity of an s-t cut (S, T) is: Min s-t cut: find an s-t cut of minimum capacity. Cuts s t Capacity = 62

12 An s-t cut is a node partition (S, T) such that s  S, t  T. n The capacity of an s-t cut (S, T) is: Min s-t cut: find an s-t cut of minimum capacity. Cuts s t Capacity = 28

13 L1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t. Flows and Cuts s t Value =

L1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t. Flows and Cuts s t Value = 24

L1. Let f be a flow, and let (S, T) be a cut. Then, the net flow sent across the cut is equal to the amount reaching t. Flows and Cuts s t Value = 24 0

16 Let f be a flow, and let (S, T) be a cut. Then, Proof by induction on |S|. n Base case: S = { s }. n Inductive hypothesis: assume true for |S| < k. – consider cut (S, T) with |S| = k – S = S'  { v } for some v  s, t, |S' | = k-1  cap(S', T') = | f |. – adding v to S' increase cut capacity by Flows and Cuts s v t After s v t S' Before S

17 L2. Let f be a flow, and let (S, T) be a cut. Then, | f |  cap(S, T). Proof. Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = cap(S, T), then f is a max flow and (S, T) is a min cut. Flows and Cuts s t S T

18 Max Flow and Min Cut Corollary. Let f be a flow, and let (S, T) be a cut. If |f| = cap(S, T), then f is a max flow and (S, T) is a min cut. s t Flow value = Cut capacity = 28

19 Max-Flow Min-Cut Theorem MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): In any network, the value of the max flow is equal to the value of the min cut. n "Good characterization." n Proof IOU. s t Flow value = Cut capacity = 28

20 Towards an Algorithm Find an s-t path where each arc has u(e) > f(e) and "augment" flow along the path. s t Flow value =

21 Towards an Algorithm Find an s-t path where each arc has u(e) > f(e) and "augment" flow along the path. n Repeat until you get stuck. s t Flow value = X X X

22 Towards an Algorithm Find an s-t path where each arc has u(e) > f(e) and "augment" flow along the path. n Repeat until you get stuck. n Greedy algorithm fails. s t Flow value = 10 s t Flow value = 14

23 Residual Arcs Original graph G = (V, E). n Flow f(e). n Arc e = (v, w)  E. Residual graph: G f = (V, E f ). n Residual arcs e = (v, w) and e R = (w, v). n "Undo" flow sent. vw 17 6 Capacity Flow vw 11 Residual capacity 6

24 Residual Graph and Augmenting Paths Residual graph: G f = (V, E f ). n E f = {e : f(e) 0}. s t s t G GfGf

25 Augmenting Path Augmenting path = path in residual graph. s t s t G GfGf X X X X X

26 Augmenting Path Augmenting path = path in residual graph. n Max flow  no augmenting paths ??? s t s t Flow value = 14 G GfGf

27 Max-Flow Min-Cut Theorem Augmenting path theorem (Ford-Fulkerson, 1956): A flow f is a max flow if and only if there are no augmenting paths. MAX-FLOW MIN-CUT THEOREM (Ford-Fulkerson, 1956): the value of the max flow is equal to the value of the min cut. We prove both simultaneously by showing the TFAE: (i)f is a max flow. (ii)There is no augmenting path relative to f. (iii)There exists a cut (S, T) such that |f| = cap(S, T).

28 Proof of Max-Flow Min-Cut Theorem We prove both simultaneously by showing the TFAE: (i)f is a max flow. (ii)There is no augmenting path relative to f. (iii)There exists a cut (S, T) such that |f| = cap(S, T). (i)  (ii) n We show contrapositive. n Let f be a flow. If there exists an augmenting path, then we can improve f by sending flow along path. (iii)  (i) n Next slide. (iii)  (i) n This was the Corollary to Lemma 2.

29 Proof of Max-Flow Min-Cut Theorem We prove both simultaneously by showing the TFAE: (i)f is a max flow. (ii)There is no augmenting path relative to f. (iii)There exists a cut (S, T) such that |f| = cap(S, T). (ii)  (iii) n Let f be a flow with no augmenting paths. n Let S be set of vertices reachable from s in residual graph. – clearly s  S, and t  S by definition of f s t Original Network S T

30 Augmenting Path Algorithm b  bottleneck(P) FOREACH e  P IF (e  E) // forward arc f(e)  f(e) + b ELSE // backwards arc f(e R )  f(e) - b RETURN f Augment (f, P) FOREACH e  E f(e)  0 G f  residual graph WHILE (there exists augmenting path P) f  augment(f, P) update G f RETURN f FordFulkerson (V, E, s, t)

31 Running Time Assumption: all capacities are integers between 0 and U. Invariant: every flow value f(e) and every residual capacities u f (e) remains an integer throughout the algorithm. Theorem: the algorithm terminates in at most | f * |  nU iterations. Corollary: if U = 1, then algorithm runs in O(mn) time. Integrality theorem: if all arc capacities are integers, then there exists a max flow f for which every flow value f(e) is an integer. Note: algorithm may not terminate on some pathological instances (with irrational capacities). Moreover, flow value may not even converge to correct answer.

s 4 2 t Choosing Good Augmenting Paths Use care when selecting augmenting paths. 100

s 4 2 t Choosing Good Augmenting Paths Use care when selecting augmenting paths X X X

s 4 2 t Choosing Good Augmenting Paths Use care when selecting augmenting paths

s 4 2 t Choosing Good Augmenting Paths Use care when selecting augmenting paths X X X

36 s 4 2 t Choosing Good Augmenting Paths Use care when selecting augmenting paths. 200 iterations possible.

37 Choosing Good Augmenting Paths Use care when selecting augmenting paths. n Some choices lead to exponential algorithms. n Clever choices lead to polynomial algorithms. Goal: choose augmenting paths so that: n Can find augmenting paths efficiently. n Few iterations. Edmonds-Karp (1972): choose augmenting path with n Max bottleneck capacity.(fat path) n Sufficiently large capacity.(capacity-scaling) n Fewest number of arcs.(shortest path)

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

39 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 . FOREACH e  E, f(e)  0   smallest power of 2 greater than or equal to U WHILE (   1) G f (  )   -residual graph WHILE (there exists augmenting path P in G f (  )) f  augment(f, P) update G f (  )    / 2 RETURN f ScalingMaxFlow(V, E, s, t)

40 Capacity Scaling: Analysis L1. If all arc capacities are integers, then throughout the algorithm, all flow and residual capacity values remain integers. n Thus,  = 1  G f (  ) = G f, so upon termination f is a max flow. L2. The outer while loop repeats 1 +  log 2 U  times. n Initially U   < 2U, and  decreases by a factor of 2 each iteration. L3. Let f be the flow at the end of a  -scaling phase. Then value of the maximum flow is at most | f | + m . L4. There are at most 2m augmentations per scaling phase. n Let f be the flow at the end of the previous scaling phase. n L3  |f*|  | f | + m (2  ). n Each augmentation in a  -phase increases | f | by at least . Theorem. The algorithm runs in O(m 2 log (2U) ) time.

41 Capacity Scaling: Analysis L3. Let f be the flow at the end of a  -scaling phase. Then value of the maximum flow is at most |f| + m . n We show that at the end of a  -phase, there exists a cut (S, T) such that cap(S, T)  | f | + m . n Choose S to be the set of nodes reachable from s in G f (  ). – clearly s  S, and t  S by definition of S s t Original Network S T

42 Choosing Good Augmenting Paths Use care when selecting augmenting paths. n Some choices lead to exponential algorithms. n Clever choices lead to polynomial algorithms. Goal: choose augmenting paths so that: n Can find augmenting paths efficiently. n Few iterations. Edmonds-Karp (1972): choose augmenting path with n Max bottleneck capacity.(fat path) n Sufficiently large capacity.(capacity-scaling) n Fewest number of arcs.(shortest path)

43 Shortest Augmenting Path Intuition: choosing path via breadth first search. n Easy to implement. – may implement by coincidence! n Finds augmenting path with fewest number of arcs. FOREACH e  E f(e)  0 G f  residual graph WHILE (there exists augmenting path) find such a path P by BFS f  augment(f, P) update G f RETURN f ShortestAugmentingPath(V, E, s, t)

44 Shortest Augmenting Path: Overview of Analysis L1. Throughout the algorithm, the length of the shortest path never decreases. n Proof ahead. L2. After at most m shortest path augmentations, the length of the shortest augmenting path strictly increases. n Proof ahead. Theorem. The shortest augmenting path algorithm runs in O(m 2 n) time. n O(m+n) time to find shortest augmenting path via BFS. n O(m) augmentations for paths of exactly k arcs. n If there is an augmenting path, there is a simple one.  1  k < n  O(mn) augmentations.

45 Shortest Augmenting Path: Analysis Level graph of (V, E, s). n For each vertex v, define (v) to be the length (number of arcs) of shortest path from s to v. n L G = (V, E G ) is subgraph of G that contains only those arcs (v,w)  E with (w) = (v) + 1. s t s t = 0 = 1 = 2 = 3 LG: LG: G:

46 Shortest Augmenting Path: Analysis Level graph of (V, E, s). n For each vertex v, define (v) to be the length (number of arcs) of shortest path from s to v. n L = (V, F) is subgraph of G that contains only those arcs (v,w)  E with (w) = (v) + 1. n Compute in O(m+n) time using BFS, deleting back and side arcs. n P is a shortest s-v path in G if and only if it is an s-v path L. s t = 0 = 1 = 2 = 3 L:

47 Shortest Augmenting Path: Analysis L1. Throughout the algorithm, the length of the shortest path never decreases. n Let f and f' be flow before and after a shortest path augmentation. n Let L and L' be level graphs of G f and G f ' n Only back arcs added to G f ' – path with back arc has length greater than previous length s t = 0 = 1 = 2 = 3 L s t L'

48 Shortest Augmenting Path: Analysis L2. After at most m shortest path augmentations, the length of the shortest augmenting path strictly increases. n At least one arc (the bottleneck arc) is deleted from L after each augmentation. n No new arcs added to L until length of shortest path strictly increases. s t = 0 = 1 = 2 = 3 L s t L'

49 Shortest Augmenting Path: Review of Analysis L1. Throughout the algorithm, the length of the shortest path never decreases. L2. After at most m shortest path augmentations, the length of the shortest augmenting path strictly increases. Theorem. The shortest augmenting path algorithm runs in O(m 2 n) time. n O(m+n) time to find shortest augmenting path via BFS. n O(m) augmentations for paths of exactly k arcs. n O(mn) augmentations. Note:  (mn) augmentations necessary on some networks. n Try to decrease time per augmentation instead. n Dynamic trees  O(mn log n) Sleator-Tarjan, 1983 n Simple idea  O(mn 2 )

50 Shortest Augmenting Path: Improved Version Two types of augmentations. n Normal augmentation: length of shortest path doesn't change. n Special augmentation: length of shortest path strictly increases. L3. Group of normal augmentations takes O(mn) time. n Explicitly maintain level graph - it changes by at most 2n arcs after each normal augmentation. n Start at s, advance along an arc in L G until reach t or get stuck. – if reach t, augment and delete at least one arc – if get stuck, delete node s t = 0 = 1 = 2 = 3 LG LG

51 Shortest Augmenting Path: Improved Version s t LG LG s t LG LG s 25 6t LG LG augment delete 3

52 Shortest Augmenting Path: Improved Version s 25 6t LG LG s 25 6t LG LG STOP: length of shortest path must have strictly increased augment

53 Shortest Augmenting Path: Improved Version ARRAY pred[v  V] L G  level graph of G f v  s, pred[v]  nil REPEAT WHILE (there exists (v,w)  L G ) pred[w]  v, v  w IF (v = t) P  path defined by pred[] f  augment(f, P) update L G v  s, pred[v]  nil delete v from L G UNTIL (v = s) RETURN f AdvanceRetreat(V, E, f, s, t) advance retreat augment

54 Shortest Augmenting Path: Improved Version Two types of augmentations. n Normal augmentation: length of shortest path doesn't change. n Special augmentation: length of shortest path strictly increases. L3. Group of normal augmentations takes O(mn) time. n Explicitly maintain level graph - it changes by at most 2n arcs after each normal augmentation. n Start at s, advance along an arc in L G until reach t or get stuck. – if reach t, augment and delete at least one arc – if get stuck, delete node – at most n advance steps before one of above events Theorem. Algorithm runs in O(mn 2 ) time. n O(mn) time between special augmentations. n At most n special augmentations.

55 Choosing Good Augmenting Paths: Summary First 4 rules assume arc capacities are between 0 and U. MethodAugmentations Augmenting pathnU Max capacitym log U Capacity scalingm log U Shortest pathmn Running time mnU m log U (m + n log n) m 2 log U m2nm2n Improved shortest pathmn mn 2 Improved capacity scalingm log Umn log U

56 History Dantzig Discoverer Simplex MethodBig-Oh mn 2 U1951 Year Ford, FulkersonAugmenting pathmnU1955 Edmonds-KarpShortest pathm2nm2n1970 DinitzShortest path mn Edmonds-Karp, DinitzCapacity scalingm 2 log U1972 Dinitz-GabowCapacity scalingmn log U1973 KarzanovPreflow-push n3n Sleator-TarjanDynamic treesmn log n1983 Goldberg-TarjanFIFO preflow-pushmn log (n 2 / m) Goldberg-RaoLength function m 3/2 log (n 2 / m) log U mn 2/3 log (n 2 / m) log U 1997