Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.

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.
Advanced Algorithm Design and Analysis (Lecture 7) SW5 fall 2004 Simonas Šaltenis E1-215b
1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.
MAXIMUM FLOW Max-Flow Min-Cut Theorem (Ford Fukerson’s Algorithm)
CSE 326: Data Structures Network Flow and APSP Ben Lerner Summer 2007.
The Maximum Network Flow Problem. CSE Network Flows.
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 
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.
1 The Max Flow Problem. 2 Flow networks Flow networks are the problem instances of the max flow problem. A flow network is given by 1) a directed graph.
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.
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.
COMS Network Theory Week 6: February 28, 2008 Dragomir R. Radev Thursdays, 6-8 PM 233 Mudd Spring 2008.
All-Pairs Shortest Paths
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.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
1 Ford-Fulkerson method Ford-Fulkerson(G) f = 0 while( 9 simple path p from s to t in G f ) f := f + f p output f Runs in time O(|f max | |E|) where f.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Maximum Flow Chapter 26.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Announcements Network Flow today, depending on how far we get, we will do String Matching on Wednesday Then Review for Final next Monday This week’s lab.
Single Source Shortest-Path: The General Case (with negative edges) Bellman-Ford algorithm. Iteratively relax all edges |V|-1 times Running time? O(VE).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
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.
Network Flow Analysis of Algorithms.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 25.
Algorithm Design and Analysis (ADA)
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Flow Networks Ching-Chen Huang Hsi-Yue Hsiao. CONTENTS Network flows on directed acyclic graphs Ford-fulkerson Algorithms -Residual networks.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
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,
Maximum Flow Problem Definitions and notations The Ford-Fulkerson method.
Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search.
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)
Maximum Flow Chapter 26.
The Maximum Network Flow Problem
Maximum Flow Chapter 26.
BIPARTITE GRAPHS AND ITS APPLICATIONS
Richard Anderson Lecture 23 Network Flow
Lecture 22 Network Flow, Part 2
ADVANCED ALGORITHMS GRAPH ALGORITHMS (UNIT-2).
Network Flows and Matching (Supplementary)
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 21 Network Flow
Network Flows and Matching (Supplementary)
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
Text Book: Introduction to algorithms By C L R S
Lecture 21 Network Flow, Part 1
Lecture 22 Network Flow, Part 2
Richard Anderson Lecture 22 Network Flow
Presentation transcript:

Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005

2 This Lecture All-pairs shortest paths –Johnson’s algorithm Maximum flow –Concepts –Ford-Fulkerson method –Maximum bipartite matching

3 Johnson’s Algorithm What if the graph is sparse? –If no negative edges – run repeated Dijkstra’s –If negative edges – let us somehow change the weights of all edges (to w’) and then run repeated Dijkstra’s Requirements for reweighting: –Non-negativity: for each (u,v), w’(u,v)  0 –Shortest-path equivalence: for all pairs of vertices u and v, a path p is a shortest path from u to v using weights w if and only if p is a shortest path from u to v using weights w’.

4 Choosing reweighting function How to choose function h? The idea of Johnson: –1. Augment the graph by adding vertex s and edges (s,v) for each vertex v with 0 weights. 2. Compute the shortest paths from s in the augmented graph (using Belman-Ford). 3. Make h(v) = (s, v) s

5 Johnson’s algorithm Why does it work? –By definition of the shortest path: for all edges (u,v), h(u)  h(v) + w(u,v) –Thus, w(u,v) + h(u) – h(v)  0 Johnson’s algorithm: –1. Construct augmented graph –2. Run Bellman-Ford (possibly report a negative cycle), to find h(v) =  (s, v) for each vertex v –3. Reweight all edges: w’(u,v)  w(u,v) + h(u) – h(v). –4. For each vertex u: Run Dijkstra’s from u, to find  ’(u, v) for each v For each vertex v: D[u][v]  ’(u, v) + h(v) – h(u)

6 Example Do the reweighting on this example:

7 Flow networks What if weights in a graph are maximum capacities of some flow of material? –Pipe network to transport fluid (e.g., water, oil) Edges – pipes, vertices – junctions of pipes –Data communication network Edges – network connections of different capacity, vertices – routers (do not produce or consume data just move it) –Concepts (informally): Source vertex s (where material is produced) Sink vertex t (where material is consumed) For all other vertices – what goes in must go out Goal: maximum rate of material flow from source to sink

8 Formalization How do we formalize flows? –Graph G=(V,E) – a flow network Directed, each edge has capacity c(u,v)  0 Two special vertices: source s, and sink t For any other vertex v, there is a path s  …  v  …  t –Flow – a function f : V  V  R Capacity constraint: For all u, v  V: f(u,v)  c(u,v) Skew symmetry: For all u, v  V: f(u,v) = –f(v,u) Flow conservation: For all u  V – {s, t}:

9 Maximum flow What do we want to maximize? –Value of the flow f: We want to find a flow of maximum value! s t 9 a b c d

Augmenting path Idea for the algorithm: –If we have some flow,… –…and can find a path p from s to t (augmenting path), such that there is a > 0, and for each edge (u,v) in p we can add a units of flow: f(u,v) + a  c(u,v) –Then just do it, to get a better flow! –Augmenting path in this graph? s t 9 a b c d

11 The Ford-Fulkerson method Ford-Fulkerson(G,s,t) 01 initialize flow f to 0 everywhere 02 while there is an augmenting path p do 03 augment flow f along p 04 return f Sketch of the method: How do we find augmenting path? How much additional flow can we send through that path? Does the algorithm always find the maximum flow?

12 Residual network How do we find augmenting path? –It is any path in residual network: Residual capacities: c f (u,v) = c(u,v) – f(u,v) Residual network: G f =(V,E f ), where E f = {(u,v)  V  V : c f (u,v) > 0} What happens when f(u,v) < 0 (and c(u,v) = 0)? Observation – edges in E f are either edges in E or their reversals: |E f |  2|E| Compute residual network: s t 9 a b c d

13 Residual capacity of a path How much additional flow can we send through an augmenting path? –Residual capacity of a path p in G f : c f (p) = min{c f (u,v): (u,v) is in p} –Doing augmentation: for all (u,v) in p, we just add this c f (p) to f(u,v) (and subtract it from f(v,u)) –Resulting flow is a valid flow with a larger value. –What is the residual capacity of the path (s,a,b,t)?

14 The Ford-Fulkerson method Ford-Fulkerson(G,s,t) 01 for each edge (u,v) in G.E do 02 f(u,v)  f(v,u)  0 03 while there exists a path p from s to t in residual network G f do 04 c f = min{c f (u,v): (u,v) is in p} 05 for each edge (u,v) in p do 06 f(u,v)  f(u,v) + c f 07 f(v,u)  -f(u,v) 08 return f The algorithms based on this method differ in how they choose p in step 03.

15 Cuts –A cut is a partition of V into S and T = V – S, such that s  S and t  T –The net flow (f(S,T)) through the cut is the sum of flows f(u,v), where u  S and v  T –The capacity (c(S,T)) of the cut sum of capacities c(u,v), where u  S and v  T –Minimum cut – a cut with the smallest capacity of all cuts –|f|= f(S,T) Does it always find the maximum flow? s t 9 a b c d

16 Correctness of Ford-Fulkerson Max-flow min-cut theorem: –If f is the flow in G, the following conditions are equivalent: 1. f is a maximum flow in G 2. The residual network G f contains no augmenting paths 3. |f| = c(S,T) for some cut (S,T) of G

17 Edmonds-Karp algorithm Take shortest path (in terms of number of edges) as an augmenting path – Edmonds-Karp algorithm –How do we find such a shortest path? –Running time O(VE 2 ), because the number of augmentations is O(VE) –To prove this we need to prove that: The length of the shortest path does not decrease Each edge can become critical at most ~ V/2 times. Edge (u,v) on an augmenting path p is critical if it has the minimum residual capacity in the path: c f (u,v) = c f (p)

18 Maximum Bipartite Matching A bipartite graph is a graph G=(V,E) in which V can be divided into two parts L and R such that every edge in E is between a vertex in L and a vertex in R. e.g. vertices in L represent skilled workers and vertices in R represent jobs. An edge connects workers to jobs they can perform.

19 A matching in a graph is a subset M of E, such that for all vertices v in V, at most one edge of M is incident on v. Maximum Bipartite Matching

20 A maximum matching is a matching of maximum cardinality. maximal not maximum maximum Maximum Bipartite Matching

21 Solving the Maximum Bipartite Matching Problem Greedy algorithm? Reduce an instance of the maximum bipartite matching problem on graph G to an instance of the max-flow problem on a corresponding flow network G’. Solve using Ford-Fulkerson method.

22 Corresponding Flow Network To form the corresponding flow network G' of the bipartite graph G: –Add a source vertex s and edges from s to L. –Direct the edges in E from L to R. –Add a target vertex t and edges from R to t. –Assign a capacity of 1 to all edges. Claim: max-flow in G’ corresponds to a max- bipartite-matching on G.

23 Example min cut |M| = 3  max flow = 3