Algorithm Circle Extra Lecture: Solving the Assignment Problem with Network Flow

Similar documents
Maximum flows & Maximum Matchings

CSE 417 Network Flows (pt 4) Min Cost Flows

Network Flow. November 23, CMPE 250 Graphs- Network Flow November 23, / 31

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

Lecture 18 Solving Shortest Path Problem: Dijkstra s Algorithm. October 23, 2009

Computational Methods in IS Research Fall Graph Algorithms Network Flow Problems

Minimum Spanning Tree (undirected graph)

Jessica Su (some parts copied from CLRS / last quarter s notes)

Maximum Flow. Flow Networks. Flow Networks Ford-Fulkerson Method Edmonds-Karp Algorithm Push-Relabel Algorithms. Example Flow Network

Lecture 3: Graphs and flows

Source. Sink. Chapter 10: Iterative Programming Maximum Flow Problem. CmSc250 Intro to Algorithms

Network Design and Optimization course

and 6.855J March 6, Maximum Flows 2

CSC 8301 Design & Analysis of Algorithms: Linear Programming

Solving problems on graph algorithms

Problem Set 7 Solutions

Lecture 6: Shortest distance, Eulerian cycles, Maxflow

Minimum Cost Edge Disjoint Paths

Network Flow I. Lecture Overview The Network Flow Problem

Lecture 3: Totally Unimodularity and Network Flows

Outline: Finish uncapacitated simplex method Negative cost cycle algorithm The max-flow problem Max-flow min-cut theorem

CS261: Problem Set #2

Maximum Flow Algorithms

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016

Tutorial for Algorithm s Theory Problem Set 5. January 17, 2013

COMP 251 Winter 2017 Online quizzes with answers

CS261: Problem Set #1

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

Copyright 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin Introduction to the Design & Analysis of Algorithms, 2 nd ed., Ch.

Network flows and Menger s theorem

1. Let n and m be positive integers with n m. a. Write the inclusion/exclusion formula for the number S(n, m) of surjections from {1, 2,...

CSE 417 Network Flows (pt 3) Modeling with Min Cuts

Homework 3 Solutions

COMP4128 Programming Challenges

LECTURES 3 and 4: Flows and Matchings

Routing Protocols and the IP Layer

Network Flow. The network flow problem is as follows:

Solution for Homework set 3

CS612 Algorithms for Electronic Design Automation

Mathematics for Decision Making: An Introduction. Lecture 18

TIE Graph algorithms

Lecture 11: Maximum flow and minimum cut

Graph Algorithms (part 3 of CSC 282),

Introduction to Algorithms. Lecture 11

Cuts, Connectivity, and Flow

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

1 Weighted matchings in bipartite graphs

Discrete Optimization 2010 Lecture 5 Min-Cost Flows & Total Unimodularity

Algorithms for Data Science

Data Structures and Algorithms

Today. Maximum flow. Maximum flow. Problem

Material handling and Transportation in Logistics. Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Lecture 6 Basic Graph Algorithms

Student Name and ID Number. MATH 3012, Quiz 3, April 16, 2018, WTT

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

I ACCEPT NO RESPONSIBILITY FOR ERRORS ON THIS SHEET. I assume that E = (V ).

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

s-t Graph Cuts for Binary Energy Minimization

Graph Algorithms. A Brief Introduction. 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ.

Graph Algorithms (part 3 of CSC 282),

Shortest Path Algorithms

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8

Dynamic-Programming algorithms for shortest path problems: Bellman-Ford (for singlesource) and Floyd-Warshall (for all-pairs).

CSC 373 Lecture # 3 Instructor: Milad Eftekhar

CSC 373: Algorithm Design and Analysis Lecture 8

CS/COE 1501 cs.pitt.edu/~bill/1501/ Network Flow

All Shortest Paths. Questions from exercises and exams

Reducing Directed Max Flow to Undirected Max Flow and Bipartite Matching

Advanced Algorithm Design and Analysis (Lecture 5) SW5 fall 2007 Simonas Šaltenis

COT 6936: Topics in Algorithms! Giri Narasimhan. ECS 254A / EC 2443; Phone: x3748

Title. Ferienakademie im Sarntal Course 2 Distance Problems: Theory and Praxis. Nesrine Damak. Fakultät für Informatik TU München. 20.

Network Flow. By: Daniel Pham, Anthony Huber, Shaazan Wirani

Today: Amortized Analysis (examples) Multithreaded Algs.

College of Computer & Information Science Fall 2007 Northeastern University 14 September 2007

Analysis of Algorithms, I

Shortest path problems

Lecture #7. 1 Introduction. 2 Dijkstra s Correctness. COMPSCI 330: Design and Analysis of Algorithms 9/16/2014

Tutorial 4: Flow Artificial Intelligence

1 Dynamic Programming

Graphs. Part II: SP and MST. Laura Toma Algorithms (csci2200), Bowdoin College

Introduction to Algorithms

Artificial Intelligence

Transportation Planning: The maximum flow problem

Matching. Algorithms and Networks

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

n 2 ( ) ( ) + n is in Θ n logn

Notes for Lecture 20

Lecture and notes by: Sarah Fletcher and Michael Xu November 3rd, Multicommodity Flow

CSE 101. Algorithm Design and Analysis Miles Jones Office 4208 CSE Building Lecture 8: Negative Edges

Lecture 11: Analysis of Algorithms (CS ) 1

Problem set 2. Problem 1. Problem 2. Problem 3. CS261, Winter Instructor: Ashish Goel.

Datenstrukturen & Algorithmen Solution of Sheet 11 FS 14

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Lecture 19 Shortest Path vs Spanning Tree Max-Flow Problem. October 25, 2009

10. EXTENDING TRACTABILITY

Lecture 10,11: General Matching Polytope, Maximum Flow. 1 Perfect Matching and Matching Polytope on General Graphs

CS483 Design and Analysis of Algorithms

Transcription:

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Algorithm Circle Extra Lecture: Solving the with Network Flow 17 September 2012

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Outline 1 The 2 Network Flow 3 Minimum-Cost Maximum Flow

The Network Flow Minimum-Cost Maximum Flow Shameless Plug The Problem We are given two groups of N objects. Each object in the first group must be assigned to a distinct object in the second group. Each assignment between a pair of elements has an associated cost. We need to find the set of assignments that minimises the total cost.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Minimum Weight Bipartite Matching We can recast this problem as finding the minimum weight matching in a complete bipartite graph. 6 6 9 3 4 8 9 4 8 2 2 5 2 5 3 2 3 3 Weighted bipartite matching [1]

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Minimum Weight Bipartite Matching We can recast this problem as finding the minimum weight matching in a complete bipartite graph. 6 6 9 3 4 8 9 4 8 2 2 5 2 5 3 2 3 3 Weighted bipartite matching [1]

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Outline 1 The 2 Network Flow 3 Minimum-Cost Maximum Flow

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Network Flow We will solve this matching problem by reducing it to a problem in graph theory concerning flow through a graph. A flow network is a directed graph (V, E) where each edge (u, v) E has a numerical capacity c(u, v). Two vertices s, t V play a special role: s is the source vertex and t is the sink. We are often concerned with finding a flow through this network.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Network Flow We will solve this matching problem by reducing it to a problem in graph theory concerning flow through a graph. A flow network is a directed graph (V, E) where each edge (u, v) E has a numerical capacity c(u, v). Two vertices s, t V play a special role: s is the source vertex and t is the sink. We are often concerned with finding a flow through this network.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Network Flow We can think of flow networks as being a network of pipes. Water enters the network at the source and exits at the sink. The amount of water flowing through each edge gives the flow through the network. The capacities of the edges represent the maximum amount of water that can flow through a given edge per second.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Network Flow More formally, we can see that the flow through an edge f (u, v) must satisfy the following: Capacity Constraints: f (u, v) c(u, v) Reverse flow: f (u, v) = f (v, u) Additionally for a vertex v other than source and sink, flow must be conserved. Conservation of flow: f (v, w) = 0. w V Here we use the convention that if two vertices u, v are not connected by an edge then f (u, v) = c(u, v) = 0.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow The archetypical problem in network flow is determining the maximum possible total flow through a network. This can be solved by the Ford-Fulkerson algorithm. We consider the residual capacity of each edge r(u, v) = c(u, v) f (u, v). A path from source to sink that only uses edges of positive residual capacity is called an augmenting path.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow The archetypical problem in network flow is determining the maximum possible total flow through a network. This can be solved by the Ford-Fulkerson algorithm. We consider the residual capacity of each edge r(u, v) = c(u, v) f (u, v). A path from source to sink that only uses edges of positive residual capacity is called an augmenting path.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow Ford-Fulkerson Initially, there is no flow through the network. While we can find an augmenting path, we send flow along that path, add this to the total flow and update the residual capacities. When there are no more augmenting paths, the algorithm terminates and we have found the maximum flow. This algorithm is greedy, but there is an important subtlety that allows it to get the correct result. Flow may be sent backwards through an edge reducing the flow through that edge in order to increase flow elsewhere.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow Ford-Fulkerson Initially, there is no flow through the network. While we can find an augmenting path, we send flow along that path, add this to the total flow and update the residual capacities. When there are no more augmenting paths, the algorithm terminates and we have found the maximum flow. This algorithm is greedy, but there is an important subtlety that allows it to get the correct result. Flow may be sent backwards through an edge reducing the flow through that edge in order to increase flow elsewhere.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow Ford-Fulkerson Initially, there is no flow through the network. While we can find an augmenting path: Let f be the flow we may send along that path. Increment the flow along each edge of the path, and decrement the flow along each reverse edge, by f. Increment the total flow by f. When there are no more augmenting paths, the algorithm terminates and we have found the maximum flow. This algorithm is greedy, but there is an important subtlety that allows it to get the correct result. Flow may be sent backwards through an edge reducing the flow through that edge in order to increase flow elsewhere.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow Ford-Fulkerson Initially, there is no flow through the network. While we can find an augmenting path: Let f be the flow we may send along that path. Increment the flow along each edge of the path, and decrement the flow along each reverse edge, by f. Increment the total flow by f. When there are no more augmenting paths, the algorithm terminates and we have found the maximum flow. This algorithm is greedy, but there is an important subtlety that allows it to get the correct result. Flow may be sent backwards through an edge reducing the flow through that edge in order to increase flow elsewhere.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Maximum Flow Ford-Fulkerson Correctness of this algorithm follows from the Max-flow Min-cut theorem which we will not discuss here. For termination, we assume the weights are integers. Then on each iteration we increase the flow by 1. Thus, the algorithm terminates after at most f iterations where f is the maximum flow. Each iteration takes O(E) time so the total runtime is O(Ef ).

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Bipartite Matching as Maximum Flow We will illustrate the Ford-Fulkerson algorithm by considering the following problem. Consider the assignment problem, but suppose that all the costs are all either 0 or. We may represent this as a graph by including edges only where the cost is 0. The resulting matching problem can be solved by finding the maximum flow.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Bipartite Matching as Maximum Flow Example 1 1 1 1 1 1 1 1 Bipartite matching flow network [2]

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Bipartite Matching as Maximum Flow Example 1 1 1 1 1 1 1 1 Bipartite matching flow network [2]

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Ford-Fulkerson Example A X B Y C Z Bipartite matching augmenting paths [3] D W

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Outline 1 The 2 Network Flow 3 Minimum-Cost Maximum Flow

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Minimum-Cost Maximum Flow Now we can finally generalise the Maximum Flow problem to be able to solve our original problem. We consider a weighted flow network, where w(u, v) denotes the weight of each edge in the graph. The Minimum-Cost Maximum Flow problem is to find, out of all possible the assignments of flows that give the maximum total flow, the one that minimises the following quantity f (u, v) w(u, v). (u,v) E

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Minimum-Cost Maximum Flow The solution is given by a simple modification of the Ford-Fulkerson algorithm. In the standard algorithm, it is not specified how augmenting paths are found, but generally depth first search is used. Instead, we use a shortest path algorithm, such as Bellman-Ford, to find the augmenting path of the least weight. We weight the back-edges going in the reverse direction with the negative of the weight of the forward direction. This is why we need a shortest path algorithm that can handle negative weight edges.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug The The Solution As before we use network flow to find a matching of the graph associated with the assignment problem. But this time, we weight the edges according to the cost of the assignment. The runtime of this algorithm is Θ(V EV ) = Θ(V 4 ). There is a way to dynamically reassign weights to the graph so that we can use Dijkstra s to find the shortest path. This gives a runtime of Θ(V 3 ). This is out of the scope of the lecture, but the re-weighting is very similar to that used in Johnson s algorithm for negative-edge-weight all-pairs shortest paths.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug The The Solution As before we use network flow to find a matching of the graph associated with the assignment problem. But this time, we weight the edges according to the cost of the assignment. The runtime of this algorithm is Θ(V EV ) = Θ(V 4 ). There is a way to dynamically reassign weights to the graph so that we can use Dijkstra s to find the shortest path. This gives a runtime of Θ(V 3 ). This is out of the scope of the lecture, but the re-weighting is very similar to that used in Johnson s algorithm for negative-edge-weight all-pairs shortest paths.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Algorithm Circle Haskell Course Algorithm Circle is holding a Haskell course that will run on Saturday the 22 nd of September and Saturday 27 nd of September. Haskell is a purely functional programming language with non-strict semantics 1. The following Haskell code generates an infinite list containing the Fibonacci numbers: let fib = 0:1: zipwith (+) fib (tail fib) 1 It is also the best programming language.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug ACM ICPC The Southern African Regionals of the ACM Intercollegiate Programming Contest will be taking place on Saturday the 20 th of October. There will be an information session this Wednesday in Meridian. Training sessions will be held on the 23 rd and 30 th of September and another date to be announced.

The Network Flow Minimum-Cost Maximum Flow Shameless Plug Licensing These lecture slides were created by for UCT Algorithm Circle and are licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. I made use of the following content from Bruce Merry s Algorithm Circle lecture on Matching Problems: 1 Weighted bipartite matching diagram 2 Bipartite matching flow network 3 Bipartite matching augmenting paths