CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
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.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
The Maximum Network Flow Problem. CSE Network Flows.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli Ch26 of CSLR and many other sources. Marmara Univ. Picture taken from without permission.
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CS138A Network Flows Peter Schröder. CS138A Flow Networks Definitions a flow network G=(V,E) is a directed graph in which each edge (u,v)
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
1 Maximum flow problems. 2 - Introduction of: network, max-flow problem capacity, flow - Ford-Fulkerson method pseudo code, residual networks, augmenting.
1 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method Maximum bipartite matching.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
The max flow problem
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
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.
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 5 Tuesday, 10/7/08 Graph Algorithms: Part 2.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 5 Wednesday, 10/4/06 Graph Algorithms: Part 2.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2004 Lecture 5 Wednesday, 10/6/04 Graph Algorithms: Part 2.
1 The Min Cost Flow Problem. 2 Flow Networks with Costs Flow networks with costs are the problem instances of the min cost flow problem. A flow network.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
1 The Min Cost Flow Problem. 2 The Min Cost Flow problem We want to talk about multi-source, multi-sink flows than just “flows from s to t”. We want to.
Assignment 4. (Due on Dec 2. 2:30 p.m.) This time, Prof. Yao and I can explain the questions, but we will NOT tell you how to solve the problems. Question.
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
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.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
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.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
CS223 Advanced Data Structures and Algorithms 1 Maximum Flow Neil Tang 3/30/2010.
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.
Theory of Computing Lecture 12 MAS 714 Hartmut Klauck.
Iterative Improvement for Domain-Specific Problems Lecturer: Jing Liu Homepage:
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
Instructor Neelima Gupta Edited by Divya Gaur(39, MCS '09) Thanks to: Bhavya(9), Deepika(10), Deepika Bisht(11) (MCS '09)
The Maximum Network Flow Problem
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
The Maximum Network Flow Problem
Maximum Flow Chapter 26.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Graph Algorithms Minimum Spanning Tree (Chap 23)
CS4234 Optimiz(s)ation Algorithms
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
Chapter 5. Optimal Matchings
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Instructor: Shengyu Zhang
Network Flows and Matching (Supplementary)
Flow Networks Topics Flow Networks Residual networks
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Text Book: Introduction to algorithms By C L R S
Lecture 22 Network Flow, Part 2
Advanced Graph Homer Lee 2013/10/31.
Presentation transcript:

CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow

CS 473Lecture ?2 FORD-FULKERSON METHOD / ALGORITHM iterative algorithm: start with initial flow f =[0] with |f| = 0 –at each iteration, increase | f | by finding an augmenting path –repeat this process until no augmenting path can be found –by max-flow min-cut thm: upon termination this process yields a max flow FORD-FULKERSON-METHOD(G, s, t) initialize flow f to 0 while  an augmenting path p do augment flow f along path p return f

CS 473Lecture ?3 FORD-FULKERSON METHOD / ALGORITHM basic Ford-Fulkerson Algorithm: data structures –note (u,v)  E f only if (u,v)  E or (v,u)  E –maintain an adj-list representation of directed graph G' = (V', E'), where E' = {(u,v): (u,v)  E or (v,u)  E}, i.e., –for each v  Adj[u] in G' maintain the record –note: G' used to represent both G and G f, i.e., for any edge (u,v)  E' c[u,v] > 0  (u,v)  E and c f [u,v] > 0  (u,v)  E f vf(u,v)c(u,v)c f (u,v)

CS 473Lecture ?4 FORD-FULKERSON METHOD / ALGORITHM FORD-FULKERSON (G', s, t) for each edge (u,v)  E' do f [u,v] ← 0 c f [u,v] ← 0 G f ← COMPUTE-GF(G', f) while  an s t path p in G f do c f (p) ← min {c f [u,v]: (u,v)  p} for each edge (u,v)  p do f [u,v] ← f [u,v] + c f (p) CANCEL(G', u, v) G f ← COMPUTE-GF(G', f) COMPUTE-GF (G', f) for each edge (u,v)  E' do if c[u,v] – f [u,v] > 0 then c f [u,v] ← c[u,v] – f[u,v] else c f [u,v] ← 0 return G' CANCEL (G', u, v) min ← {f [u,v], f [v,u]} f [u,v] ← f [u,v] – min f [v,u] ← f [v,u] – min

CS 473Lecture ?5 FORD-FULKERSON ALGORITHM augmenting path in G f is chosen arbitrarily performance if capacities are integers: O(E |f*|) –while-loop: time to find s t path in G f = O(E') = O(E) –# of while-loop iterations: ≤ |f*|, where f* = max flow so, running time is good if capacities are integers and |f*| is small

CS 473Lecture ?6 FORD-FULKERSON ALGORITHM s u v t 0/100 0/1 0/100 s u v t p = c f (p) = 1 | f 1 | = | f 0 | + | f p | = 0+1 = 1 f0f0 Gf0Gf0

CS 473Lecture ?7 FORD-FULKERSON ALGORITHM s u v t 0/100 1/1000/100 1/1 1/100 s u v t p = c f (p) = 1 | f 2 | = | f 1 | + | f p | = 1+1 = 2 f1f1 Gf1Gf

CS 473Lecture ?8 FORD-FULKERSON ALGORITHM s u v t 1/100 0/1 1/100 s u v t 99 1 p = c f (p) = 1 | f 3 | = | f 2 | + | f p | = 2+1 = 3 f2f2 Gf2Gf

CS 473Lecture ?9 FORD-FULKERSON ALGORITHM s u v t 1/100 2/1001/100 1/1 2/100 s u v t p = c f (p) = 1 | f 4 | = | f 3 | + | f p | = 3+1 = 4 f3f3 Gf3Gf

CS 473Lecture ?10 FORD-FULKERSON ALGORITHM choose p = in odd iterations choose p = in even iterations –200 augmentations to reach |f*| = 200 might never terminate for non-integer capacities efficient algorithms: –augment along max-capacity path in G f : not mentioned in textbook –augment along breadth-first path in G f : Edmonds-Karp algorithm  O(VE 2 )

CS 473Lecture ?11 EDMONDS-KARP ALGORITHM def: δ f (s,v) = shortest path distance from s to v in G f –unit edge weights in G f  δ f (s,v) = breadth-first distance from s to v in G f L7:  v  V – {s,t}; δ (s,v) in G f ’s increases monotonically with each augmentation proof: suppose –(i) a flow f on G induces G f –(ii) f p along an augmenting path in G f produces f’ = f + f p on G –(iii) f’ on G induces G f’ notation: δ(s,v) = δ f (s,v) and δ’(s,v) = δ f’ (s,v)

CS 473Lecture ?12 ANALYSIS OF EDMONDS-KARP ALGORITHM want to prove: δ' (s,v) ≥ δ(s,v)  v  V – {s,t} for contradiction: assume δ'(s,v) < δ(s,v) for some v without loss of generality: assume δ' (s,v) is minimal over all such vertices –i.e., δ' (s,v) < δ' (s,u)  u  V – {s,t}  δ' (s,u) < δ(s,u) –thus δ' (s,u) < δ' (s,v)  δ' (s,u) ≥ δ(s,u) (1)

CS 473Lecture ?13 ANALYSIS OF EDMONDS-KARP ALGORITHM consider a shortest s v path p': s u → v in G f’  δ'(s,u) = δ'(s,v) – 1 by “subpath is also a shortest path” δ' (s,u) < δ' (s,v)  by (1), δ' (s,u) ≥ δ(s,u) (2)  consider this edge (u,v)  E f ' : question: was (u,v)  E f ?  YES: i.e., (u,v)  E f ' and (u,v)  E f ; note f(u,v) < c(u,v) δ(s,v) ≤ δ(s,u) + 1by triangle inequality ≤ δ' (s,u) + 1by (2) = δ' (s,v)  δ' (s,v) ≥ δ(s,v) contradiction

CS 473Lecture ?14 ANALYSIS OF EDMONDS-KARP ALGORITHM NO: i.e., (u,v)  E f ' but (u,v)  E f ; note f(u,v)=c(u,v) –f p pushes flow back along edge (u,v)  (v,u)  p in G f –i.e., augmenting path p is of the form p = s v → u t –note: p is a breadth-first path from s to t (Edmond-Karp algorithm) –δ(s,v) = δ(s,u) – 1 by “subpath is also a shortest path” ≤ δ' (s,u) – 1 by (2) = (δ' (s,v) – 1) – 1 by “subpath is also a shortest path” = δ' (s,v) – 2 < δ'(s,v)  δ'(s,v) ≥ δ(s,v)contradiction

CS 473Lecture ?15 ANALYSIS OF EDMONDS-KARP ALGORITHM what is the bound on the total # of augmentations? def: an edge (u,v) in G f is critical on an augmenting path p in G f if c f (u,v) = c f (p) at least one edge on an augmenting path must be critical a critical edge disappears from G f after the augmentation –f '(u,v) = (f+f p )(u,v) = f (u,v) + f p (u,v) = f (u,v) + (c(u,v) – f (u,v)) = c(u,v)  c f ' (u,v) = c'(u,v) – f '(u,v) = c(u,v) – c(u,v) = 0

CS 473Lecture ?16 ANALYSIS OF EDMONDS-KARP ALGORITHM Thm: number of flow augmentations is O(EV) proof: find a bound on the number of times an edge (u,v) becomes critical –let (u,v) becomes critical the first time along path p = s u → v t in G f δ(s,v) = δ(s,u) + 1 (1), since p is a shortest path –then (u,v) disappears from the residual network –(u,v) can reappear an another augmenting path only after net flow from u to v is decreased –this only happens if (v,u) appears on an augmenting path

CS 473Lecture ?17 ANALYSIS OF EDMONDS-KARP ALGORITHM assume this event occurs along a path p' = s u → v t in G f ' later –δ'(s,u) = δ'(s,v) + 1 since p' = s u → v t is a shortest path ≥ δ(s,v) + 1 by L7 = (δ(s,u) + 1) + 1 since p' = s u → v t is a shortest path = δ(s,u) + 2  δ' (s,u) ≥ δ(s,u) + 2 i.e., δ(s,u) increase by ≥ 2 each time (u,v) becomes critical, except the first time thus each edge (u,v) can become critical at most O(V) times, since –1 ≤ δ(s,u) ≤ | V | - 2 and δ(s,u) never decreases by L7  (E) edges in G f ’s  # of flow augmentations = O(VE) running time of Edmonds-Karp algorithm: |E|× O(VE) = O(E 2 V) –finding an augmenting path in a G f = breadth-first search = O(E)

CS 473Lecture ?18 MAXIMUM BIPARTITE MATCHING PROBLEM many combinatorial optimization problems can be reduced to a max-flow problem maximum bipartite matching problem is a typical example

CS 473Lecture ?19 MAXIMUM BIPARTITE MATCHING PROBLEM given an undirected graph G = (V, E) def: a matching is a subset of edges M  E such that  v  V, at most one edge of M is incident to v def: a vertex v  V is matched by a matching M if some edge M is incident to v, otherwise v is unmatched def: a maximum matching M* is a matching M of maximum cardinality, i.e., |M*| ≥ |M| for any matching M def: G=(V,E) is a bipartite graph if V=L  R where L∩R=  such that E={(u,v): u  L and v  R}

CS 473Lecture ?20 MAXIMUM BIPARTITE MATCHING PROBLEM applications: job task assignment problem –Assigning a set L of tasks to a set R of machines –(u,v)  E  task u  L can be performed on a machine v  R –a max matching provides work for as many machines as possible

CS 473Lecture ?21 MAXIMUM BIPARTITE MATCHING PROBLEM example: two matchings M 1 & M 2 on a sample graph with |M 1 | = 2 & |M 2 | = 3 u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v2 LR M 1 = {(u 1,v 1 ), (u 3,v 3 )} u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v2 LR M 2 = {(u 2,v 1 ), (u 3,v 2 ), (u 5,v 3 )}

CS 473Lecture ?22 FINDING A MAXIMUM BIPARTITE MATCHING idea: construct a flow network in which flows correspond to matchings define the corresponding flow network G'=(V', E') for the bipartite graph as –V' = V  {s}  {t}s, t  V –E' = {(s,u):  u  L }  {(u,v): u  L, v  R, (u,v)  E }  {(v,t):  v  R } –assign unit capacity to each edge of E'

CS 473Lecture ?23 FINDING A MAXIMUM BIPARTITE MATCHING u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v2 s t u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v

CS 473Lecture ?24 FINDING A MAXIMUM BIPARTITE MATCHING def: a flow f on a flow network is integer-valued if f(u,v) is integer  u,v  V L8: (a) IF M is a matching in G, THEN  an integer-valued f on G' with | f | = |M| (b) IF f is an integer-valued f on G', THEN  a matching M in G with | M | = | f |

CS 473Lecture ?25 FINDING A MAXIMUM BIPARTITE MATCHING proof L8 (a): let M be a matching in G –define the corresponding flow f on G' as  u,v  M; f(s,u)=f(u,v)=f(v,t) = 1 & f(u,v) = 0 for all other edges first show that f is a flow on G': –1 unit of flow passes thru the path s → u → v → t for each u,v  M these paths are disjoint s t paths, i.e., no common intermediate vertices –f is a flow on G' satisfying capacity constraint, skew symmetry & flow conservation because f can be obtained by flow augmentation along these s t disjoint paths

CS 473Lecture ?26 FINDING A MAXIMUM BIPARTITE MATCHING second show that | f | = |M|: –net flow accross the cut ({s}  L, R  {t}) = | f | by L3 –| f | = f (s  L, R  t) = f (s, R  t) + f (L, R  t) = f (s, R  t) + f (L, R) + f (L, t) = 0 + f (L, R) + 0; f (s, R  t) = f (L, t) since  no such edges = f (L, R) = |M| since f(u,v) = 1  u  L, v  R & (u,v)  M

CS 473Lecture ?27 FINDING A MAXIMUM BIPARTITE MATCHING proof L8 (b): let f be a integer-valued flow in G' –define M={(u,v): u  L, v  R, and f (u,v) > 0} first show that M is a matching in G: i.e., all edges in M are vertex disjoint –let p e (u) / p l (u) = positive net flow entering / leaving vertex u,  u  V –each u  L has exactly one incoming edge (s,u) with c(s,u)=1  p e (u) ≤ 1  u  L

CS 473Lecture ?28 FINDING A MAXIMUM BIPARTITE MATCHING –since f is integer-valued;  u  L, p e (u) = 1  p l (u) = 1 due to flow conservation   u  L, p e (u)=1   exactly one vertex v  R  f ( u, v ) = 1 to make p l (u) = 1 –thus, at most one edge leaving each vertex u  L carries positive flow = 1 –a symmetric argument holds for each vertex v  R –therefore, M is a matching

CS 473Lecture ?29 FINDING A MAXIMUM BIPARTITE MATCHING second show that |M| = | f |: –|M| = f (L, R) by above def for M since f (u,v) is either 0 or 1 = f (L, V' – s – L – t) = f (L,V') – f (L,s) – f (L,L) – f (L,t) = 0 – f (L,s) – 0 – 0 = – f (L,s) = f (s,L) = | f | due to skew symmetry & then def. f (L,V') = f (L,V') = 0 due to flow cons. f (L,t) = 0 since no edges from L to t

CS 473Lecture ?30 FINDING A MAXIMUM BIPARTITE MATCHING example: a matching M with |M| = 3 & a f on the corresponding G' with | f | = 3 u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v2 u1u1 u3u3 u4u4 u5u5 u2u2 v1v1 v3v3 v4v4 v2v2 s t