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

Similar documents
1 Review for Lecture 2 MaxFlow

CMPSCI 611: Advanced Algorithms

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

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

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

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

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

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

Lecture 2: Network Flows 1

Algorithms and Theory of Computation. Lecture 11: Network Flow

Algorithms: COMP3121/3821/9101/9801

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

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

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

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

6.046 Recitation 11 Handout

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

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

Discrete Optimization 2010 Lecture 3 Maximum Flows

Algorithm Design and Analysis

CSC 373: Algorithm Design and Analysis Lecture 12

Linear Programming. Jie Wang. University of Massachusetts Lowell Department of Computer Science. J. Wang (UMass Lowell) Linear Programming 1 / 47

Maximum flow problem

Mathematics for Decision Making: An Introduction. Lecture 13

Internet Routing Example

Exposition of the Dinitz algorithm

Max Flow: Algorithms and Applications

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)}

Network Flows made simple

7.5 Bipartite Matching

CS 1501 Recitation. Xiang Xiao

Two Applications of Maximum Flow

Lecture 8 Network Optimization Algorithms

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

Algorithm Design and Analysis

Maximum flow problem (part I)

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

Algorithms: Lecture 12. Chalmers University of Technology

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

CSE 202 Homework 4 Matthias Springer, A

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

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

Parallel Graph Algorithms (con4nued)

The min cost flow problem Course notes for Optimization Spring 2007

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

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

Algorithm Design and Analysis

CS675: Convex and Combinatorial Optimization Fall 2014 Combinatorial Problems as Linear Programs. Instructor: Shaddin Dughmi

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

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

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

Discrete Optimization Lecture 5. M. Pawan Kumar

Parallel Graph Algorithms (con4nued)

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

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

Soviet Rail Network, 1955

2.13 Maximum flow with a strictly positive initial feasible flow

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

5 Flows and cuts in digraphs

Flows. Chapter Circulations

Lecture 21 November 11, 2014

CS675: Convex and Combinatorial Optimization Fall 2016 Combinatorial Problems as Linear and Convex Programs. Instructor: Shaddin Dughmi

Lecture 10 September 27, 2016

Midterm Exam 2 Solutions

The maximum flow problem

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

CSC2420: Algorithm Design, Analysis and Theory Spring (or Winter for pessimists) 2017

Breadth-First Search of Graphs

8.5 Sequencing Problems

1 Matchings in Non-Bipartite Graphs

CS 598RM: Algorithmic Game Theory, Spring Practice Exam Solutions

CSC2420: Algorithm Design, Analysis and Theory Fall 2017

NP and Computational Intractability

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

Review Questions, Final Exam

NP and Computational Intractability

Lecture 3. 1 Polynomial-time algorithms for the maximum flow problem

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.

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Lecture 13 Spectral Graph Algorithms

Polynomial-Time Reductions

Network Flow Problems Luis Goddyn, Math 408

NP-Completeness. Algorithmique Fall semester 2011/12

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

CSC Design and Analysis of Algorithms. LP Shader Electronics Example

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

6. Linear Programming

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

GRAPH ALGORITHMS Week 7 (13 Nov - 18 Nov 2017)

Single Source Shortest Paths

ORIE 633 Network Flows October 4, Lecture 10

FFT: Fast Polynomial Multiplications

Graph Theory and Optimization Computational Complexity (in brief)

On shredders and vertex connectivity augmentation

Complexity Theory Part II

The Multiple Traveling Salesman Problem with Time Windows: Bounds for the Minimum Number of Vehicles

- Well-characterized problems, min-max relations, approximate certificates. - LP problems in the standard form, primal and dual linear programs

ACO Comprehensive Exam March 17 and 18, Computability, Complexity and Algorithms

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

Transcription:

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

Flow Networks A flow network is a weighted digraph G = (V, E), where the weight is called capacity, denoted by c, such that For all (u, v) E: c(u, v) 0. For (u, v) / E: c(u, v) = 0. If (u, v) E, then (v, u) / E. Flow networks do not allow antiparallel edges. That is, (u, v) and (v, u) cannot be both E. No self loops. G has one source node s V (note: s may have incoming edges). G has one sink node t V (note: t may have outgoing edges). Every node u V {s, t} is on a path from s to t. Note that for each node v V {s, t}, it s possible to have (s, v) E or (v, s) E, but not both. J. Wang (UMass Lowell) Maximum Flow 2 / 27

Flow Network Constraints A flow is a function f : V V R with the following constraints: Capacity constraint: For all u, v V : 0 f (u, v) c(u, v). Flow conservation: For all u V \ {s, t}, f (v, u) = f (u, v). If (u, v) / E, then f (u, v) = 0. The value of a flow, denoted by f, is defined as follows: f = f (s, v) f (v, s). Note: the second summation is 0; but we keep it here for later use when dealing with residual networks. J. Wang (UMass Lowell) Maximum Flow 3 / 27

Flow Network Example J. Wang (UMass Lowell) Maximum Flow 4 / 27

Maximum Flow Input: A flow network G = (V, E), a source s V, a sink t V, and a flow function f : V V R. Output: max f { f f is a flow of G from s to t} (namely, the value of the maximum flow in G). Network Flow Applications include Liquid flowing through pipes Parts through assembly lines Current through power grids Data through communication networks Maximum bipartite matching Minimum cuts J. Wang (UMass Lowell) Maximum Flow 5 / 27

Handling Multiple Sources and Sinks J. Wang (UMass Lowell) Maximum Flow 6 / 27

Ford-Fulkerson Method Residual networks. A residual network of (G, f ), denoted by G f = (V, E f ), is a flow network with positive residual capacity c f, where for each u, v V : c(u, v) f (u, v), if (u, v) E, c f (u, v) = f (v, u), if (v, u) E, 0, otherwise. Thus, E f = {(u, v) V V c f (u, v) > 0}. Augmenting paths. An augmenting path is a path from s to t in a residual network G f. The flow allowed on an augmenting path is the minimum residual capacity on the path, denoted by f. The augmentation of flow f by f, denoted by f f, is defined as follows: { f f f (u, v) + f (u, v) f (v, u), if (u, v) E, (u, v) = 0, otherwise. J. Wang (UMass Lowell) Maximum Flow 7 / 27

Residual Network and Augmenting Path Example J. Wang (UMass Lowell) Maximum Flow 8 / 27

Augmentation Satisfies Capacity Constraint Want to show for (u, v) E: 0 f f (u, v) c(u, v). Since (v, u) E and (u, v) E, c f (v, u) = f (u, v). Thus, f (v, u) c f (v, u) = f (u, v). Hence, for each (u, v) E: f f (u, v) = f (u, v) + f (u, v) f (v, u) f (u, v) + f (u, v) f (u, v) = f (u, v) 0. f f (u, v) = f (u, v) + f (u, v) f (v, u) f (u, v) + f (u, v) f (u, v) + c f (u, v) = f (u, v) + c(u, v) f (u, v) = c(u, v). J. Wang (UMass Lowell) Maximum Flow 9 / 27

Augmentation Satisfies Flow Conservation For each u V {s, t}: f f (u, v) = (f (u, v) + f (u, v) f (v, u)) = f (u, v) + f (u, v) f (v, u) = f (v, u) + f (v, u) f (u, v) = f f (v, u). J. Wang (UMass Lowell) Maximum Flow 10 / 27

Augmentation Increases Flow We want to compute the value of f f for the original network G. Recall that it s possible to have (s, v) E or (v, s) E, but not both. Let V 1 = {v (s, v) E}, V 2 = {v (v, s) E}. Then V 1 V 2 = and V 1 V 2 V. f f = f f (s, v) f f (v, s) = 1 f f (s, v) 2 f f (v, s) = (f (s, v) + f (s, v) f (v, s)) (f (v, s) + f (v, s) f (s, v)) 1 2 = f (s, v) f (v, s) + (f (s, v) f (v, s)) 1 2 1 V 2 = (f (s, v) f (v, s)) + (f (s, v) f (v, s)) = f + f. J. Wang (UMass Lowell) Maximum Flow 11 / 27

Ford-Fulkerson Method Continued 1 Initialize flow f to 0. 2 While there still exists an augmenting path p in the residual network G f, augment flow f along p. Ford-Fulkerson(G, s, t) 1 for each edge (u, v) E 2 f (u, v) = 0 3 while there is an augmenting path p from s to t in G f 4 c f (p) = min{c f (u, v) (u, v) p} 5 for each edge (u, v) p 6 if (u, v) G.E 7 (u, v).f = (u, v).f + c f (p) 8 else (v, u).f = (v, u).f c f (p) Every path from s to t is now at full capacity and thus a maximum flow is found. Will prove this result later. J. Wang (UMass Lowell) Maximum Flow 12 / 27

Ford-Fulkerson Method Example J. Wang (UMass Lowell) Maximum Flow 13 / 27

Ford-Fulkerson Method Example Continued J. Wang (UMass Lowell) Maximum Flow 14 / 27

Time Complexity of Ford-Fulkerson First, we need to use a data structure to store the network, which is a special graph G = (V, E ) with E = {(u, v) (u, v) E or (v, u) E}. Since all edges in G are also in G, the flows and capacities can be stored as attributes on the edges. We can use adjacency list representation for this purpose. The first for loop runs in Θ( E ) time. The while loop starts by finding an augmenting path. Let s assume that the capacity function is c : V V Z. If the maximum flow is f then the while loop runs at most f times, since the flow increases by at least one each time. The residual network for any flow f is part of G, for it is given by all the edges (u, v) E such that c f (u, v) > 0. We can either use BFS or DFS to find an augmenting path. Either one runs in time O( V + E ) if G is implemented using an adjacency list representation. J. Wang (UMass Lowell) Maximum Flow 15 / 27

Time Complexity of Ford-Fulkerson Continued The runtime using BFS or DFS is O( f ( V + E ) if the capacities are integrals. This is a pseudo-polynomial-time algorithm. In practice, capacities may be given as rational numbers. We can scale all the capacities to integrals. We can improve the runtime of Ford-Fulkerson to polynomial time using BFS to find the shortest augmented path from s to t. This implementation is called the Edmonds-Karp algorithm. The runtime of Edmonds-Karp algorithm is O( V E 2 ), independent of the value of the maximum flow. J. Wang (UMass Lowell) Maximum Flow 16 / 27

Proof of Edmonds-Karp Runtime Lemma 26.7. The shortest-path distance δ f (s, v) in G f increases monotonically with each flow augmentation, where v V {s, t}. Proof. By contradiction. Let f be the flow just before the first augmentation that decreases some shortest-path distance. Let f be the flow just afterward. Let v be the closest node to s on a shortest path p with δ f (s, v) > δ f (s, v). Let p = s u v be a shortest path from s to v in G f (u, v) E f, δ f (s, u) = δ f (s, v) 1. Because of how v is chosen, we have δ f (s, u) δ f (s, u). so that J. Wang (UMass Lowell) Maximum Flow 17 / 27

Proof Continued Claim: (u, v) E f. If (u, v) E f, then δ f (s, v) δ f (s, u) + 1 (by triangle inequality) δ f (s, u) + 1 = δ f (s, v), contradicting to the assumption that δ f (s, v) > δ f (s, v). To have (u, v) E f but (u, v) E f, the augmentation must increase the flow from v to u. Edmonds-Karp always augments flow along shortest paths. Thus, the shortest path from s u G f must have s v u. Hence, δ f (s, v) = δ f (s, u) 1 δ f (s, u) 1 = δ f (s, v) 2, Contradicting to the assumption that δ f (s, v) > δ f (s, v). This completes the proof. J. Wang (UMass Lowell) Maximum Flow 18 / 27

Complexity of Edmonds-Karp Theorem 26.8. Edmonds-Karp performs O( V E ) flow augmentations. Proof. An edge (u, v) G f is critical on an augmenting path p if c f (u, v) = min{c f (e) e is an edge of p}. Each edge e = (u, v) E can become critical at most V /2 times. A proof is presented below. When e is critical for the first time, we have δ f (s, v) = δ f (s, u) + 1. Once the flow is augmented, e disappears from E f. e cannot reappear until after (v, u) appears on an augmenting path. Let f be the flow when this happens. Then δ f (s, u) = δ f (s, v) + 1. Since δ f (s, v) δ f (s, v) (Lemma 26.7), we have δ f (s, u) δ f (s, v) + 1 = δ f (s, u) + 2. J. Wang (UMass Lowell) Maximum Flow 19 / 27

Proof Continued In a cycle that (u, v) becomes critical, the distance from s to u increases by at least 2. The distance from s to u is initially at least 0. The intermediate nodes on a shortest path from s to u cannot contain s, u, or t. The distance for any shortest path from s to u is at most V 2. Thus, after (u, v) becomes critical, it can become critical at most ( V 2)/2 = V /2 1 times more. (Reason: Let k be the number of times that it can become critical, then we must have 2k = V 2.) There are O( E ) edges in a residual network. The total number of critical edges is O( V E ). Each augmenting path has at least one critical edge. This completes the proof. J. Wang (UMass Lowell) Maximum Flow 20 / 27

Cuts The node V in a flow network can be partitioned into a cut (S, T ), where s S, t S, and T = V S. The capacity of a cut (S, T ) is defined by c(s, T ) = c(u, v). u S,v T Let (S, T ) be any cut of G and f a flow. Then the flow from S to T, denoted by f (S, T ), is always equal to f. f = f (s, v) f (v, s) + ( f (u, v) ) f (v, u) u V {s} = ( f (s, v) + ) f (u, v) ( f (v, s) + ) f (v, u) u S {s} u S {s} = f (u, v) f (v, u). u S u S J. Wang (UMass Lowell) Maximum Flow 21 / 27

Proof Continued Since V = S T and S T =, split each summation over V into summations over S and T to get f = f (u, v) f (v, u) u S v T u S v T = f (S, T ). f (S, T ) c(s, T ) for the following reason: f (S, T ) = f (u, v) f (v, u) u S v T u S v T f (u, v) u S v T c(u, v) u S v T = c(s, T ). J. Wang (UMass Lowell) Maximum Flow 22 / 27

Max-Flow Min-Cut Theorem Theorem 26.6. (1) f is a maximum flow in G iff (2) G f contains no augmenting paths iff (3) f = c(s, T ) for some cut (S, T ) of G (this implies that this (S, T ) is a minimum cut). Proof. That (1) implies (2) is straightforward. To show that (2) implies (3), let S = {v V there exists a path from s to t in G f }. Let T = V S. Then (S, T ) is a cut because t S. Let u S and v T. If (u, v) E, then f (u, v) = c(u, v). This is because if f (u, v) < c(u, v), then (u, v) E f, and so v S, a contradiction. If (u, v) E, then f (u, v) = 0. This is because if f (u, v) > 0, then c f (u, v) = f (v, u) > 0, and so (u, v) E f, contradicting to v S. J. Wang (UMass Lowell) Maximum Flow 23 / 27

Proof Continued f (u, v) = 0 for other cases. Thus, f = f (S, T ) = f (u, v) f (v, u) u S v T v T u S = c(u, v) 0 u S v T v T u S = C(S, T ). To show that (3) implies (1), it suffices to note that f = f (S, T ) c(s, T ). J. Wang (UMass Lowell) Maximum Flow 24 / 27

Maximum Bipartite Matching Sometimes a problem that appears to have nothing to do with maximum flow can be recast into a maximum flow problem. Given an undirected graph G = (V, E), a matching is a subset of edges such that no two edges share a common node. A matching with the largest number of edges is a maximum matching. Let G = (L R, E) be an undirected bipartite graph. We want to find a maximum matching. Construct a flow network by connecting a new node s to all nodes in L and connecting all nodes in R to another new node t. Assign each edge in the new network a capacity of 1. Then the maximum flow of the network corresponds to the maximum matching. J. Wang (UMass Lowell) Maximum Flow 25 / 27

Maximum Bipartite Matching Example J. Wang (UMass Lowell) Maximum Flow 26 / 27

An Application of Maximum Bipartite Matching In a local Apple store there are m sales reps working on a typical working day. At a peak hour there are n customers acquiring different types of services. A sales rep may be able to provide the service needed by certain customers. For example, sales rep Eric may be able to serve customers Alice, Bob, and Charlie. Moreover, each sales rep can only serve one customer at a time. Find an assignment so that maximum number of customers are served at a time. This is a maximum bipartite matching problem. J. Wang (UMass Lowell) Maximum Flow 27 / 27