Lecture 2: Just married

Similar documents
Bipartite Matchings and Stable Marriage

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

Matchings in Graphs. Definition 3 A matching N in G is said to be stable if it does not contain a blocking pair.

Omega notation. Transitivity etc.

CSC2556. Lecture 5. Matching - Stable Matching - Kidney Exchange [Slides : Ariel D. Procaccia]

CS 6901 (Applied Algorithms) Lecture 2

Math 301: Matchings in Graphs

Matching Theory and the Allocation of Kidney Transplantations

Two Applications of Maximum Flow

Notes for Recitation 7

We set up the basic model of two-sided, one-to-one matching

Ma/CS 6b Class 3: Stable Matchings

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

1. REPRESENTATIVE PROBLEMS

Subramanian s stable matching algorithm

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

Introduction to Graph Theory

CS320 Algorithms: Theory and Practice. Course Introduction

1. REPRESENTATIVE PROBLEMS

COMP251: Bipartite graphs

Approximation and Randomized Algorithms (ARA) Lecture 1, September 3, 2012

Combinatorial Optimisation, Problems I, Solutions Term /2015

Game Theory: Lecture #5

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

Algorithm Design and Analysis

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

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

Algorithm Design and Analysis

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

COMP251: Bipartite graphs

Flows. Chapter Circulations

6.046 Recitation 11 Handout

Lecture 2: Network Flows 1

Max Flow: Algorithms and Applications

Today. Couple of more induction proofs. Stable Marriage.

Two-Sided Matching. Terence Johnson. December 1, University of Notre Dame. Terence Johnson (ND) Two-Sided Matching December 1, / 47

Algorithms: Lecture 12. Chalmers University of Technology

PROBLEMS OF MARRIAGE Eugene Mukhin

Algorithms: COMP3121/3821/9101/9801

1. REPRESENTATIVE PROBLEMS

CSEP 521 Applied Algorithms. Richard Anderson Winter 2013 Lecture 1

Markov Decision Processes

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

Algorithms and Theory of Computation. Lecture 11: Network Flow

CS 6783 (Applied Algorithms) Lecture 3

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

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

An improved approximation algorithm for the stable marriage problem with one-sided ties

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

Stable Marriage with Ties and Bounded Length Preference Lists

Consider a complete bipartite graph with sets A and B, each with n vertices.

COOPERATIVE GAME THEORY: CORE AND SHAPLEY VALUE

MIDTERM: CS 6375 INSTRUCTOR: VIBHAV GOGATE October,

1 The Arthur-Merlin Story

2. Prime and Maximal Ideals

Price of Stability in Survivable Network Design

Lecture 5: The Principle of Deferred Decisions. Chernoff Bounds

Ma/CS 6b Class 3: Stable Matchings

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

CSC 373: Algorithm Design and Analysis Lecture 12

Analysis of Algorithms Fall Some Representative Problems Stable Matching

Cheating to Get Better Roommates in a Random Stable Matching

Algorithms: COMP3121/3821/9101/9801

The key is that there are two disjoint populations, and everyone in the market is on either one side or the other

What do you do when you can t use money to solve your problems?

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Algorithms For Inference Fall 2014

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

Lecture 4: An FPTAS for Knapsack, and K-Center

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

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

1. STABLE MATCHING. stable matching problem Gale Shapley algorithm hospital optimality context

CS 6901 (Applied Algorithms) Lecture 3

5 Flows and cuts in digraphs

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

Algorithmic Discrete Mathematics. March 21-23, 2017

Algorithms. [Knuth, TAOCP] An algorithm is a finite, definite, effective procedure, with some input and some output.

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

Algorithms Exam TIN093 /DIT602

1 T 1 = where 1 is the all-ones vector. For the upper bound, let v 1 be the eigenvector corresponding. u:(u,v) E v 1(u)

APPROXIMATION ALGORITHMS FOR THE STABLE MATCHING PROBLEM

PRIMES Math Problem Set

Matching. Terence Johnson. April 17, University of Notre Dame. Terence Johnson (ND) Matching April 17, / 41

Introduction to Quantum Branching Programs

Lecture 3: String Matching

Maximum flow problem

1 Perfect Matching and Matching Polytopes

CS264: Beyond Worst-Case Analysis Lecture #15: Smoothed Complexity and Pseudopolynomial-Time Algorithms

Computational Thinking

1.1 First Problem: Stable Matching. Six medical students and four hospitals. Student Preferences. s6 h3 h1 h4 h2. Stable Matching Problem

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

princeton univ. F 13 cos 521: Advanced Algorithm Design Lecture 17: Duality and MinMax Theorem Lecturer: Sanjeev Arora

CS261: A Second Course in Algorithms Lecture #9: Linear Programming Duality (Part 2)

Lecture 6: Introducing Complexity

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

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

Discrete Optimization

Generating p-extremal graphs

COMPSCI 611 Advanced Algorithms Second Midterm Exam Fall 2017

MATH 521, WEEK 2: Rational and Real Numbers, Ordered Sets, Countable Sets

Unit 01 Motion with constant velocity. What we asked about

Transcription:

COMP36111: Advanced Algorithms I Lecture 2: Just married Ian Pratt-Hartmann Room KB2.38: email: ipratt@cs.man.ac.uk 2017 18

Outline Matching Flow networks Third-year projects The stable marriage problem

Consider the following (slightly idealized) matchmaking problem. We are given: a set of n boys and n girls; a specification of who is prepared to marry whom. We want to compute: a 1 1 pairing of boys with girls producing the maximum number of couples.

For example: boys girls

For example: boys girls

For example: boys girls

For example: boys girls

For example: boys girls

For example: boys girls

For example: boys girls

For example: boys girls

A bipartite graph is a triple G = (U, V, E) where U and V are disjoint sets and E U V. U V Note that G = (U V, E) can be regarded as a (directed) graph in the sense of the previous lecture.

Let G = (V, W, E) be a bipartite graph. A matching is a subset E E such that E such that for all v V, there is at most one w W with (v, w) E, and, for all w W, there is at most one v V with (v, w) E. The matching is perfect if every node in V and W is incident to some e E. We then have the problem: MATCHING Given: A bipartite Graph G Return: Yes if G has a perfect matching, and No otherwise.

Here is a naïve algorithm for solving this problem begin naivematch(v,w,e) if V = if W = return Yes else return No pick v V for each {w (v, w) E} Let (V, W, E ) be result of removing v, w from (V, W, E) if naivematch(v,w,e ), return Yes return No It is pretty clear that this will in general take exponential time in n = V. Maybe we can do better...

Outline Matching Flow networks Third-year projects The stable marriage problem

Let (V, E) be a directed graph. A back-loop is a pair of edges {(u, v), (v, u)}. A flow network is a quintuple (V, E, s, t, c) where (V, E) is a directed graph with no back-loops, s, t V are distinct, and c : E N. 1 5 13 8 9 14 2 9 4 11 We assume s has no incoming edges and t no outgoing edges.

Let N = (V, E, s, t, c) be a flow network. A flow in N is a function f : E R + with the following properties: The net flow out of any node u (V \ {s, t}) is zero: v:(u,v) E f (u, v) v:(v,u) E No edge (u, v) E exceeds its capacity: f (u, v) c(u, v). The value of f is the quantity: f (s, v) f (v, s) = v:(s,v) E v:(v,s) E (v,t) E f (v, u) = 0. f (v, t) v:(t,v) E f (t, v).

Our problem: given a flow network N, compute a flow f for N whose value is maximum; such a flow will be called optimal. That is, we have the computation task: MAX FLOW Given: A flow network N Return: An optimal flow f for N. It is obvious that such an optimal flow exists. Notice that it will not in general be unique.

Here is a flow (numbers in red) for the above flow network: 1 (0) 5 (5) 13 (5) 8 (8) 9 (8) 14 (9) 2 (2) 9 (1) 4 (4) 11 (5)

The key idea: given a flow network N = (V, E, s, t, c) and a flow f, we construct an auxiliary directed graph N f, G = (V, E f ), where E f is the set of pairs: {(u, v) E f (u, v) < c(u, v)} {(u, v) (v, u) E and f (v, u) > 0}. That is, the edges of directed graph N f are those edges in E on which the capacity is not exhausted; the reversal of those edges in E on which there is some flow. Note that N f may contain back-loops.

Original network N with flow f : 1 (0) 5 (5) 13 (5) 8 (8) 9 (8) 14 (9) 2 (2) 9 (1) 4 (4) 11 (5) Auxiliary directed graph N f :

Original network N with flow f : 1 (0) 5 (5) 13 (5) 8 (8) 9 (8) 14 (9) 2 (2) 9 (1) 4 (4) 11 (5) Auxiliary directed graph N f :

Original network N with new flow f : 1 (1) 5 (5) 13 (4) 8 (8) 9 (9) 14 (10) 2 (2) 9 (0) 4 (4) 11 (4) New auxiliary directed graph N f :

Lemma (Min-cut, Max-flow) Let N = (V, E, s, t, c) be a flow network and f a flow in N. Then there is a path in N f from s to t if and only if f is not optimal. Proof. The only-if direction is trivial. Suppose, conversely, there is no path from s to t in N f. Let S be the set of nodes V reachable from s in N f, and T = V \ S. 0 s S T t f (e) = c(e) There is no backflow from T to S, and no spare capacity from S to T.

Here is the algorithm: begin flowmax(v,e,s,t,c) set f (e) = 0 for all e E while reachable(n f,s,t) let e 1,..., e m be the edges on a path from s to t for 1 i m if e i E, increment f (e i ) else decrement f (e 1 i ) return f By the Min-Cut-Max-Flow Theorem, this algorithm terminates with f optimal. This argument has the following amazing corollary: If a flow network has integral capacities, then there is an optimal flow with integral values.

suppose V = n and c(e) C. We know that REACHABILITY in N f can be solved in Time(O(n + m)) where n is the number of nodes and m the number of edges. The maximum flow is nc (s is connected to < n other nodes, with capacity C, so there are at most nc cycles of the main loop). Hence the operating time is at O(n(n + m)c). (Actually, we can do a bit better in regard to C... )

A flow network with costs is a sextuple N = (V, E, s, t, c, γ) where (V, E, s, t, c) is a flow network and γ : E N. We think of γ as a cost function, where γ(e) is the price per unit of flow along e. We can draw a flow network with each edge e labelled c(e)/γ(e). 1/10 5/1 13/1 8/1 9/0 14/2 2/11 9/1 4/3 11/11 The total cost of a flow f in N is e E f (e) γ(e).

This suggests another interesting computation task: MAX FLOW Given: A flow network with cost function, N Return: An optimal flow f for N having the minimum cost among all optimal flows. It is again obvious that such a minimum cost optimal flow exists. Again, it will not in general be unique.

In fact, a slight modification of the above algorithm will solve this problem beautifully. We regard the cost function as giving distances in the derived graph: if (u, v) is an edge of N f and (u, v) E, the distance d(u, v) is γ(e); if (u, v) is an edge of N f and (v, u) E, the distance d(u, v) is γ(e). Notice that there these distances may be negative. However, we may assume that there are no cycles of total negative length. (This is actually rather tricky to see... )

Lemma Let N be a flow network with cost function, and suppose f is a flow of value v through N, such that f has minimal cost among all flows of value v. Suppose π is a path in N f from s to t of minimal length, and let f be obtained from f by augmenting along π (in the usual way). Then f has minimal cost among all flows of value v + 1. A rigorous proof is quite involved, and we will not give one in this course. See Jungnickel Graphs, Networks and Algorithms, 3rd ed. Springer, 2008, p. 299 ff. Warning: this is hard.

Here is the resulting algorithm for computing minimum cost optimal flows: begin flowmaxcost(v,e,s,t,c,γ) set f (e) = 0 for all e E while reachable(n f,s,t) let e 1,..., e m be the edges on a path from s to t of minimal length according to γ for 1 i m if e i E, increment f (e i ) else decrement f (e 1 i ) return f It is sometimes known as the Busacker-Gowen algorithm.

MATCHING can be thought of as a flow optimization problem source sink We take the links in the graph to represent flow capacities: Let n be the number of boys (girls) and m the number of possible matches. all links have capacity 1; an perfect matching corresponds to a flow from source to sink with value n, where n is the number of boys/girls. But we have just seen how to solve this problem on O(n(n + m)) time!

Outline Matching Flow networks Third-year projects The stable marriage problem

The task: Students choose projects, and each project is associated with one or more supervisors; supervisors have maximum loads; projects have maximum numbers of participants; The Lab Manager must assign students to projects so as to maximize student satisfaction. The general set-up of (unranked) choices, projects and supervisors can still be modelled as a flow network: 2 (1) 2 (0) source 1 (1) 1 (1) 2 (1) 2 (1) 2 (1) 3 (2) sink 2 (0)

To take account of rankings, we introduce costs into the flow network: choice rankings (for Student 1 only) are shown in blue; we model these rankings as costs per unit of flow. 2 (1) source Student 1 1 3 2 2 (0) 1 (1) 1 (1) 2 (1) 2 (1) 2 (1) 3 (2) sink 2 (0) Here, an optimal assignment of students to projects corresponds to a least cost maximal flow in the network.

So, we have a mathematical model of our problem: the structure of students, projects, supervisors, choices, loadings... is represented as a flow network with costs; an optimal assignment of m students corresponds to a least cost integral flow of size m Now use the Busacker-Gowen algorithm to solve this problem. Remember: this algorithm runs incrementally, gradually increasing the flow from the source to the sink by one unit on each pass; after m passes, a least-cost flow of size m has been found; at the (m + 1)st pass, the current least-cost flow of size m is revised to yield a least-cost flow of size m + 1; it runs in polynomial time.

How the program is used: students input their choices (by a certain deadline) using a web form; once the deadline is passed the Third Year Project Administrator runs the assignment software; the assignment software computes the optimum assignment, asks for verification, and writes the assignment to the CS administration databases; the assignment is then published on the internet. Important considerations: all students should be treated fairly (everyone equally likely to get his first choice); all supervisors should be treated fairly (loads should be as even as possible).

Program structure VDU/file output User input Flow network Busacker- Gowen algorithm Assignments Data entry webpage Randomizer Student choices ACSO database And here is a run...

p:\programs\java\...\projassignv4>java ProjAssign Safe flag is set to true maxnumberofstudentsassigned= 20 Number 1st 2nd 3rd 4th 5th Cost 1 1 0 0 0 0 3 2 2 0 0 0 0 5 3 2 1 0 0 0 9 4 2 2 0 0 0 13 5 2 2 1 0 0 18... 19 4 9 4 2 0 98 20 4 8 4 3 1 108

Outline Matching Flow networks Third-year projects The stable marriage problem

Arnold Schwarzenegger

Arnold Schwarzenegger

Arnold Schwarzenegger Ingrid Bergman

Arnold Schwarzenegger Ingrid Bergman

Arnold Schwarzenegger Ingrid Bergman Al Roth Lloyd Shapley

The stable matching problem Consider the following (slightly idealized) matchmaking problem. We are given: a set of n boys and n girls; a strict ranking, for each boy, of all the girls a strict ranking, for each girl, of all the boys We want to compute: a 1 1 pairing of boys with girls in which, for every boy a and girl b, either a prefers his partner to b or b prefers her partner to a. (Such a pairing is called a stable matching.)

It helps to draw the arrangement as a complete bipartite graph: 3 4 5 1 2 boys girls It is not in the least obvious that a stable matching always exists.

It helps to draw the arrangement as a complete bipartite graph: 3 5 1 2 4 boys girls It is not in the least obvious that a stable matching always exists.

The Gale-Shapley algorithm generates a matching as follows begin Gale-Shapley(Boys rankings, Girls rankings) until all boys are engaged do for each boy a with no fiancée do a proposes to the girl he most prefers among those that a has not yet proposed to for each girl b with new proposals do let a be b s most preferred new suitor if b has no fiancé b gets engaged to a if b prefers a to her existing fiancé b cancels her existing engagement b gets engaged to a All the engaged couples get married the end

Theorem The Gale-Shapley algorithm terminates with a stable matching. Proof. The algorithm terminates

Theorem The Gale-Shapley algorithm terminates with a stable matching. Proof. The algorithm terminates Once a girl receives a proposal, she always has some fiancé or other. If there are any unengaged girls, some boy will propose to one of them eventually. Hence all the girls get engaged Hence all the boys get engaged and the algorithm stops.

Theorem The Gale-Shapley algorithm terminates with a stable matching. Proof. The algorithm terminates The resulting matching is stable

Theorem The Gale-Shapley algorithm terminates with a stable matching. Proof. The algorithm terminates The resulting matching is stable Suppose a, b and a, b, are distinct married couples produced by the algorithm. If b prefers a to a, then a never proposed to b. But a proposed to all girls better (for him) than or equal to b Therefore, a does not prefer b to b.

Exercise: show that Gale-Shapley terminates in time O(n 2 ), where n is the number of boys (or girls).

Theorem The stable matching, M, produced by the Gale-Shapley algorithm is optimal for boys: if boy a is married to girl b in M, but prefers girl b, then there is no stable matching M in which a is married to b. Proof. a b a b a b a b Gale-Shapley Stable matching M If a prefers b to b, then the pair a, b M must have been a rejected proposal or cancelled engagement in the construction of M.

Theorem The stable matching, M, produced by the Gale-Shapley algorithm is optimal for boys: if boy a is married to girl b in M, but prefers girl b, then there is no stable matching M in which a is married to b. Proof. a b a b a b a b Gale-Shapley Stable matching M If a prefers b to b, then the pair a, b M must have been a rejected proposal or cancelled engagement in the construction of M.

Proof. Let a, b M be the first pair rejected or cancelled in the construction of M. a b a b a b a b Gale-Shapley Stable matching M Let a be such that b rejects/cancels a for a in construction of M. So b prefers a to a. Let b be the partner of a in M (stable). So a prefers b to b. But then the pair a, b must have been rejected/cancelled in construction of M, contradicting fact that a, b is first.

Proof. Let a, b M be the first pair rejected or cancelled in the construction of M. a b a b a b a b Gale-Shapley Stable matching M Let a be such that b rejects/cancels a for a in construction of M. So b prefers a to a. Let b be the partner of a in M (stable). So a prefers b to b. But then the pair a, b must have been rejected/cancelled in construction of M, contradicting fact that a, b is first.

Summary In this lecture, we have considered: a pseudo-polynomial-time algorithm for determining optimal flows in flow networks; the reduction of maximum matching to flow optimization (with bounded capacities); a pseudo-polynomial-time algorithm for determining minimal cost optimal flows in flow networks with costs; a practical application of this algorithm; an algorithm for producing stable matchings. Items marked in blue are not examinable. In several cases, we found that analysing these (practically useful) algorithms yields interesting mathematical results. Reading: G+T Ch 16.