Algorithms: COMP3121/3821/9101/9801

Similar documents
Flow Network. The following figure shows an example of a flow network:

1 Review for Lecture 2 MaxFlow

Lecture 2: Network Flows 1

CMPSCI 611: Advanced Algorithms

10 Max-Flow Min-Cut Flows and Capacitated Graphs 10 MAX-FLOW MIN-CUT

Algorithms and Theory of Computation. Lecture 11: Network Flow

Running Time. Assumption. All capacities are integers between 1 and C.

The min cost flow problem Course notes for Search and Optimization Spring 2004

The min cost flow problem Course notes for Optimization Spring 2007

6.046 Recitation 11 Handout

Maximum Flow. Jie Wang. University of Massachusetts Lowell Department of Computer Science. J. Wang (UMass Lowell) Maximum Flow 1 / 27

Algorithm Design and Analysis

Types of Networks. Internet Telephone Cell Highways Rail Electrical Power Water Sewer Gas

Agenda. Soviet Rail Network, We ve done Greedy Method Divide and Conquer Dynamic Programming

Internet Routing Example

We say that a flow is feasible for G (or just feasible if the graph and capacity function in question are obvious) if

The max flow problem. Ford-Fulkerson method. A cut. Lemma Corollary Max Flow Min Cut Theorem. Max Flow Min Cut Theorem

Algorithm Design and Analysis

Algorithms: Lecture 12. Chalmers University of Technology

directed weighted graphs as flow networks the Ford-Fulkerson algorithm termination and running time

Flows and Cuts. 1 Concepts. CS 787: Advanced Algorithms. Instructor: Dieter van Melkebeek

Two Applications of Maximum Flow

5 Flows and cuts in digraphs

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

CSE 326: Data Structures Network Flow. James Fogarty Autumn 2007

Mathematics for Decision Making: An Introduction. Lecture 13

CSC 373: Algorithm Design and Analysis Lecture 12

Problem set 1. (c) Is the Ford-Fulkerson algorithm guaranteed to produce an acyclic maximum flow?

Maximum Flow. Reading: CLRS Chapter 26. CSE 6331 Algorithms Steve Lai

Network Flows made simple

Maximum Flow Problem (Ford and Fulkerson, 1956)

CSCE423/823. Introduction. Flow Networks. Ford-Fulkerson Method. Edmonds-Karp Algorithm. Maximum Bipartite Matching 2/35 CSCE423/823.

CS 1501 Recitation. Xiang Xiao

Max Flow: Algorithms and Applications

22 Max-Flow Algorithms

The maximum flow problem

CS 170 DISCUSSION 10 MAXIMUM FLOW. Raymond Chan raychan3.github.io/cs170/fa17.html UC Berkeley Fall 17

Graph Algorithms -2: Flow Networks. N. H. N. D. de Silva Dept. of Computer Science & Eng University of Moratuwa

7.5 Bipartite Matching

Exposition of the Dinitz algorithm

Chapter 7. Network Flow. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Algorithm Design and Analysis

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

Flows. Chapter Circulations

Lecture 8 Network Optimization Algorithms

Basics on the Graphcut Algorithm. Application for the Computation of the Mode of the Ising Model

CS 138b Computer Algorithm Homework #14. Ling Li, February 23, Construct the level graph

Undirected Graphs. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { 1-2, 1-3, 2-3, 2-4, 2-5, 3-5, 3-7, 3-8, 4-5, 5-6 } n = 8 m = 11

Maximum flow problem

. CS711008Z Algorithm Design and Analysis. Lecture 10. Algorithm design technique: Network flow and its applications 1. Dongbo Bu

Algorithms: COMP3121/3821/9101/9801

p 3 p 2 p 4 q 2 q 7 q 1 q 3 q 6 q 5

CSC Design and Analysis of Algorithms. LP Shader Electronics Example

Parallel Graph Algorithms (con4nued)

Lecture 1. 1 Overview. 2 Maximum Flow. COMPSCI 532: Design and Analysis of Algorithms August 26, 2015

Network Flows. CTU FEE Department of control engineering. March 28, 2017

Discrete Optimization 2010 Lecture 3 Maximum Flows

Soviet Rail Network, 1955

(1,3) (3,4) (2,2) (1,2) (2,4) t

6. Linear Programming

Algorithm Theory - Exercise Class

Parallel Graph Algorithms (con4nued)

Introduction to Graph Theory

10.3 Matroids and approximation

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

Maximum flow problem (part I)

2.13 Maximum flow with a strictly positive initial feasible flow

COMP3121/9101/3821/9801 Lecture Notes. Linear Programming

Breadth-First Search of Graphs

Notes on Graph Theory

IS 709/809: Computational Methods in IS Research Fall Exam Review

Network Augmentation and the Multigraph Conjecture

Maximum Integer Flows in Directed Planar Graphs with Multiple Sources and Sinks and Vertex Capacities

Energy minimization via graph-cuts

1 Matchings in Non-Bipartite Graphs

Lecture 18: More NP-Complete Problems

NP-Hardness reductions

2. A vertex in G is central if its greatest distance from any other vertex is as small as possible. This distance is the radius of G.

The Simplest and Smallest Network on Which the Ford-Fulkerson Maximum Flow Procedure May Fail to Terminate

Bipartite Subgraphs of Integer Weighted Graphs

FINAL EXAM PRACTICE PROBLEMS CMSC 451 (Spring 2016)

CSE 202 Homework 4 Matthias Springer, A

Contents. Introduction

Standard Diraphs the (unique) digraph with no vertices or edges. (modulo n) for every 1 i n A digraph whose underlying graph is a complete graph.

Lecture 2: Just married

List of Theorems. Mat 416, Introduction to Graph Theory. Theorem 1 The numbers R(p, q) exist and for p, q 2,

Review Questions, Final Exam

Algorithm Design and Analysis

Design and Analysis of Algorithms

Chapter 9: Relations Relations

Combinatorial Optimization

Maximum flow problem CE 377K. February 26, 2015

1 Perfect Matching and Matching Polytopes

Multi-coloring and Mycielski s construction

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

Earliest Arrival Flows with Multiple Sources. Imran Rauf

Graphs and Network Flows IE411. Lecture 12. Dr. Ted Ralphs

Lecture 21 November 11, 2014

The partial inverse minimum cut problem with L 1 -norm is strongly NP-hard. Elisabeth Gassner

Transcription:

NEW SOUTH WALES Algorithms: COMP32/382/90/980 Aleks Ignjatović School of Computer Science and Engineering University of New South Wales LECTURE 7: MAXIMUM FLOW COMP32/382/90/980 / 24

Flow Networks A flow network G = (V, E) is a directed graph in which each edge e = (u, v) E has a non-negative capacity c(u, v) 0. There are two distinguished vertices: a source s and a sink t. A flow in G is a real valued non-negative function f : E R +, f(u, v) 0, which satisfies Capacity constraint: for all edges e(u, v) E we require f(u, v) c(u, v). 2 Flow conservation: For all v V {s, t} we require f(u, v) = f(v, w). (u,v) E (v,w) E COMP32/382/90/980 2 / 24

Flow Networks The value of the flow is defined as f = v V f(s, v). Clearly, also f = v V f(v, t). Example of a flow network with some network flow in it: first number on an edge: flow through that edge; second number: the capacity of the edge. COMP32/382/90/980 3 / 24

Flow Networks Example of flow networks (possibly with several sources and many sinks): transportation networks, gas pipelines, computer networks... The residual flow network for a flow network with some flow in it: the network with the leftover capacities each edge of the original network has a leftover capacity for more flow equal to the capacity of the edge minus the flow through the edge; if the flow through an edge is equal to the capacity of the edge, this edge disappears in the residual network; new virtual edges appear in opposite direction of an original edge with some flow in it; they represent the possibility to reduce the flow through the original edge; thus their capacity is equal to the flow through the original edge. COMP32/382/90/980 4 / 24

Flow Networks Residual flow networks can be used to increase the total flow through the network by adding an augmenting path The capacity of an augmenting path is the capacity of its bottleneck edge, i.e. the capacity of the smallest capacity edge on that path. We can now recalculate the flow through all edges along the augmenting path by adding the additional flow through the path if the flow through the augmenting path is in the same direction as the original flow, and subtracting if in opposite direction: COMP32/382/90/980 5 / 24

Ford Fulkerson method for finding maximal flow Ford - Fulkerson algorithm for finding maximal flow in a flow network: Keep adding flow through new augmenting paths for as long as it is possible; When there are no more augmenting paths, you have achieved the largest possible flow in the network. Example: COMP32/382/90/980 6 / 24

Ford - Fulkerson method for finding maximal flow COMP32/382/90/980 7 / 24

Ford - Fulkerson method for finding maximal flow Ford Fulkerson algorithm for finding maximal flow in a flow network: Keep adding flow through new augmenting paths for as long as it is possible; When there are no more augmenting paths, you have achieved the largest possible flow in the network. Why does this procedure terminate? Why cant we get stuck in a loop, which keeps adding augmenting paths forever? If all the capacities are integers, then each augmenting path increases the flow through the network for at least unit; the total flow cannot be larger than the sum of all capacities of all edges, so eventually the process must terminate. COMP32/382/90/980 8 / 24

Ford - Fulkerson method for finding maximal flow Even if the procedure does terminate, why does it produce a flow of the largest possible value? Maybe we have created bottlenecks by choosing bad augmenting paths; maybe better choices of augmenting paths could produce a larger total flow through the network? This is not at all obvious, and to show that this is not the case we need a mathematical proof! The proof is based on the notion of a minimal cut in a flow network: A cut in a flow network is any partition of the vertices of the underlying graph into two subsets S and T such that: S T = V 2 S T = 3 s S and t T. COMP32/382/90/980 9 / 24

Cuts in flow networks The capacity c(s, T ) of a cut (S, T ) is the sum of capacities of all edges whose left end is in S and the right end in T, i.e. c(s, T ) = (u,v) E {c(u, v) : u S & v T } Note that the capacities of edges going in the opposite direction, i.e., from T to S do not count. The flow through a cut f(s, T ) is the total flow through edges from S to T minus the total flow through edges from T to S: f(s, T ) = (u,v) E {f(u, v) : u S & v T } (u,v) E {f(u, v) : u T & v S} Clearly, f(s, T ) c(s, T ) because for every edge (u, v) E we assumed f(u, v) c(u, v), and f(u, v) 0. COMP32/382/90/980 0 / 24

Cuts in flow networks Example: In the above example the net flow across the cut is given by f(s, T ) = f(v, v 3) + f(v 2, v 4) f(v 2, v 3) = 2 + 4 = 9 Note that the flow in the opposite direction (from T to S) is subtracted. The capacity of the cut c(s, T ) is given by c(s, T ) = c(v, v 3) + c(v 2, v 4). Note that we add only the capacities of vertices from S to T and not of vertices in the opposite direction. COMP32/382/90/980 / 24

Cuts in flow networks Theorem: The maximal amount of flow in a flow network is equal to the capacity of the cut of minimal capacity. Since any flow has to cross every cut, any flow must be smaller than the capacity of any cut: f = f(s, T ) c(s, T ). Thus, if we find a flow f which equals the capacity of some cut (S, T ), then such flow must be maximal and the capacity of such a cut must be minimal. capacities of network cuts network flows maximal flow = minimal cut capacity We now show that when the Ford - Fulkerson algorithm terminates, it produces a flow equal to the capacity of an appropriately defined cut. COMP32/382/90/980 2 / 24

Cuts in flow networks Assume that the Ford - Fulkerson algorithm has terminated and that there no more augmenting paths from the source s to the sink t in the last residual network flow. Define S to be the source s and all vertices u such that there is a path in the residual network flow from the source s to that vertex u. Define T to be the set of all vertices for which thee is no such path. Since there are no more augmenting paths from s to t, clearly the sink t belongs to T. COMP32/382/90/980 3 / 24

Cuts in flow networks Claim: all the edges from S to T are fully occupied with flow, and all the edges from T to S are empty. S 3/5 v T u 2 s t x 6/9 6 y Proof: If an edge (u, v) from S to T had some additional capacity left, then in the residual flow network the path from s to u could be extended to a path from s to v which contradict our assumption that v T. If and edge (y, x) from T to S had any flow in it, then in the residual flow network the path from s to x could be extended to a path from x to y, which is again a contradiction with our assumption that y T. COMP32/382/90/980 4 / 24

Cuts in flow networks Since all edges from S to T are occupied with flows to their full capacity and since there is no flow from T to S, the flow across the cut (S, T ) is precisely equal to the capacity of this cut. Thus, such a flow is maximal and the corresponding cut is a minimal cut, regardless of the particular way how the augmenting paths were chosen. Trying to do the Ford Fulkerson algorithm without constructing the residual flow can make you miss augmenting paths: Importance of making residual network flow u u s t s t v v COMP32/382/90/980 5 / 24

Cuts in flow networks How efficient is the Ford-Fulkerson algorithm? s 000 000 t s 000 000 t 000 000 000 000 /000 000 999 000 s 000 / /000 t s 000 999 t /000 /000 999 999 COMP32/382/90/980 6 / 24

Cuts in flow 000 networks /000 000 999 /000 /000 999 999 s /000 0/ t s /000 999 999 2/000 /000 s / t /000 2/000 The Ford-Fulkerson algorithm can potentially run in time proportional to the value of max flow, which can be exponential in the size of the input. COMP32/382/90/980 7 / 24

Edmonds-Karp Max Flow Algorithm The Ford-Fulkerson algorithm can potentially run in time proportional to the value of max flow, which can be exponential in the size of the input. The Edmonds-Karp algorithm improves the Ford Fulkerson algorithm in a simple way: always choose the shortest path from the source s to the sink t, where the shortest path means the fewest number of edges, regarding of their capacities (i.e., each edge has the same unit weight). Note that this choice is somewhat counter intuitive: we preferably take edges with small capacities over edges with large capacities, for as long as they are along the shortest path from s to t. Why does such a choice speed up the Ford - Fulkerson algorithm? To see this, one needs a tricky mathematical proof, see the textbook. One can prove that such algorithm runs in time O( V E 2 ) time. COMP32/382/90/980 8 / 24

Networks with multiple sources and sinks Flow networks with multiple sources and sinks are reducible to networks with a single source and single sink by adding a super-sink and super-source and connecting them to all sources and sinks, respectively, by edges of infinite capacities. S t Super source S2 t2 Super sink Sn tn COMP32/382/90/980 9 / 24

Maximum matching in bipartite graphs We turn a Maximum Matching problem into a Max Flow problem by adding a super source and a super sink, and by giving all existing edges a capacity of A matching in a graph G is a subset M of all edges E such that each vertex of the graph belongs to at most one of the edges in the matching M. S T COMP32/382/90/980 2 / 24

Maximum matching in bipartite graphs Note how the residual flow network allows rerouting the flow in order to increase the total throughput. COMP32/382/90/980 23 / 24

Other application of Max Flow algorithms Assume you have a movie rental agency. At the moment you have k movies in stock, with m i copies of movie i. Each of n customers can rent out at most 5 movies at a time. The customers fave sent you their preferences which a list of movies they would like to see. Your goal is to dispatch the largest possible number of movies. m 5 5 5 U U2 U3 m2 m3 m4 U4 mi 5 Un mk COMP32/382/90/980 24 / 24