Network Flow Analysis of Algorithms.

Slides:



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

COMP 482: Design and Analysis of Algorithms
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.
Lecture 5: Network Flow Algorithms Max-Flow Min-Cut Single-Source Shortest-Path (SSSP) Job Sequencing.
Max Flow Problem Given network N=(V,A), two nodes s,t of V, and capacities on the arcs: uij is the capacity on arc (i,j). Find non-negative flow fij for.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
CSE 421 Algorithms Richard Anderson Lecture 23 Network Flow 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)
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 19.
CSCI 256 Data Structures and Algorithm Analysis Lecture 18 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
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.
Advanced Algorithms Piyush Kumar (Lecture 2: Max Flows) Welcome to COT5405 Slides based on Kevin Wayne’s slides.
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.
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.
Flows sourcesink s t Flows sourcesink edge-weights = capacities.
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.
CSEP 521 Applied Algorithms
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.
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.
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.
Maximum Flow Chapter 26. Flow Concepts Source vertex s – where material is produced Sink vertex t – where material is consumed For all other vertices.
Chapter 7 April 28 Network Flow.
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.
Data Structures & Algorithms Network Flow Richard Newman based on book by R. Sedgewick.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 23.
CSEP 521 Applied Algorithms Richard Anderson Lecture 8 Network Flow.
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.
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)
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 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.
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
Chapter 7 Network Flow Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Flow Networks Topics Flow Networks Residual networks
Flow Networks General Characteristics Applications
Algorithms (2IL15) – Lecture 7
EE5900 Advanced Embedded System For Smart Infrastructure
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
Lecture 22 Network Flow, Part 2
Presentation transcript:

Network Flow Analysis of Algorithms

Network Flow A flow network is a directed graph in which each directed edge (u,v) has a positive capacity c(u,v) > 0 – Capacity is the maximum rate of flow that any edge can carry Two special nodes: source, s, and target, t

Network Flow Flow is the rate at which material moves from the source to the target For example, liquid through pipes, electrical current through a circuit, data through a network, or many other types of information The value of flow f is defined to be the total flow leaving the source vertex Can be positive, negative, or zero f is also the value of the in-flow at the target

Network Flow A flow network is a directed graph with a source vertex s, a target vertex t, and every edge labeled with a positive capacity, c Initial network with capacities on the edges. No flow yet.

Network Flow A flow is then induced at the source At every vertex except s and t, the inflow must be equal to the outflow at that vertex

Network Flow Every flow must satisfy the following 3 properties: 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}, vV f(u,v) = 0 The maxflow problem: given a directed graph (network) with a capacity on each edge, find a flow of maximum value

Ford-Fulkerson Algorithm Ford-Fulkerson is a greedy, iterative method for solving the maxflow problem: Initially, flow = 0 for all u,v  V At each stage, an augmenting path is found An augmenting path is a path from s to t for which we can push more flow Repeat until no more augmenting paths can be found

Ford-Fulkerson Algorithm The residual network Consider a flow network (G,c) together with a flow f Define a new flow network (Gf,cf), where Gf has the same node set as G, and cf(u,v) = c(u,v) - f(u,v) – The capacities of Gf are the unused capacities of G Gf is called the residual network, cf is called the residual capacity If we can find an additional flow f’(u,v) in Gf, then we can define f*(u,v) to be the current total flow in the network G, where f*(u,v) = f(u,v) + f’(u,v)

Ford-Fulkerson Algorithm The “leftover” capacity in the original network with flow f creates an augmenting path available for more flow (the residual network) When the capacity of an edge is used up, we can reverse the direction of the edge to allow data to flow in the opposite direction.

Ford-Fulkerson Algorithm The residual capacity cf = the capacity that is left over after a flow has “run” along an edge The bottleneck capacity b = the minimum residual capacity of the edges along the augmenting path b = min { cf(u,v): (u,v) is on path p }

Ford-Fulkerson Algorithm Initialize: Start with a flow of 0 on each edge Repeat: Push more flow along an augmenting path until a maximum flow has been found

Ford-Fulkerson Algorithm An augmenting path is any undirected path from s to t such that either: Flow can be increased along a forward edge (an edge with capacity that is not full) or Flow can be decreased along a backward edge (a reversed edge with a flow that is not zero) Send 10 units of flow from s to t.

Ford-Fulkerson Algorithm Send 10 units of flow from s to t. Send 5 units of flow from s to t.

Ford-Fulkerson Algorithm Send 3 units of flow from s to t. Terminate when all paths from s to t are blocked by either a full forward edge or an empty backward edge

Ford-Fulkerson Algorithm Question: In the flow network shown below, how many different augmenting paths are there with respect to the given flow f ? 1 0/4 3 10/10 8/8 6/10 2/2 6/6 s 2 4 t 6/10 8/9 10/10

Ford-Fulkerson Algorithm When the capacities are integers, Ford-Fulkerson runs in time proportional to the number of edges in the graph times the maximum flow in the graph.

Analysis of Ford-Fulkerson How do you choose an augmenting path? Will any sequence of paths do just as well? Consider the following flow network: u u u 1,000,000 s 1,000,000 999,999 999,999 999,999 s 1,000,000 1,000,000 1 1 1 999,999 1 t 1,000,000 1 1 s t t 999,999 999,999 1 v 1 1 v v Two augmenting paths with bottleneck capacities of 1, and resulting residual network. Running time is proportional to E  f, where f is the value of the maximum flow; for this example, f = 2,000,000.

Improvements to Ford-Fulkerson Edmunds and Karp suggested two heuristics for improving performance by selecting better augmenting paths Always augment by a path of maximum bottleneck capacity (the fattest path) or Always augment by a path with the fewest number of edges (the shortest path)

Is Ford-Fulkerson Optimal? Since Ford-Fulkerson is a greedy method, how do we know if we have found the optimal (maximum) flow? Consider: A flow is maximum if and only if its residual network contains no augmenting paths There will be no more augmenting paths when all the bottleneck capacities have been used up The bottleneck capacities are found from the minimum cut of the network

Network Cuts Definition: A cut is a partition of the vertices into two disjoint sets, A and B An st-cut is a cut where the source s is in A and the sink t is in B A B s t

Network Cuts The capacity of a cut is the sum of the capacities of the edges from A to B In the example below, A = {s} and B = {all other vertices}

Network Cuts In this example, A = {the dark-colored vertices} and B = {the light-colored vertices} – Only include the edges from A to B when determining the capacity across the cut; do not include the edges from B to A or from A to A

Network Cuts Question: In the flow network shown here, what is the capacity of the cut with A = {s,2,4} and B = {1,3,t}? 4 1 3 8 10 10 2 6 s 2 4 t 10 9 10 Mincut problem: For all possible ways to cut a graph with s  A and t  B, find the cut of minimum capacity.

Flows and Cuts The net flow across a cut (A, B) is the sum of the flows on its edges from A (gray vertices) to B (white vertices) minus the sum of the flows on its edges from B to A Flow-value lemma: Let f be any flow and let (A, B) be any cut. Then, the net flow across (A, B) equals the value of f. In other words, every cut must have the same net flow!

Maxflow-Mincut Theorem According to the flow-value lemma, the net flow is the same across all s-t cuts, including the minimum s-t cut – If you send as much flow as you possibly can (the maximum flow), then the capacities of the minimum cut will be saturated and you cannot send more flow Therefore, the maximum flow = minimum cut

Maxflow-Mincut Theorem Proof: Suppose (A, B) is a cut such that vertex u  A We can move u to B without altering the flow because of the conservation of flow (flow in = flow out), thus f(A, B) = f(A - {u}, B + {u}) Therefore, every flow (even the maximum flow) is the same regardless of where you cut (even the minimum cut) A A-{u} w w 4 4 w3 w2 w1 w3 w2 = u w w u 5 5 B B+{u} s s w1 t t

Flow Equivalence Conditions The following three conditions are equivalent for any flow f: There exists a cut whose capacity equals the value of the flow f Flow f is a maxflow There is no augmenting path with respect to f

Flow Equivalence Conditions There exists a cut whose capacity equals the value of the flow f Flow f is a maxflow 1 implies 2: Suppose that (A, B) is a cut with capacity equal to the value of f Then, the value of any other flow f ' ≤ capacity of cut(A, B) = value of f (by assumption on 1 above) Thus, f is a maxflow

Flow Equivalence Conditions Flow f is a maxflow There is no augmenting path with respect to f 2 implies 3 using the contrapositive (3 implies 2): Suppose that there is another augmenting path with respect to the current flow f We could send more flow along this path Thus, the current flow f is not a maxflow

Flow Equivalence Conditions 3. There is no augmenting path with respect to f 1. There exists a cut whose capacity equals the value of the flow f 3 implies 1: If there is no augmenting path with respect to f (i.e., if there is no path from s to t where we could send more flow), then this creates a cut The capacity of this cut defines the bottleneck, and has flow with value f (from the flow-value lemma)

Applications of Network Flow Data mining Open-pit mining Bipartite matching Network reliability Baseball elimination Image segmentation Network connectivity Distributed computing Security of statistical data Egalitarian stable matching Multi-camera scene reconstruction Sensor placement for homeland security Many, many, more

Edge-Disjoint Paths A set of paths is edge-disjoint if their edge sets are disjoint, i.e., no two paths share an edge – Multiple paths may go through some of the nodes The Edge-Disjoint Paths Problem is to find the maximum number of edge-disjoint s-t paths in G The maximum number of edge-disjoint s-t paths is equal to the minimum number of edges whose removal separates s from t

Edge-Disjoint Paths The Ford-Fulkerson algorithm can be used to find a maximum set of edge-disjoint s-t paths in runtime proportional to VE Given a graph G = (V,E) with source s and sink t, create a flow network with a capacity of 1 on each edge s t Maximum number of edge-disjoint paths = 3

Maximum Bipartite Matching The assignment/matching/marriage problem Goal: Find a maximum bipartite match Example: match L machines with R tasks to be performed Example: match L applicants to R job offers Edge (x,y) represents “applicant x wants job y” and “company y wants applicant x” The goal is to make the maximum number of matches of student to jobs Multiple acceptance is forbidden!

Maximum Bipartite Matching X Y X Y A bipartite graph. On the left is a match with cardinality 2, and on the right is a match with cardinality 3. The match on the right is optimal because 3 > 2.

Maximum Bipartite Matching To find a maximum bipartite matching: construct a flow network, where a flow correspond to a match Construct a flow network G’ Set all weights to 1 (initial capacities) Run Ford-Fulkerson Maximum bipartite matching = maximum flow Runtime is proportional to VE

Maximum Bipartite Matching  s t X Y X Y The corresponding flow network G with maximum flow shown. Each edge in G has capacity of 1. Shaded edges have a flow of 1, and all other edges carry no flow. The shaded edges from X to Y correspond to those in a maximum matching of the bipartite graph.

Baseball Elimination Four baseball teams are trying to finish in first place. Currently, each team has the following number of wins: New York: 92 Baltimore: 91 Toronto: 91 Boston: 90 There are five games left in the season; these consist of all possible pairings of the four teams, except for New York and Boston. Can Boston finish in first place, or at least tie for first?

Baseball Elimination New York: 92 Baltimore: 91 Toronto: 91 Boston: 90 Boston can finish with at most 92 wins. Cumulatively, the other three teams have 274 wins currently, and their three games against each other will produce exactly three more wins, for a final total of 277. But 277 wins divided by three teams means that one of them must end up with more than 92 wins. Therefore, Boston cannot end up in first place, or even tie for first.

Baseball Elimination Suppose each team has the following number of wins: New York: 90 Baltimore: 88 Toronto: 87 Boston: 79 The remaining games are as follows: Boston still has four games against each of the other three teams. Baltimore has one more game against each of New York and Toronto. New York and Toronto still have six games left to play against each other. Is Boston eliminated?

Baseball Elimination New York: 90 Baltimore: 88 Toronto: 87 Boston: 79 Boston can end with at most 91 wins. Together, New York and Toronto already have 177 wins; their six remaining games will result in a total of 183, and since 183/2 > 91, one of them must end up with more than 91 wins. Therefore, Boston is eliminated. Interestingly, in this instance, we cannot prove that Boston is eliminated by averaging all three teams. The three teams ahead of Boston together have a total of 265 wins with 8 games left among them. This is a total of 273, and 273/3 = 91. Averaging over all three teams does not prove that Boston could not tie for first. You must be careful to choose the correct set!

Baseball Elimination In general, suppose we have a set S of teams, and for each x  S, its current number of wins is wx. Also, for two teams x, y  S, they still have to play gxy games against each other. We also have a specific team z, for which we want to know the best outcome. Let’s suppose that z requires m wins total to end up in first place. Let S = S – {z}, and let g* = the total number of games left between all pairs of teams in S. Now construct a flow network G to determine whether z has been eliminated: include nodes s and t, a vertex uxy for each pair of teams x, y  S with a non-zero number of games left to play against each other, and a node vx for each team x  S.

Baseball Elimination Include the following edges: (s, uxy) with capacity gxy (uxy, vx) and (uxy, vy) with capacities gxy (vx, t) with capacity m - wx If there is a flow of value at least g*, then it is possible for the outcomes of all remaining games to yield a situation where no team has more than m wins. Hence, if team z wins all its remaining games, it can still achieve at least a tie for first place. Team z has been eliminated if and only if the maximum flow in G has value strictly less than g*.

Baseball Elimination wNewYork wBaltimore = 88 wToronto wBoston = 90 NY-Tor NY wBaltimore = 88 6 wToronto wBoston = 87 = 79 91 - 90 = 1 6 1 Tor 91 - 87 = 4 t NY-Balt 1 s gNY-Tor = 6 gNY-Bal = 1 gBal-Tor = 1 Boston has 12 games left, so m = 91 1 1 Balt-Tor Balt 91 - 88 = 3 1 The maximum flow has value = 7, whereas g* = 6 + 1 + 1 = 8 (g* is the total number of games left between teams in S). Since max flow < g*, Boston cannot at least tie for first place.

Baseball Elimination QUESTION: How many vertices and edges, respectively, are there in a flow network that is constructed to determine whether one team is mathematically eliminated from a baseball league containing N teams? Assume the worst case (when there is a game remaining between every pair of teams in the league). N and N2 N2 and N2 N2 and N3 N2 and N4

Network Flow Holy Grail Worst-case analysis is generally not useful for predicting or comparing maxflow algorithm performance in practice Current best in practice: Push-relabel method with gap relabeling runs in time proportional to E3/2

Network Flow Holy Grail Year Method Worst Case Discovered By 1951 Simplex E3 C Dantzig 1955 Augmenting path E C* Ford-Fulkerson 1970 Shortest augmenting path E3 Dinitz and Edmonds-Karp Fattest augmenting path E2 log E log(E C) 1977 Blocking flow E5/2 Cherkasky 1978 E7/3 Galil 1983 Dynamic trees E2 log E Sleator and Tarjan 1985 Capacity scaling E2 log C Gabow 1997 Length function E1/2 log E log C Goldberg and Rao 2012 Compact network E2 / log E Orlin ? E