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

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
MAX FLOW APPLICATIONS CS302, Spring 2013 David Kauchak.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
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.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
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.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Maximum Flow Chapter 26.
MAX FLOW APPLICATIONS CS302, Spring 2012 David Kauchak.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
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.
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.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
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.
A directed graph G consists of a set V of vertices and a set E of arcs where each arc in E is associated with an ordered pair of vertices from V. V={0,
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Flow A flow f for a network N is is an assignment of an integer value f(e) to each edge e that satisfies the following properties: Capacity Rule: For each.
Maximum Flow Chapter 26.
V15: Max-Flow Min-Cut V15 continues chapter 12 in Gross & Yellen „Graph Theory“ Theorem [Characterization of Maximum Flow] Let f be a flow in a.
Max-flow, Min-cut Network flow.
CS4234 Optimiz(s)ation Algorithms
V12: Network Flows V12 follows closely chapter 12.1 in
Algorithm Design and Analysis
Lectures on Network Flows
Algorithms and Networks Hans Bodlaender
Richard Anderson Lecture 23 Network Flow
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.
Lecture 22 Network Flow, Part 2
CSCI 3160 Design and Analysis of Algorithms Tutorial 8
Network Flow.
Max-flow, Min-cut Network flow.
Network Flow 2016/04/12.
Instructor: Shengyu Zhang
Edmonds-Karp Algorithm
Network Flows and Matching (Supplementary)
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 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
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Network Flow and Connectivity in Wireless Sensor Networks
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
離散數學 DISCRETE and COMBINATORIAL MATHEMATICS
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
Text Book: Introduction to algorithms By C L R S
Network Flow.
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Maximum Flow Neil Tang 4/8/2008
Lecture 22 Network Flow, Part 2
Network Flow.
Richard Anderson Lecture 22 Network Flow
Presentation transcript:

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 5/26/2018 5:00 PM 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 5/26/2018 5:00 PM Maximum Flow

Outline and Reading Flow networks Maximum flow Cut (§8.1.2) Maximum flow Augmenting path (§8.2.1) Maximum flow and minimum cut (§8.2.1) Ford-Fulkerson’s algorithm (§8.2.2-8.2.3) Edmonds-Karp algorithm (§8.2.4) Maximum Bipartite Matching Minimum Cost Flow (§8.4) 5/26/2018 5:00 PM Maximum Flow

Flow Network A flow network (or just network) N consists of Example: A weighted digraph G with nonnegative integer edge weights, where the weight of an edge e is called the capacity c(e) of e Two distinguished vertices, s and t of G, called the source and sink, respectively, such that s has no incoming edges and t has no outgoing edges. Example: w s v u t z 3 9 1 7 6 5 2 5/26/2018 5:00 PM Maximum Flow

Flow A flow f for a network N is is an assignment of an integer value f(e) to each edge e that satisfies the following properties: Capacity Rule: For each edge e, 0  f (e)  c(e) Conservation Rule: For each vertex v  s,t where E-(v) and E+(v) are the incoming and outgoing edges of v, resp. The value of a flow f , denoted |f|, is the total flow from the source, which is the same as the total flow into the sink Example: w s v u t z 3/3 2/9 1/1 1/3 3/7 2/6 4/5 3/5 2/2 5/26/2018 5:00 PM Maximum Flow

Maximum flow of value 10 = 4 + 3 + 3 = 3 + 3 + 4 1/3 A flow for a network N is said to be maximum if its value is the largest of all flows for N The maximum flow problem consists of finding a maximum flow for a given network N Applications Hydraulic systems Electrical circuits Traffic movements Freight transportation 2/6 1/1 3/7 t s 3/3 w 2/9 4/5 1/1 3/5 u z 2/2 Flow of value 8 = 2 + 3 + 3 = 1 + 3 + 4 v 3/3 4/6 1/1 3/7 t s 3/3 w 2/9 4/5 1/1 3/5 u z 2/2 Maximum flow of value 10 = 4 + 3 + 3 = 3 + 3 + 4 5/26/2018 5:00 PM Maximum Flow

Cut t w s v u z 3 9 1 7 6 5 2 c A cut of a network N with source s and sink t is a partition c = (Vs,Vt) of the vertices of N such that s  Vs and t  Vt Forward edge of cut c: origin in Vs and destination in Vt Backward edge of cut c: origin in Vt and destination in Vs Flow f(c) across a cut c: total flow of forward edges minus total flow of backward edges Capacity c(c) of a cut c: total capacity of forward edges Example: c(c) = 24 f(c) = 8 w s v u t z 3/3 2/9 1/1 1/3 3/7 2/6 4/5 3/5 2/2 c f(c) = 2 –1 + 3 + 2 + 2 = 8 5/26/2018 5:00 PM Maximum Flow

Flow and Cut |f| = 8 c(c1) = 6 + 3 + 1 + 2 = 12 Lemma: The flow f(c) across any cut c is equal to the flow value |f| The flow f(c) across a cut c is less than or equal to the capacity c(c) of the cut Theorem: The value of any flow is less than or equal to the capacity of any cut, i.e., for any flow f and any cut c, we have |f|  c(c) c1 c2 v 1/3 2/6 1/1 3/7 t s 3/3 w 2/9 4/5 1/1 3/5 u z 2/2 |f| = 8 c(c1) = 6 + 3 + 1 + 2 = 12 c(c2) = 3 + 7 + 9 + 2 = 21 5/26/2018 5:00 PM Maximum Flow

Augmenting Path p Consider a flow f for a network N Let e be an edge from u to v: Residual capacity of forward edge e, from u to v: Df(u, v) = c(e) - f (e) Residual capacity of backward edge e, from v to u: Df(v, u) = f (e) Let p be a path from s to t The residual capacity Df(p) of p is the smallest of the residual capacities of the edges of p A path p from s to t is an augmenting path if Df(p) > 0 w s v u t z 3/3 2/9 1/1 1/3 2/7 2/6 4/5 0/1 2/5 2/2 p Df(s,u) = 3 Df(u,w) = 1 Df(w,v) = 1 Df(v,t) = 2 Df(p) = 1 |f| = 7 5/26/2018 5:00 PM Maximum Flow

Flow Augmentation p p Lemma: s v u t z 3/3 2/9 1/1 1/3 2/7 2/6 4/5 0/1 2/5 2/2 p Lemma: Let p be an augmenting path for flow f in network N. There exists a flow f for N of value | f | = |f | + Df(p) Proof: We compute flow f by modifying the flow on the edges of p Forward edge: f (e) = f(e) + Df(p) Backward edge: f (e) = f(e) - Df(p) | f | = 7 Df(p) = 1 w s v u t z 3/3 2/9 0/1 2/3 2/7 2/6 4/5 1/1 3/5 2/2 p | f | = 8 5/26/2018 5:00 PM Maximum Flow

Ford-Fulkerson’s Algorithm Initially, f(e) = 0 for each edge e Repeatedly Search for an augmenting path p Augment by Df(p) the flow along the edges of p A specialization of DFS (or BFS) searches for an augmenting path An edge e is traversed from u to v provided Df(u, v) > 0 Algorithm FordFulkersonMaxFlow(N) for all e  G.edges() setFlow(e, 0) while G has an augmenting path p { compute residual capacity D of p } D   for all edges e  p { compute residual capacity d of e } if e is a forward edge of p d  getCapacity(e) - getFlow(e) else { e is a backward edge } d  getFlow(e) if d < D D  d { augment flow along p } setFlow(e, getFlow(e) + D) setFlow(e, getFlow(e) - D) 5/26/2018 5:00 PM Maximum Flow

Max-Flow and Min-Cut c(c) = | f | = 10 Termination of Ford-Fulkerson’s algorithm There is no augmenting path from s to t with respect to the current flow f Define Vs set of vertices reachable from s by augmenting paths Vt set of remaining vertices Cut c = (Vs,Vt) has capacity c(c) = |f| Forward edge: f(e) = c(e) Backward edge: f(e) = 0 Thus, flow f has maximum value and cut c has minimum capacity Theorem: The value of a maximum flow is equal to the capacity of a minimum cut 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 c(c) = | f | = 10 5/26/2018 5:00 PM Maximum Flow

Example (1) w s v u t z 0/3 0/9 0/1 1/7 0/6 0/5 1/1 1/5 0/2 w s v u t 1/3 0/9 1/1 0/3 2/7 1/6 1/5 0/1 1/2 w s v u t z 1/3 0/9 0/1 0/3 1/7 0/6 1/5 1/2 w s v u t z 2/3 0/9 0/1 1/3 2/7 1/6 1/5 1/2 5/26/2018 5:00 PM Maximum Flow

Example (2) two steps w s v u t z 2/3 0/9 0/1 3/3 2/7 3/6 1/5 1/2 w s 1/9 1/1 3/7 4/6 2/5 0/1 1/5 1/2 w s v u t z 3/3 1/9 0/1 2/7 3/6 2/5 1/5 1/2 w s v u t z 3/3 1/9 1/1 4/7 4/6 3/5 2/2 two steps 5/26/2018 5:00 PM Maximum Flow

Analysis In the worst case, Ford-Fulkerson’s algorithm performs v u 1/1 1/50 0/50 p1 In the worst case, Ford-Fulkerson’s algorithm performs |f*| flow augmentations, where f* is a maximum flow Example The augmenting paths found alternate between p1 and p2 The algorithm performs 100 augmentations Finding an augmenting path and augmenting the flow takes O(n + m) time The running time of Ford-Fulkerson’s algorithm is O(|f*|(n + m)) t s v u 0/1 1/50 p2 5/26/2018 5:00 PM Maximum Flow

Edmonds-Karp Algorithm Variation of Ford-Fulkerson’s algorithm Uses a simple technique for finding good augmenting path in faster running time. It is more greedy in the choice of path Chooses an augmenting path p with the smallest number of edges This can be done in O(m) by a modified BFS traversal Complexity O(n m2) Lemma: The number of flow augmentations in the Edmonds-Karp algorithm for a network with n vertices and m edges is no more than n m. 5/26/2018 5:00 PM Maximum Flow

Maximum Bipartite Matching Graph G(V,E) is bipartite (denoted G(V1,V2,E) ) if The vertices V of G can be partitioned into two disjoint sets, V1 and V2 Every edge e of G has one endpoint in V1 and the other in V2. A matching in G is a set of edges (subset of E) that have no endpoints in common. A matching in bipartite graph is called bipartite matching. We are often interested in maximum matching, that is, the matching with maximum number of edges. M=1 M=2 V1 V2 5/26/2018 5:00 PM Maximum Flow

Maximum Bipartite Matching V1 V2 Solution is non-unique Examples: (all are maximum, M=2) 5/26/2018 5:00 PM Maximum Flow

Reduction to Max Flow Problem Systematic approach to bipartite matching problem Create a network flow N from graph G(V1,V2,E): Add a source s and a sink t Connect s withV1 and t with V2, using directed edges Direct edges E from V1 to V2 and assign capacities c(e)=1 Solve a max flow problem on the network flow N max M = max f V1 V2 s t 5/26/2018 5:00 PM Maximum Flow

Reduction to Max Flow Problem Proof of correctness f(e) = 1  e  M Set M is a matching: The flow through e is 0 or 1 (capacity is 1) Each vertex in V1 has exactly one incoming edge: by flow conservation rule there is at most one outgoing edge for v V1 Each vertex in V2 has exactly one outgoing edge: there is at most one incoming edge for v V2 Hence, each vertex in V1 will be paired in M by at most one vertex in V2 ., hence M is the matching. Finally, size of M = |f|. V1 V2 s t 5/26/2018 5:00 PM Maximum Flow

Minimum Cost Flow Problem A variant of the max flow problem, applicable to networks where there is a cost w(e) associated with sending a unit flow through an edge. Associate cost w(e) with each edge e in the network N Compute flow f with minimum total cost: min w(f) = e  E w(e) f(e) That is, find a minimum-cost flow among all the flows of maximum value f Sometimes, given a fixed flow f, compute minimum-cost flow with flow value = f. Solving min-cost flow uses augmented cycles concept. 5/26/2018 5:00 PM Maximum Flow

Minimum Cost Flow Problem f(e) / c(e),w(e) Augmenting cycle  : a cycle that has non-zero residual capacity Df() Residual capacity Df() along the cycle  : min of c(e)-f(e) for forward edges f(e)>0 for backward edges Example: Initially f=2 and w(f)=8 Augmenting cycle {s,v,u,s} has residual capacity Df() = 1. The cost of  is w()=-1 Flow f’ obtained by pushing 1 unit of flow along  has cost: w(f’) = w(f) + w( ) Df() = 8 - 1= 7 t s u v 0 / 3,1 1 / 2, 1 1 / 1, 3 t s u v 1/3,1 0 / 1, 3 2 / 2, 1 1/ 1, 3 p2 1 / 2, 1 5/26/2018 5:00 PM Maximum Flow