1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search.

Slides:



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

Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 22.
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.
Chapter 10: Iterative Improvement The Maximum Flow Problem The Design and Analysis of Algorithms.
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 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.
Chapter 23 Minimum Spanning Trees
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)
CS138A Maximum Bipartite Matching Peter Schröder.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
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.
CSE 589 Part III The computer is useless It can only answer questions. -- Pablo Picasso.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 4 Tuesday, 10/2/01 Graph Algorithms: Part 2 Network.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Yangjun Chen 1 Network Flow What is a network? Flow network and flows Ford-Fulkerson method - Residual networks - Augmenting paths - Cuts of flow networks.
Chapter 27 Maximum Flow Maximum Flow Problem The Ford-Fulkerson method m bipartite matching.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
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.
Maximum Flow Maximum Flow Problem The Ford-Fulkerson method
Flow Networks Formalization Basic Results Ford-Fulkerson Edmunds-Karp Bipartite Matching Min-cut.
Maximum Flow Chapter 26.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 5 Graph Algorithms.
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).
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
CS223 Advanced Data Structures and Algorithms 1 Review for Final Neil Tang 04/27/2010.
Max Flow – Min Cut Problem. Directed Graph Applications Shortest Path Problem (Shortest path from one point to another) Max Flow problems (Maximum material.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Flow Networks & Flows.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
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)
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.
Chapter 26 of CLSR Maximum Network Flow by me Dr. M. Sakalli from Ch26 of CSLR and many other sources. Marmara Univ.
1 Network Flow CSC401 – Analysis of Algorithms Chapter 8 Network Flow Objectives: Flow networks –Flow –Cut Maximum flow –Augmenting path –Maximum flow.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
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
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Maximum Flow Chapter 26.
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)
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
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
Presentation transcript:

1 Review of some graph algorithms Graph G(V,E) (Chapter 22) –Directed, undirected –Representation Adjacency-list, adjacency-matrix Breadth-first search (BFS), O(V+E) Depth-first search (DFS), O(V+E), recursive –Topological Sort –Strong connected components

2 Review of some graph algorithms Minimum Spanning Tree (Chapter 23) –Greedy algorithm –Kruskal’s algorithm: O(ElgV) Using disjoint set algorithm, similar to connected components – Prim’s algorithm: O(E+VlgV) Similar to Dijkstra, using min-priority QUEUE Single-source shortest paths (Chapter 24) –Bellman-Ford algorithm: O(VE) d j =min{d j,d k +w(j,k)} where k is j’s neighbor –Dijkstra’s algorithm: O(E+VlgV) Find the closest node n1 which is s’s neighbor, modify other nodes distance Find the second closest node n2 which is the neighbor of s or n1, modify the distance Find the third closest node n3, which is the neighbor of s, n1, or n2,,….

3 Graph algorithms (cont.) All-pairs shortest paths (Chapter 25) –Floyd-Warshall algorithms: O(V 3 ). –Dynamic programming, similar to Matrix Chain Multiplications –d ij (0) =w ij –For k  1 to n for i  1 to n –for j  1 to n »d ij (k) =min(d ij (k-1),d ik (k-1) +d kj (k-1) )

4 Maximum Flow (chap. 26) Max-flow problem: –A directed graph G=, a capacity function on each edge c(u,v)  0 and a source s and a sink t. A flow is a function f : V  V  R that satisfies: Capacity constraints: 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},  v  V f(u,v)=0, or to say, total flow out of a vertex other s or t is 0, or to say, how much comes in, also that much comes out. –Find a maximum flow from s to t. –Denote the value of f as |f|=  v  V f(s,v), i.e., the total flow out of the source s. |f|=  u  V f(u,t), i.e., the total flow into the sink t.

5 Example of max-flow problem

6 Ford-Fulkerson method Contains several algorithms: –Residue networks –Augmenting paths

7 Residual Networks Given a flow network G= and a flow f, –the residual network of G induced by f is G f = where E f ={(u,v)  V  V: c f (u,v)=c(u,v)-f(u,v), and c f (u,v)>0} –a network with left capacity >0, also a flow network.

8 Residual network and augmenting path

9 Residual network and flow theorem Lemma 26.2 (page 653): –Let G= be a flow network with source s and sink t, and let f be a flow, –Let G f be the residual network of G induced by f, and let f' be a flow of G f. –Define the flow sum: f+f' as: –(f+f')(u.v)=f(u.v)+f'(u.v), then –f+f' is a flow in G with value |f+f'|=|f|+|f'|. Proof: –Capacity constraint, skew symmetry, and flow conservation and finally |f+f'|=|f|+|f'|.

10 Augmenting paths Let G= be a flow network with source s and sink t, and let f be a flow, An augmenting path p in G is a simple path from s to t in G f, the residual network of G induced by f. Each edge (u,v) on an augmenting path admits some additional positive flow from u to v without violating the capacity constraint. Define residual capacity of p is the maximum amount we can increase the flow: –c f (p)=min{c f (u,v): (u,v) is on p.}

11 Augmenting path Lemma 26.3 (page 654): –Let G= be a flow network with source s and sink t, let f be a flow, and let p be an augmenting path in G f. Define f p : V  V  R by: f p (u,v)= c f (p) if (u,v) is on p. -c f (p) if (v,u) is on p. 0 otherwise –Then f p is a flow in G f with value |f p |=c f (p) >0. Corollary 26.4 (page 654): –Define f'=f+f p, then f' is a flow in G with value |f'|=|f|+|f p |>|f|.

12 Basic Ford-Fulkerson algorithm Running time: if capacities are in irrational numbers, the algorithm may not terminate. Otherwise, O(|E||f*|) where f* is the maximum flow found by the algorithm: while loop runs f* times, increasing f* by one each loop, finding an augmenting path using depth- first search or breadth-first search costs |E|.

13 Execution of Ford-Fulkerson

14 An example of loop |f*| times Note: if finding an augmenting path uses breadth-first search, i.e., each augmenting path is a shortest path from s to t in the residue network, while loop runs at most O(|V||E|) times (in fact, each edge can become critical at most |V|/2-1 times), so the total cost is O(|V||E| 2 ). Called Edmonds-Karp algorithm.

15 Network flows with multiple sources and sinks Some problems can be reduced to maximum flow problem. Here give two examples. Reduce to network flow with single source and single sink Introduce a supersource s which is directly connected to each of the original sources s i with a capacity c(s,s i )=  Introduce a supersink t which is directly connected from each of the original sinks t i with a capacity c(s i,s)= 

16 Maximum bipartite matching Matching in a undirected graph G=(V,E) –A subset of edges M  E, such that for all vertices v  V, at most one edge of M is incident on v. Maximum matching M –For any matching M′, |M|  | M′|. Bipartite: V=L  R where L and R are distinct and all the edges go between L and R. Practical application of bipartite matching: –Matching a set L of machines with a set R of tasks to be executed simultaneously. –The edge means that a machine can execute a task.

17 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

18 Finding a maximum bipartite matching Construct a flow network G′=(V′,E′,C) from G=(V,E) as follows where =L  R: –V′=V  {s,t}, introducing a source and a sink –E′={(s,u): u  L}  E  {(v,t): v  R} –For each edge, its capacity is unit 1. As a result, the maximum flow in G′ is a maximum matching in G.

19 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.