Algorithm Design and Analysis (ADA)

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.
Algorithm Design and Analysis (ADA)
MAX FLOW APPLICATIONS CS302, Spring 2013 David Kauchak.
Introduction To Algorithms CS 445 Discussion Session 8 Instructor: Dr Alon Efrat TA : Pooja Vaswani 04/04/2005.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
The Maximum Network Flow Problem. CSE Network Flows.
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.
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
Lectures on Network Flows
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf.
HW2 Solutions. Problem 1 Construct a bipartite graph where, every family represents a vertex in one partition, and table represents a vertex in another.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2001 Lecture 4 Tuesday, 2/19/02 Graph Algorithms: Part 2 Network.
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
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.
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.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
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.
MAX FLOW CS302, Spring 2013 David Kauchak. Admin.
Maximum Flow Chapter 26.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
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.
CS 473Lecture ?1 CS473-Algorithms I Lecture ? Network Flows Finding Max Flow.
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.
1 WEEK 11 Graphs III Network Flow Problems A Simple Maximum-Flow Algorithm Izmir University of Economics.
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.
Chapter 7 April 28 Network Flow.
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.
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.
Announcements Finish up Network Flow today Then Review for Final on Monday ◦ HW#5 is due on Monday, let me or the TA’s know if you have trouble starting.
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.
Data Structures & Algorithms Network Flow Richard Newman based on book by R. Sedgewick.
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.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
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.
11/21/02CSE Max Flow CSE Algorithms Max Flow Problems.
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
Contest Algorithms January 2016 Describe the maxflow problem, explain the Ford-Fulkerson, Edmonds-Karp algorithms. Look at the mincut problem, bipartite.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
CS4234 Optimiz(s)ation Algorithms
Richard Anderson Lecture 23 Network Flow
Instructor: Shengyu Zhang
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lecture 10 Network flow Max-flow and Min-cut Ford-Fulkerson method
Richard Anderson Lecture 23 Network Flow
Flow Networks and Bipartite Matching
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
Richard Anderson Lecture 22 Network Flow
Lecture 22 Network Flow, Part 2
Presentation transcript:

Algorithm Design and Analysis (ADA) 242-535, Semester 1 2014-2015 12. Maxflow Networks v.2 Objectives describe the maxflow problem, explain and analyse the Ford-Fulkerson, Edmonds-Karp look at the mincut problem, bipartite matching and edge disjoint paths

Overview A Flow Network Ford-Fulkerson (FF) Algorithm Edmonds-Karp (EK) Algorithm The Mincut Problem Bipartite Matching Edge Disjoint Paths Making Maxflow Faster

1. A Flow Network 'pipe' capacity for 'water' flow x 20 10 30 s t source terminal (sink) 20 10 y What is the maximum flow f from s to t?

Answer flow / capacity x 20/20 10/10 10/30 s t 20/20 10/10 y flows must be integer 10/30 s t 20/20 10/10 y Maxflow f = 30 = ∑ outflow of s = ∑ inflow of t

Flow Rules Capacity constraint Flow conservation inflow at v = 0 ≤ edge's flow ≤ edge's capacity Flow conservation inflow = outflow at every vertex (except s and t) inflow at v = 5 + 5 + 0 = 10 outflow at v = 10 + 0 = 10

Another Example A maxflow f in G is 19

Many Applications of Maxflow Bipartite matching Data mining Network reliability Image processing Network connectivity Distributed computing many more ... blood flow analysis

2. Ford-Fulkerson (FF) Algorithm void FF(Graph G, Node s, Node t) { initialize flows on all edges in G to 0; change G into residual graph Gf; while (can find an augmented path P in Gf) { bottleneck b = minimum of edge weights in P; augment flow along P in G using b; regenerate Gf from updated G; } report maxflow f in G; }

Graph  Residual Graph Every flow/capacity edge in the graph G becomes two edges in the residual graph Gf forward edge: max amount can increase flow flow / capacity Gf 11 G 6 / 17 u v u v 6 values on edges called residual capacities backward edge: max amount can decrease flow

2.1 Example: initial G  Gf x x G to Gf s t s t y y x 0/10 x 0/20 20 10 G to Gf s t s t 0/30 30 10 0/10 0/20 20 y y 20 x 10 To make Gf less messy, 0 weighted edges are not drawn. s t 30 10 20 y

Find an Augmented Path P in Gf In FF, an augmented path is any path from s to t in the residual graph Gf forward and backward edges can be used (if not 0) 20 x One possible augmented path P: s  x  y  t 10 s t 20 30 30 20 10 20 y Bottleneck b = min of edge weights in P = 20

Augment Flow along P in G using b The flow fe on each edge e in G can change in two ways: fe = fe + b in G if the edge in P is a forward edge i.e. increase the flow fe = fe – b in G if the edge in P is a backward edge i.e. decrease the flow

Update G x x G to Gf s t s t y y One augmented path P: s  x  y  t x 0/10 0/20 20 x 10 G to Gf s t 0/30 s t 30 10 0/10 0/20 20 y y One augmented path P: s  x  y  t x 0/10 20/20 augment flow s t 20 30 20/30 20 0/10 20/20 Bottleneck b = 20; s  x and y  t are the critical edges y

Regenerate Gf from Updated G x 10 x 0/10 20/20 G to Gf 20 s 10 t s t 20/30 20 10 20 0/10 20/20 y y remove 0 weight edges x 10 20 s 10 t 20 10 20 y

Find Augmented Path x One augmented path P: s  y  x  t s t y 10 20 10 One augmented path P: s  y  x  t s t 20 10 20 10 20 10 y Bottleneck b = 10; s  y and x  t are the critical edges

Update G x x G to Gf s t s t y y One augmented path P: s  y  x  t x 0/10 x 20/20 10 G to Gf 20 s t s 10 t 20/30 20 10 20 0/10 20/20 y y One augmented path P: s  y  x  t x 10/10 20/20 augment flow 10 20 10 s t 10/30 Bottleneck b = 10 10/10 20/20 y

Regenerate Gf from Updated G x x 10/10 20/20 G to Gf 20 s 20 10 t s t 10 10/30 20 10 10/10 20/20 y y remove 0 weight edges x 20 s 20 10 t 10 20 10 y

Find Augmented Path x There are no paths from s to t. The while loop in FF() exits, and the maximum flow f in G is reported. 20 s 20 10 t 10 20 10 y maxflow f = 30 = ∑ outflow of s = ∑ inflow of t = ∑ all bottlenecks b's = 20 + 10 = 30 x 10/10 20/20 s t 10/30 10/10 20/20 y

2.2 Another Example v1 12 v3 20 16 t s 4 7 9 13 v2 v4 4 14

Add Initial Flows of 0 v1 v3 t s v2 v4 0/12 0/20 0/16 0/4 0/7 0/9 0/13 0/14

Generate Initial Gf G to Gf s t s t remove 0 weight edges s t 12 v1 0/12 v3 v1 v3 0/20 16 20 0/16 0/9 9 s t s 4 7 t 0/4 0/7 14 0/13 v2 v4 13 4 0/14 v2 v4 0/4 remove 0 weight edges 12 v1 v3 16 20 9 s 4 7 t 14 13 v2 4 v4

Gf G b = 4 b = 4 b = 4

Gf G b = 7 2 b = 4 11 maxflow f = 23 (also = ∑ all b's) 2 11

2.3. FF Running Time dfs/bfs = O(V+E) = O(E) O(E) O(E) O(E) O(E) void FF(Graph G, Node s, Node t) { initialize flows on all edges in G to 0; change G into residual graph Gf; while (can find an augmented path P in Gf) { bottleneck b = minimum of edge weights in P; augment flow along P in G using b; regenerate Gf from updated G; } report maxflow f in G; } O(E) O(E) O(E) O(E) Total Running time: O(E ∙ |f|) no. of loops = | f |

Why no. of loops == |f|? The loop stops when no more b's can be found. The maxflow f = ∑ all b's In the worst case each time round loop produces the smallest b, which is 1 So it will take f loops before ∑ all b's == f So max no. of loops == |f|

In the worst case, the running time of FF is O(E · |f|) |f| might be very big depending on the problem. It might be much larger than the number of edges.

2.4. FF can be slow!

The Augmenting Paths First Second

many, many more Third Fourth

199th 200th (= maxflow)

Choosing Paths is Important Only two iterations are needed.

2.5. Choosing Augmenting Paths Use care when selecting augmenting paths Some choices lead to exponential algorithms Clever choices lead to polynomial algorithms If capacities are not integers, some algorithm are not guaranteed to terminate Goal: choose augmenting paths so that: Can find augmenting paths efficiently Few iterations Choose augmenting paths with: Max bottleneck capacity Sufficiently large bottleneck capacity Fewest number of edges

3. Edmonds-Karp (EK) Algorithm void EK(Graph G, Node s, Node t) { initialize flows on all edges in G to 0; change G into residual graph Gf; while (can find an augmented SHORTEST path P in Gf) { bottleneck b = minimum of edge weights in P; augment flow along P in G using b; regenerate Gf from updated G; } report maxflow f in G; } Running time: O(V· E2)

Finds an augmenting path using breadth-first search. The bfs algorithm is slightly changed: a weight of 1 is assigned to every forward and backward edge, not the edge's residual capacity i.e. count the no. of edges

3.1. First Example Again x 20 10 30 s t 20 10 y

Generate Initial Gf x x G to Gf s t s t y y remove 0 weight edges x s 0/10 x 0/20 20 10 G to Gf s t s t 0/30 30 10 0/10 0/20 20 y y remove 0 weight edges 20 x 10 s t 30 10 20 y

Gf  G x x s t s t b = 10 y y x x s t s t b = 10 y y 10/10 20 10 10/20 0/30 30 10 b = 10 20 0/10 0/20 y y 10 x x 10/10 10 10/20 10 s t s t 0/30 30 10 b = 10 20 10/10 10/20 y y

Gf  G x x s t s t b = 10 y y x maxflow f = 30 (also = ∑ all b's) s t 10/10 10 20/20 10 s 30 t s t 10/30 10 10 b = 10 10 10/10 20/20 y y x 10 maxflow f = 30 (also = ∑ all b's) 20 s 20 10 t 10 20 y

3.2. EK Running Time bfs = O(V+E) = O(E) O(E) O(E) O(E) O(E) void EK(Graph G, Node s, Node t) { initialize flows on all edges in G to 0; change G into residual graph Gf; while (can find an augmented SHORTEST path P in Gf) { bottleneck b = minimum of edge weights in P; augment flow along P in G using b; regenerate Gf from updated G; } report maxflow f in G; } O(E) O(E) O(E) O(E) Running time: O(V· E2) no. of loops = O(V · E)

Why no. of loops == O(V∙E)? The loop stops when no more b's can be found (i.e. when there are no more critical edges). So max no of loops == max no. of critical edges Remember: Smallest shortest path == 1 Longest shortest path == |V| - 1 Smallest b in a path == 1

Assume e is critical when path distance = p: What is the maximum number of times one edge e (u -- v) can be critical? Assume e is critical when path distance = p: assume path distance of s to u == d u s t 1 assume path distance of s to t == p v path s to v == d+1

The earliest that e can next be critical is when path distance = p+2 path distance of s to u == d + 2 u s t 1 smallest path distance of s to t == p + 2 v smallest path s to v == d+1

So the most times that one edge can be critcal is when p == 1, 3, 5, 7, ..., |V-1| = O(v/2) = O(V) times The most times that all e edges can be critical is: E * O(V) = O(E ∙ V) Max no. of critical edges == O(V ∙ E) == max no. of loops

4. The Mincut Problem A cut is a partition of a flow network's vertices into two disjoint sets, with the source (s) in one set A and the sink (t) in the other set B. A cut's capacity is the sum of the capacities of the edges from A to B. The minimum cut (mincut) problem: find a cut of minimum capacity.

find a cut of minimum capacity. Example don't count edges from B to A capacity = 10 + 5 + 15 = 30 capacity = 10 + 8 + 16 = 34 The minimum cut (mincut) problem: find a cut of minimum capacity.

Maxflow == Mincut The maxflow problem The mincut problem find a flow of maximum value The mincut problem find a cut of minimum capacity Two problems that appear very different but are actually two versions of the same question. Maxflow-mincut theorem: maxflow value = mincut capacity

5. Bipartite Matching Offers: Students apply for jobs. Each student gets several offers. Is there a way to match every student to a different job?

As a Bipartite Graph Alice Adobe Bob Amazon Carol Facebook Dave Google Eliza IBM Frank Yahoo

Maximize No. of 1-1 Edges Alice Adobe Bob Amazon Carol Facebook Dave Google A perfect match Eliza IBM Frank Yahoo

Changing Bipartite to Maxflow Direct edges from L to R, and set all capacities to 1. Add source s, and link s to each node in L. Add sink t, and link each node in R to t. 1 1 1 1 1

Conversion to Maxflow Alice Adobe Bob Amazon Carol Facebook s t Dave 1/1 1/1 1/1 Bob Amazon 1/1 1/1 1/1 1/1 Carol 1/1 Facebook 1/1 1/1 s t 1/1 1/1 Dave Google 1/1 1/1 1/1 Eliza IBM 1/1 1/1 1/1 Frank Yahoo Other edges are 0/1

6. Edge Disjoint Paths Find the max number of edge-disjoint s-t paths in a digraph. two paths are edge-disjoint if they have no edge in common

Solution Two edge-disjoint s-t paths:

Maxflow Formulation Assign capacities of 1 to every edge. Max no. of edge-disjoint s-to-t paths = maxflow 1/1 0/1 1/1 1/1 1/1 1/1 0/1 1/1 1/1 1/1 1/1 Other edges are 0/1

6.1. Network Connectivity Related Problem: Find the min. no. of edges whose removal disconnects t from s. A set of edges F disconnects t from s if each s-t paths uses at least one edge in F removing F would make t unreachable from s Removing two edges breaks the s-t link

The max no. of edge-disjoint s-t paths = min no The max no. of edge-disjoint s-t paths = min no. of edges whose removal disconnects t from s. utilizes the mincut

7. Making MaxFlow Faster year method worst case running time discovered by 1955 augmenting path O(E · |f|) Ford-Fulkerson 1970 shortest augmented path O(V · E2) Edmonds-Karp 1983 dynamic trees O(E2 ·log E) Sleator-Tarjan 1985 capacity scaling O(E2 · log C) Gabow 1997 length function O(E3/2 · log E · log C) Goldberg-Rao ? E C is the biggest capacity on an edge in the graph.

Analysis is Tricky Worst-case big-Oh is generally not useful for predicting or comparing real-world maxflow algorithm speeds. Best in practice: push-relabel method with gap relabeling: O(E3/2) (can be written as O(V3) very close to linear in E