Two Applications of Maximum Flow

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

Max Flow: Algorithms and Applications

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

Algorithm Design and Analysis

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

Algorithms: Lecture 12. Chalmers University of Technology

6.046 Recitation 11 Handout

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

Algorithms and Theory of Computation. Lecture 11: Network Flow

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

Mathematics for Decision Making: An Introduction. Lecture 13

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

5 Flows and cuts in digraphs

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

CMPSCI 611: Advanced Algorithms

Algorithm Design and Analysis

Maximum flow problem

7.5 Bipartite Matching

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

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

CMSC 451: Max-Flow Extensions

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

Algorithms: COMP3121/3821/9101/9801

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

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

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

2.13 Maximum flow with a strictly positive initial feasible flow

Introduction 1.1 PROBLEM FORMULATION

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

Lecture 21 November 11, 2014

Algorithm Design and Analysis

1 Review for Lecture 2 MaxFlow

The min cost flow problem Course notes for Optimization Spring 2007

Review Questions, Final Exam

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

The Max Flow Problem

Lecture 2: Network Flows 1

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

Discrete Optimization 2010 Lecture 3 Maximum Flows

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

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

Introduction to Graph Theory

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

Discrete Optimization 23

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

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.

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

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

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

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

Network Flows made simple

Soviet Rail Network, 1955

Maximum Flow Problem (Ford and Fulkerson, 1956)

Algorithm Design and Analysis

Maximum flow problem (part I)

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

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

Lecture 5 January 16, 2013

Week 4. (1) 0 f ij u ij.

C&O 355 Mathematical Programming Fall 2010 Lecture 2. N. Harvey

6. Linear Programming

Recall: Matchings. Examples. K n,m, K n, Petersen graph, Q k ; graphs without perfect matching

Chapter 7 Matchings and r-factors

Maximum flow problem CE 377K. February 26, 2015

1 Matchings in Non-Bipartite Graphs

CS261: Problem Set #3

Lecture 8 Network Optimization Algorithms

Duality of LPs and Applications

Math 5490 Network Flows

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

1 Perfect Matching and Matching Polytopes

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

Today. Flow review. Augmenting paths. Ford-Fulkerson Algorithm. Intro to cuts (reason: prove correctness)

CSC 373: Algorithm Design and Analysis Lecture 12

Lecture 13: Polynomial-Time Algorithms for Min Cost Flows. (Reading: AM&O Chapter 10)

CSC Design and Analysis of Algorithms. LP Shader Electronics Example

On shredders and vertex connectivity augmentation

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

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

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

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

CS 1501 Recitation. Xiang Xiao

The maximum flow problem

Flows. Chapter Circulations

CS599: Convex and Combinatorial Optimization Fall 2013 Lecture 17: Combinatorial Problems as Linear Programs III. Instructor: Shaddin Dughmi

Lecture 2: Just married

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

Minimum cost transportation problem

Internet Routing Example

Network Flow Problems Luis Goddyn, Math 408

WEAKLY AND STRONGLY POLYNOMIAL ALGORITHMS FOR COMPUTING THE MAXIMUM DECREASE IN UNIFORM ARC CAPACITIES

CS 6820 Fall 2014 Lectures, October 3-20, 2014

Review Questions, Final Exam

Generating p-extremal graphs

Multicommodity Flows and Column Generation

1 Matroid intersection

Realization of set functions as cut functions of graphs and hypergraphs

3.3 Easy ILP problems and totally unimodular matrices

Friday, September 21, Flows

MAS210 Graph Theory Exercises 5 Solutions (1) v 5 (1)

Transcription:

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem CS 40/MCS 40 Lecture 6 Computer Algorithms I Jan Verschelde, 25 July 208 Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 2 / 28

the bipartite matching problem 0 2 In a bipartite graph G = (V, E), we have: V = A B, A B =, A, B. 3 2 for any edge (a, b) E: a A and b B. 4 6 5 7 A matching M in a bipartite graph G = (V, E): M E, is a subset of the set of edges, 2 every vertex appears at most once in M. Given a bipartite graph G, the bipartite matching problem asks to find the matching M in G of the largest size. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 3 / 28

the flow network for a bipartite graph Given G = (V, E), with V = A B, add a source s and sink t, V = V { s, t }, and construct the flow network G = (V, E ) as: s 0 2 4 3 5 t 6 7 For all e E: e E, all edges of G are directed. 2 For all a A: (s, a) E, connect the source to A. 3 For all b B: (b, t) E, connect the sink to B. 4 For all edges e E : c e =, all capacities are one. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 4 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 5 / 28

matchings and flows To a matching M in G corresponds a flow f in G : Let M = { (a, b ), (a 2, b 2 ),..., (a m, b m ) }. For all (a, b) M: f (s, a) =, f (a, b) =, and f (b, t) =. The value of the flow is m, v(f ) = m. Exercise : Verify that the f corresponding to a matching M is an s-t flow: Show that the capacity conditions on f in G hold. 2 Show that the conservation conditions on f in G hold. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 6 / 28

flows and matchings If all capacities are integers, then there is an integer valued flow. If we have an integer valued flow f in G = (V, E), then M = { (a, b) E f (a, b) = }. Lemma If the value of the flow f is m, then #M = m. Proof. G is the flow network for the bipartite graph G = (V, E), with V = A B. Consider the cut which separates the source s from A. The value of the flow is m = f in (A). By the conservation conditions, f out (A) = f in (A), the flow into A equals the flow out of A. The edges out of A that carry flow are the edges of M. The flow at each edge equals one. The number of edges with flow equals the size of M. Q.E.D. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 7 / 28

the flow and its corresponding matching If we have an integer valued flow f in G = (V, E), then for M = { (a, b) E f (a, b) = }, we have to show that M leads to a matching in G = (V, E): Lemma Every v V appears at most once in M. Proof. By contradiction, suppose v appears twice in M. If v A, then s v This picture violates the conservation conditions at v, which contradicts that f is a flow in G. Thus v cannot appear twice in M. If v B, then a similar picture will contradict the conservation conditions of the flow. Q.E.D. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 8 / 28

maximum flow and maximum matching Theorem Given a flow f in a flow network G, constructed for a bipartite graph G = (V, E), consider M = { (a, b) E f (a, b) = }. Then, v(f ) = #M and M is a matching in G. Corollary If the value of the flow f in G is maximal over all flows, then the matching M corresponding to f is maximal as well. Exercise 2: Write a proof for the corollary. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 9 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 0 / 28

finding an alternating path s t 6 4 2 0 7 5 3 s t 6 4 2 0 7 5 3 Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 / 28

the maximum bipartite matching s t 6 4 2 0 7 5 3 s t 6 4 2 0 7 5 3 Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 2 / 28

another exercise When the Ford-Fulkerson algorithm is applied to the bipartite matching problem, the augmenting paths are called alternating paths, because those paths alternate between forward and backward edges when rerouting flow in the bipartite graph. Exercise 3: Consider the pictures on slides and 2. Describe the transitions between the top and the bottom graph, using the proper terminology introduced in lecture 5. In particular, describe the construction of the residual graph with forward and backward edges in sufficient detail. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 3 / 28

the running time The Ford-Fulkerson algorithm runs in time O(mC), C = e out of s For the flow network G constructed fro the bipartite graph G = (V, E), V = A B, C #A n, where n = #V. Therefore, we arrive at the following theorem: Theorem Consider a bipartite graph G = (V, E), with n = #V and m = #E. The maximum matching problem is solved by the Ford-Fulkerson algorithm in O(mn) time. c e. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 4 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 5 / 28

perfect matchings Definition Given a bipartite graph G = (V, E) and a matching M. M is a perfect matching if every v V appears in M. What if no perfect matching is found? Consider a bipartite graph G = (V, E), V = A B. If a, a 2 A: each incident to only one edge, and the same b is that end of their incident edge. Either a or a 2 is excluded from the matching. a a 2 b Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 6 / 28

a certificate for no perfect matching? How can we be sure no perfect matching exists? Is there a certificate? We generalize the example on the previous slide. Definition Let G = (V, E) be a bipartite graph, V = A B. For any subset S A, define Γ(S) B as: Γ(S) = { b B (a, b) E, a S }. In the example on the previous slide, S = { a, a 2 }, Γ(S) = { b } and #Γ(S) = < 2 = #S. Proposition If there is a perfect matching in a bipartite graph G = (V, E) with V = A B, then #Γ(A) #A. Does the converse hold? Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 7 / 28

Hall s theorem Theorem Let G = (V, E) be a bipartite graph, V = A B with #A = #B. Then, either G has a perfect matching, or there is a S A: #Γ(S) < #A. A perfect matching or a certificate subset S can be found in O(mn) time, where n = #V and m = #E. Outline of the proof: The Ford-Fulkerson algorithm gives the maximum flow in O(mn). 2 The value of the maximum flow equals the capacity of the minimum cut. 3 A breadth-first or dept-first search computes the cut in O(m). 4 The minimum cut can be modified to find S A: #Γ(S) < #A. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 8 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 9 / 28

supplies and demands Consider a flow network with multiple sources and multiple sinks. 3 3 the sources represent factories who provide supply, the sinks represent retail outlets who have demand. 3 2 3 2 2 2 4 Given a flow network G = (V, E) with integer capacities c e on the edges. To each vertex v corresponds a demand d v : if d v > 0, v has demand of d v and is a sink, if d v < 0, v has supply of d v and is a source, if d v = 0, v is an internal node. A circulation with demands {d v } is a function f that assigns a nonnegative number of each edge, subject to capacity conditions: for each e E: 0 f (e) c e. conservation conditions: for each v V : f in (v) f out (v) = d v. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 20 / 28

a feasibility problem A circulation with demands {d v } is a function f that assigns a nonnegative number of each edge, subject to capacity conditions: for each e E: 0 f (e) c e. conservation conditions: for each v V : f in (v) f out (v) = d v. Instead of an optimization problem, we are interested in feasibility: does there exist a circulation f which satisfies the capacity and conservation conditions? 3 3 2 3 3 2 2 3 2 2 3 2 2 2 2 3 2 4 3 2 2 4 Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 2 / 28

supply equals demand Lemma If there is a feasible circulation in a graph G = (V, E) with demands {d v }, then v V d v = 0. Proof. In a feasible solution f, the conservation conditions are satisfied: for each v V : f in (v) f out (v) = d v. Summing over all v: v V d v = v V f in (v) v V f out (v). Consider the edge (u, v) E. Along (u, v), what goes out a vertex is f out (u) and what comes in is f in (v). Summing over all vertices, the term f in (v) is canceled by f out (v) in the other sum, and the term f out (u) is canceled by f in (u) in the other sum. So the total sum equals zero. Q.E.D. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 22 / 28

the capacity D Corollary For a feasible circulation with demands {d v }: d v = d v. v V :d v >0 v V :d v <0 The common value is denoted by D = d v = d v. v V :d v >0 v V :d v <0 Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 23 / 28

Two Applications of Maximum Flow The Bipartite Matching Problem a bipartite graph as a flow network maximum flow and maximum matching alternating paths perfect matchings 2 Circulation with Demands flows with multiple sources and multiple sinks reduction to a flow problem Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 24 / 28

reduction to a flow problem Let S denote the set of all vertices v with d v < 0. Let T denote the set of all vertices v with d v > 0. Attach a super source s to each vertex u S: for each u S, add the edge (s, u) with capacity d u. Attach a super sink t to each vertex v T : for each v T, add the edge (v, t ) with capacity d v. 3 3 2 3 2 s 3 2 4 3 3 2 2 4 t In this graph G, we search for a maximum s -t flow. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 25 / 28

an exercise Exercise 4: Run the Ford-Fulkerson algorithm on the flow network shown on the previous slide. Show all steps in the execution of the algorithm. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 26 / 28

circulation and maximum flow Theorem Let G = (V, E) be a flow network with demands {d v }. Let G be the graph with added source s and sink t. There is a feasible circulation if and only if the maximum s -t flow in G has value D. Proof. We cannot have an s -t flow in G of value larger than D because the cut (A, B) with A = { s } has only capacity D. : A feasible circulation f sends a flow value of d v on each edge (s, v) and a flow value d v on each edge (v, t ). Summing over all vertices, we obtain an s -t flow of value D, which is maximal. 2 : Consider a maximum s -t flow in G of value D. Then, every edge out of s and every edge into t is completely saturated with flow. If we delete those edges, we obtain a circulation f in G which satisfies f in (v) f out (v) = d v, for every v V, so the conservation conditions are met. Q.E.D. Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 27 / 28

running time Theorem Let G = (V, E) be a flow network with demands {d v }. Let G = (V, E ) be the graph with added source s and sink t. If all capacities and demands are integer numbers, then the feasible circulation has an integer value and can be computed in O(mD) time, where m = #E. The theorem follows from the application of the Ford-Fulkerson algorithm and the observation that the constant C = equals D in the graph G. e out of s c e Computer Algorithms I (CS 40/MCS 40) Two Applications of Maximum Flow L-6 25 July 208 28 / 28