CSEP 521 Applied Algorithms

Slides:



Advertisements
Similar presentations
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Advertisements

1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
CSE 421 Algorithms Richard Anderson Lecture 23 Network Flow Applications.
Foreground/Background Image Segmentation. What is our goal? To label each pixel in an image as belonging to either the foreground of the scene or the.
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
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)
Advanced Algorithm Design and Analysis (Lecture 8) SW5 fall 2004 Simonas Šaltenis E1-215b
HW2 Solutions. Problem 1 Construct a bipartite graph where, every family represents a vertex in one partition, and table represents a vertex in another.
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)
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.
CSE 421 Algorithms Richard Anderson Lecture 24 Network Flow Applications.
15.082J and 6.855J and ESD.78J November 2, 2010 Network Flow Duality and Applications of Network Flows.
Advanced Algorithms Piyush Kumar (Lecture 4: MaxFlow MinCut Applications) Welcome to COT5405.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 26.
CS774. Markov Random Field : Theory and Application Lecture 13 Kyomin Jung KAIST Oct
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 22 Network.
CSE 421 Algorithms Richard Anderson Lecture 24 Network Flow Applications.
Applications of the Max-Flow Min-Cut Theorem. S-T Cuts SF D H C A NY S = {SF, D, H}, T={C,A,NY} [S,T] = {(D,A),(D,C),(H,A)}, Cap [S,T] =
CSE 421 Algorithms Richard Anderson Lecture 26 Network Flow Applications.
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 Problem (Thanks to Jim Orlin & MIT OCW)
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
15.082J & 6.855J & ESD.78J October 7, 2010 Introduction to Maximum Flows.
15.082J and 6.855J March 4, 2003 Introduction to Maximum Flows.
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.
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.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Prof. Swarat Chaudhuri COMP 382: Reasoning about Algorithms Fall 2015.
1 Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSE 421 Algorithms Richard Anderson Lecture 24 Network Flow Applications.
CSE 421 Algorithms Richard Anderson Lecture 21 Shortest Paths and Network Flow.
TU/e Algorithms (2IL15) – Lecture 8 1 MAXIMUM FLOW (part II)
Algorithms Classroom Activities Richard Anderson University of Washington July 3, 20081IUCEE: Algorithm Activities.
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
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
CS4234 Optimiz(s)ation Algorithms
Richard Anderson Lecture 25 Min Cut Applications and NP-Completeness
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
Richard Anderson Lecture 23 Network Flow Applications
Richard Anderson Lecture 27 Network Flow Applications
Richard Anderson Lecture 24 Network Flow Applications
Richard Anderson Lecture 25 Open Pit Mining
Flow Networks Topics Flow Networks Residual networks
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 23 Network Flow
Richard Anderson Lecture 21 Network Flow
Max Flow Min Cut, Bipartite Matching Yin Tat Lee
Flow Networks General Characteristics Applications
Flow Networks and Bipartite Matching
Piyush Kumar (Lecture 6: MaxFlow MinCut Applications)
Algorithms (2IL15) – Lecture 7
Text Book: Introduction to algorithms By C L R S
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 22 Network Flow
Lecture 21 Network Flow, Part 1
Richard Anderson Lecture 23 Network Flow Applications
Richard Anderson Lecture 20 Shortest Paths and Network Flow
Lecture 22 Network Flow, Part 2
Richard Anderson Lecture 24 Network Flow Applications
Richard Anderson Lecture 26 Open Pit Mining
Richard Anderson Lecture 22 Network Flow
Presentation transcript:

CSEP 521 Applied Algorithms Richard Anderson Lecture 9 Network Flow Applications

Announcements Reading for this week 7.5-7.12. Network flow applications Next week: Chapter 8. NP-Completeness Final exam, March 18, 6:30 pm. At UW. 2 hours In class (CSE 303 / CSE 305) Comprehensive 67% post midterm, 33% pre midterm

Network Flow

Review Network flow definitions Flow examples Augmenting Paths Residual Graph Ford Fulkerson Algorithm Cuts Maxflow-MinCut Theorem

Network Flow Definitions Flowgraph: Directed graph with distinguished vertices s (source) and t (sink) Capacities on the edges, c(e) >= 0 Problem, assign flows f(e) to the edges such that: 0 <= f(e) <= c(e) Flow is conserved at vertices other than s and t Flow conservation: flow going into a vertex equals the flow going out The flow leaving the source is a large as possible

Find a maximum flow a d g s b e h t c f i 20/20 20/20 0/5 0/5 20/20 5/5 0/5 0/5 5/5 0/20 25/30 20/20 30/30 s b e h t 20/20 0/5 5/5 20/20 0/5 0/5 15/20 15/25 c f i 20/20 10/10

Residual Graph Flow graph showing the remaining capacity Flow graph G, Residual Graph GR G: edge e from u to v with capacity c and flow f GR: edge e’ from u to v with capacity c – f GR: edge e’’ from v to u with capacity f

Residual Graph u u 15/20 0/10 5 10 15 15/30 s t 15 15 s t 5 5/10 20/20 v v

Augmenting Path Lemma Let P = v1, v2, …, vk be a path from s to t with minimum capacity b in the residual graph. b units of flow can be added along the path P in the flow graph. u u 5 10 15/20 0/10 15 15 15 s t 15/30 s t 5 5 20 5/10 20/20 v v

Ford-Fulkerson Algorithm (1956) while not done Construct residual graph GR Find an s-t path P in GR with capacity b > 0 Add b units along in G If the sum of the capacities of edges leaving S is at most C, then the algorithm takes at most C iterations

Cuts in a graph Cut: Partition of V into disjoint sets S, T with s in S and t in T. Cap(S,T): sum of the capacities of edges from S to T Flow(S,T): net flow out of S Sum of flows out of S minus sum of flows into S Flow(S,T) <= Cap(S,T)

Ford Fulkerson MaxFlow – MinCut Theorem There exists a flow which has the same value of the minimum cut Shows that a cut is the dual of the flow Proves that the augmenting paths algorithm finds a maximum flow Gives an algorithms for finding the minimum cut

Better methods of for constructing a network flow Improved methods for finding augmenting paths or blocking flows Goldberg’s Preflow-Push algorithm Text, section 7.4

Applications of Network Flow

Problem Reduction Reduce Problem A to Problem B Practical Theoretical Convert an instance of Problem A to an instance of Problem B Use a solution of Problem B to get a solution to Problem A Practical Use a program for Problem B to solve Problem A Theoretical Show that Problem B is at least as hard as Problem A

Problem Reduction Examples Reduce the problem of finding the longest path in a directed graph to the problem of finding a shortest path in a directed graph Construct an equivalent minimization problem

Undirected Network Flow Undirected graph with edge capacities Flow may go either direction along the edges (subject to the capacity constraints) u 10 20 5 s t 20 10 v Construct an equivalent flow problem

Multi-source network flow Sources s1, s2, . . ., sk Sinks t1, t2, . . . , tj Solve with Single source network flow

Bipartite Matching A graph G=(V,E) is bipartite if the vertices can be partitioned into disjoints sets X,Y A matching M is a subset of the edges that does not share any vertices Find a matching as large as possible

Application A collection of teachers A collection of courses And a graph showing which teachers can teach which courses RA 303 PB 321 CC 326 DG 401 AK 421

Converting Matching to Network Flow s t

Finding edge disjoint paths Construct a maximum cardinality set of edge disjoint paths

Theorem The maximum number of edge disjoint paths equals the minimum number of edges whose removal separates s from t

Finding vertex disjoint paths Construct a maximum cardinality set of vertiex disjoint paths

Network flow with vertex capacities

Balanced allocation Problem 9, Page 419 To make a long story short: N injured people K hospitals Assign each person to a hospital with 30 minutes drive Assign N/K patients to each hospital

Baseball elimination Can the Dinosaurs win the league? Remaining games: AB, AC, AD, AD, AD, BC, BC, BC, BD, CD W L Ants 4 2 Bees Cockroaches 3 Dinosaurs 1 5 A team wins the league if it has strictly more wins than any other team at the end of the season A team ties for first place if no team has more wins, and there is some other team with the same number of wins

Baseball elimination Can the Fruit Flies win or tie the league? Remaining games: AC, AD, AD, AD, AF, BC, BC, BC, BC, BC, BD, BE, BE, BE, BE, BF, CE, CE, CE, CF, CF, DE, DF, EF, EF W L Ants 17 12 Bees 16 7 Cockroaches Dinosaurs 14 13 Earthworms 10 Fruit Flies 15

Assume Fruit Flies win remaining games Fruit Flies are tied for first place if no team wins more than 19 games Allowable wins Ants (2) Bees (3) Cockroaches (3) Dinosaurs (5) Earthworms (5) 18 games to play AC, AD, AD, AD, BC, BC, BC, BC, BC, BD, BE, BE, BE, BE, CE, CE, CE, DE W L Ants 17 13 Bees 16 8 Cockroaches 9 Dinosaurs 14 Earthworms 12 Fruit Flies 19 15

Remaining games AC, AD, AD, AD, BC, BC, BC, BC, BC, BD, BE, BE, BE, BE, CE, CE, CE, DE s AC AD BC BD BE CE DE E A B C D T

Solving problems with a minimum cut Image Segmentation Open Pit Mining / Task Selection Problem S, T is a cut if S, T is a partition of the vertices with s in S and t in T The capacity of an S, T cut is the sum of the capacities of all edges going from S to T

Image Segmentation Separate foreground from background Reduction to min-cut problem S, T is a cut if S, T is a partition of the vertices with s in S and t in T The capacity of an S, T cut is the sum of the capacities of all edges going from S to T

Image analysis ai: value of assigning pixel i to the foreground bi: value of assigning pixel i to the background pij: penalty for assigning i to the foreground, j to the background or vice versa A: foreground, B: background Q(A,B) = S{i in A}ai + S{j in B}bj - S{(i,j) in E, i in A, j in B}pij

Pixel graph to flow graph s t

Mincut Construction s av pvu u v puv bv t

Open Pit Mining

Application of Min-cut Open Pit Mining Problem Task Selection Problem Reduction to Min Cut problem S, T is a cut if S, T is a partition of the vertices with s in S and t in T The capacity of an S, T cut is the sum of the capacities of all edges going from S to T

Open Pit Mining Each unit of earth has a profit (possibly negative) Getting to the ore below the surface requires removing the dirt above Test drilling gives reasonable estimates of costs Plan an optimal mining operation

Mine Graph -4 -3 -2 -1 -1 -3 3 -1 4 -7 -10 -2 8 3 -10

Determine an optimal mine -5 -3 -4 -4 2 -4 3 -1 -7 -10 -1 -3 -3 3 4 4 -3 -10 -10 -10 4 7 -2 -10 3 -10 -10 -10 -10 6 8 6 -3 -10 -10 -10 -10 -10 -10 1 4 4 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10

Generalization Precedence graph G=(V,E) Each v in V has a profit p(v) A set F if feasible if when w in F, and (v,w) in E, then v in F. Find a feasible set to maximize the profit -4 6 -2 -3 5 -1 -10 4

Min cut algorithm for profit maximization Construct a flow graph where the minimum cut identifies a feasible set that maximizes profit

Precedence graph construction Precedence graph G=(V,E) Each edge in E has infinite capacity Add vertices s, t Each vertex in V is attached to s and t with finite capacity edges

Show a finite value cut with at least two vertices on each side of the cut Infinite Finite t

The sink side of a finite cut is a feasible set No edges permitted from S to T If a vertex is in T, all of its ancestors are in T

Setting the costs If p(v) > 0, If p(v) < 0 If p(v) = 0 cap(v,t) = p(v) cap(s,v) = 0 If p(v) < 0 cap(s,v) = -p(v) cap(v,t) = 0 If p(v) = 0 3 3 1 1 -3 -1 -3 3 2 1 2 3 t

Enumerate all finite s,t cuts and show their capacities 2 2 -2 1 2 -2 1 1 2 1 t

Minimum cut gives optimal solution Why? 2 2 -2 1 2 -2 1 1 2 1 t

Computing the Profit Cost(W) = S{w in W; p(w) < 0}-p(w) Benefit(W) = S{w in W; p(w) > 0} p(w) Profit(W) = Benefit(W) – Cost(W) Maximum cost and benefit C = Cost(V) B = Benefit(V)

Express Cap(S,T) in terms of B, C, Cost(T), Benefit(T), and Profit(T) Cap(S,T) = Cost(T) + Ben(S) = Cost(T) + Ben(S) + Ben(T) – Ben(T) = B + Cost(T) – Ben(T) = B – Profit(T)

Summary Construct flow graph Finite cut gives a feasible set of tasks Infinite capacity for precedence edges Capacities to source/sink based on cost/benefit Finite cut gives a feasible set of tasks Minimizing the cut corresponds to maximizing the profit Find minimum cut with a network flow algorithm