fullscreen
timer
qrcode
plickers
selector
edit
reset

Some Representative Problems (1)

COS 320 - Algorithm Design

Some Representative Problems (1)

Stable Matching

matching med-school students to hospitals

Goal: given a set of preferences among hospitals and med-school students, design a self-reinforcing admissions process

Unstable Pair

Hospital \(h\) and student \(s\) form an unstable pair if both:

  • \(h\) prefers \(s\) to one of its admitted students
  • \(s\) prefers \(h\) to assigned hospital

Stable Assignment

Assigment with no unstable pairs


stable matching problem: input

Input: a set of \(n\) hospitals \(H\) and a set of \(n\) students \(S\) (one student per hospital for now)

1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

1st: most favorite; 3rd: least favorite

perfect matching

Matching

A matching \(M\) is a set of ordered pairs \(h\-s\) with \(h \in H\) and \(s \in S\) such that

  • each hospital \(h \in H\) appears in at most one pair of \(M\), and
  • each student \(s \in S\) appears in at most one pair of \(M\).


Perfect Matching

A matching \(M\) is perfect if \(|M| = |H| = |S| = n\)

perfect matching

A perfect matching \(M = \{ A\-Z, B\-Y, C\-X \}\)


1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

unstable pair

Unstable Pair

Given a perfect matching \(M\), hospital \(h\) and student \(s\) form an unstable pair if both:

  • \(h\) prefers \(s\) to matched student, and
  • \(s\) prefers \(h\) to matched hospital


Key point: An unstable pair \(h\-s\) could each improve by joint action

unstable pair

\(A\-Y\) is an unstable pair for matching \(M = \{ A\-Z, B\-Y, C\-X \}\)


1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago


Here, Atlanta and Yolanda could make a side deal that would benefit both of them, but would leave Zeus and Boston in a bad position

quiz 0: unstable pair

live view ]

Which pair is unstable in matching \(M = \{ A\-X, B\-Z, C\-Y \}\)?

  1. \(A\-Y\)

  2. \(B\-X\)

  3. \(B\-Z\)

  4. None of the above

1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

stable matching problem

Stable Matching

A stable matching is a perfect matching with no unstable pairs.


Stable matching problem: given the preference lists of \(n\) hospitals and \(n\) students, find a stable matching (if one exists).

stable matching problem

A stable matching \(M = \{ A\-X, B\-Y, C\-Z \}\)


1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

stable roommate problem

Q. Do stable matchings always exist?

  1. Not obvious a priori.

Stable roommate problem:

1st 2nd 3rd
A B C D
B C A D
C A B D
D A B C

stable roommate problem

Q. Do stable matchings always exist?

  1. Not obvious a priori.
1st 2nd 3rd
A B C D
B C A D
C A B D
D A B C

no perfect matching is stable

\(A\-B\), \(C\-D\) \(B\-C\) unstable
\(A\-C\), \(B\-D\) \(A\-B\) unstable
\(A\-D\), \(B\-C\) \(A\-C\) unstable

Observation: Stable matchings need not exist

Some Representative Problems (1)

Stable Matching: gale-shapley

gale-shapley deferred acceptance alg

An intuitive method that guarantees to find a stable matching

// Gale-Shapley (preference lists for hospitals and students)
Initialize M to empty matching
While some hospital h is unmatched and hasn't proposed to every student:
    s <- first student on h's list to whom h has not yet proposed
    If s is unmatched
        Add h-s to matching M
    Else If s prefers h to current partner h'
        Replace h'-s with h-s in matching M
    Else
        s rejects h
Return stable matching M
1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

proof of correctness: termination




Observation 1: Hospitals propose to students in decreasing order of preference.


Observation 2: Once a student is matched, the student never becomes unmatched; only "trades up"

proof of correctness: termination

Claim: Gale-Shapley terminates after at most \(n^2\) iterations of while loop.

Pf: Each time through the while loop, a hospital proposes to a new student. There are only \(n^2\) possible proposals. ∎

1st 2nd 3rd 4th 5th 1st 2nd 3rd 4th 5th
Atlanta V W X Y Z    Val B C D E A
Boston W X Y V Z Wayne C D E A B
Chicago X Y V W Z Xavier D E A B C
Dallas Y V W X Z Yolanda E A B C D
Eugene V W X Y Z Zeus A B C D E

Proposals required: \(n(n-1)+1\)

proof of correctness: perfection

Claim: Gale-Shapley produces a matching.

Pf:

proof of correctness: perfection

Claim: In Gale-Shapley matching, all hospitals get matched.

Pf: (by contradiction)


Observation 2: Once a student is matched, the student never becomes unmatched; only "trades up"

proof of correctness: perfection

Claim: In Gale-Shapley matching, all students get matched.

Pf:

proof of correctness: stability

Claim: In Gale-Shapley matching \(M'\), there are no unstable pairs.

Pf: Suppose that \(M'\) does not contain the pair \(h\)-\(s\).

summary

Stable matching problem: Given \(n\) hospitals and \(n\) students and their preferences, find a stable matching if one exists.

Theorem [Gale-Shapley 1962]: The Gale-Shapley algorithm guarantees to find a stable matching for any problem instance.

Q: How to implement Gale-Shapley algorithm efficiently?

Q: If multiple stable matchings, which one does Gale-Shapley find?

quiz 1: same stable matching?

live view ]

Do all executions of Gale-Shapley lead to the same stable matching?

  1. No, because the algorithm is nondeterministic

  2. No, because an instance can have several stable matchings

  3. Yes, because each instance has a unique stable matching

  4. Yes, even though an instance can have several stable matchings and the algorithm is nondeterministic

Some Representative Problems (1)

hospital optimality

understanding the solution

For a given problem instance, there may be several stable matchings.

1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago
1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus    Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago


An instance with two stable matchings:

\[S = \{ A\-X, B\-Y, C\-Z \}, S' = \{ A\-Y, B\-X, C\-Z \}\]

understanding the solution

Valid Partner

Student \(s\) is a valid partner for hospital \(h\) if there exists any stable matching in which \(h\) and \(s\) are matched.

Ex:

1st 2nd 3rd 1st 2nd 3rd
Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago
Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago
Chicago Xavier Yolanda
Zeus
Zeus Atlanta Boston
Chicago

An instance with two stable matchings:

\[S = \{ A\-X, B\-Y, C\-Z \}, S' = \{ A\-Y, B\-X, C\-Z \}\]

quiz 2: valid partner

live view ]

Who is the best valid partner for W in the following instance with stable matchings?

  1. A

  2. B

  3. C

  4. D

\(M_0 = \{ A\-W, B\-X, C\-Y, D\-Z \}\)

\(M_1 = \{ A\-X, B\-W, C\-Y, D\-Z \}\)

\(M_2 = \{ A\-X, B\-Y, C\-W, D\-Z \}\)

\(M_3 = \{ A\-Z, B\-W, C\-Y, D\-X \}\)

\(M_4 = \{ A\-Z, B\-Y, C\-W, D\-X \}\)

\(M_5 = \{ A\-Y, B\-Z, C\-W, D\-X \}\)

1st 2nd 3rd 4th 1st 2nd 3rd 4th
A Y Z X W W D A B C
B Z Y W X X C B A D
C W Y X Z Y C B A D
D X Z W Y Z D A B C

understanding the solution

Valid Partner

Student \(s\) is a valid partner for hospital \(h\) if there exists any stable matching in which \(h\) and \(s\) are matched.

Hospital-optimal assignment: Each hospital receives best valid partner.

Claim: All executions of Gale-Shapley yield hospital-optimal assignment.

Corollary: Hospital-optimal assigment is a stable matching!

hospital optimality

Claim: Gale-Shapley matching \(M\) is hospital-optimal.

Proof: (by contradiction)

  • Suppose a hospital is matched with student other than best valid partner
  • Hospitals propose in decreasing order of preference
    ⇒ some hospital is rejected by valid partner during G-S
  • Let \(h\) be first such hospital that is rejected, and let \(s\) be the first valid student that rejects \(h\)
  • Let \(M\) be a stable matching where \(h\) and \(s\) are matched.
  • When \(s\) rejects \(h\) in G-S, \(s\) forms (or re-affirms) commitment to a hospital, say \(h'\)
    ⇒ \(s\) prefers \(h'\) to \(h\)
  • Let \(s'\) be partner of \(h'\) in \(M\)
  • \(h'\) had not been rejected by any valid partner (including \(s'\)) at the point when \(h\) is rejected by \(s\) because this is the first rejection by a valid partner
  • Thus, \(h'\) had not yet proposed to \(s'\) when \(h'\) proposed to \(s\)
    ⇒ \(h'\) prefers \(s\) to \(s'\)
  • Thus, \(h'\)-\(s\) is unstable in \(S\), a contradiction. ∎

student pessimality

Q: Does hospital-optimality come at the expense of the students?
A: Yes.

Student-pessimal assignment: Each student receives worst valid partner.

Claim: Gale-Shapley finds student-pessimal stable matching \(M\)

Proof: (by contradiction)

  • Suppose \(h\)-\(s\) matched in \(M'\) but \(h\) is not the worst valid partner for \(s\)
  • There exists stable matching \(M\) in which \(s\) is paired with a hospital, say \(h'\), whom \(s\) prefers less than \(h\)
    ⇒ \(s\) prefers \(h\) to \(h'\)
  • Let \(s'\) be the partner of \(h\) in \(M\). By hospital-optimality, \(s\) is the best valid partner for \(h\).
    ⇒ \(h\) prefers \(s\) to \(s'\)
  • Thus, \(h\)-\(s\) is an unstable pair in \(M\), a contradiction. ∎

quiz 3: lie for gain?

live view ]

Suppose each agent knows the preference lists of every other agent before the hospital propose-and-reject algorithm is executed. Which of the following is true?

  1. No hospital can improve by falsifying its preference list

  2. No student can improve by falsifying their preference list

  3. Both A and B

  4. Neither A nor B

Deceit: Machiavelli meets Gale-Shapley

Q: Can there be an incentive to misrepresent your preference list?

Fact: No, for any hospital; yes, for some students.

Example: Xavier😈 lies by swapping

A
↔ ^^^C^^^

1 2 3 1 2 3
Atlanta X Y Z Xavier B A C
Boston Y X Z Yolanda A B C
Chicago X Y Z Zeus A B C

1 2 3 1 2 3
Atlanta X Y Z Xavier😈 B
C
A
Boston Y X Z Yolanda A B C
Chicago X Y Z Zeus A B C

Some Representative Problems (1)

context

extensions

Extension 1: some agents declare others as unacceptable (med-school student unwilling to work in Cleveland)

Extension 2: some hospitals have more than one position.

Extension 3: Unequal number of positions and students (more than 43k med-school students; only 31k positions)


Matching \(M\) is unstable if there is a hospital \(h\) and student \(s\) such that:

extensions

Matching \(M\) is unstable if there is a hospital \(h\) and student \(s\) such that:


Theorem: There exists a stable matching.

Pf: Straightforward generalization of Gale-Shapley algorithm.

historical context

National Resident Matching Program (NRMP)

2012 Nobel Prize in Economics

Lloyd Shapley: Stable matching theory and Gale-Shapley algorithm.

original application: college admissions and traditional marriage
original application: college admissions and traditional marriage

Alvin Roth: Applied Gale-Shapley to matching med-school students with hospitals, students with schools, and organ donors with patients.

Lloyd Shapley and Alvin Roth
Lloyd Shapley and Alvin Roth
won a Nobel Medal
won a Nobel Medal

Other applications

New York City High School Matching

8th Grader ranks top-5 high schools
High School ranks students (and limit)
Goal match 90k students to 500 high school programs


Other applications

QuestBridge National College Match for Low-Income Students

Student Ranks colleges
College Ranks students willing to admit (and limit)
Goal Match students to colleges


Other applications

Content delivery networks: Distribute much of world's content on web

User Prefers web server that provides fast response time
Server Prefers to serve users with low cost
Goal Assign billions of users to servers, every 10 seconds

Some Representative Problems (1)

five representative problems

Interval scheduling

Input: Set of jobs with start times and finish times.

Goal: Find maximum cardinatily (max count) subset of mutually compatible jobs (jobs don't overlap)

Weighted interval scheduling

Input: Set of jobs with start times, finish times, and weights.

Goal: Find maximum weight subset of mutually compatible jobs (jobs don't overlap)

bipartite matching

Problem: Given a bipartite graph \(G = (L \cup R, E)\), find a max cardinality matching.

A subset of edges \(M \subseteq E\) is a matching if each node appears in at most one edge in \(M\)

independent set

Problem: Given a graph \(G = (V, E)\), find a max cardinality independent set.

A subset \(S \subseteq V\) is independent if for every \((u,v) \in E\), either \(u \notin S\) or \(v \notin S\), or both.

competitive facility location

Input: Graph with weight on each node

Game: Two competing players alternate in selecting nodes. Not allowed to select a node if any of its neighbors have been selected.

Goal: Select a maximum weight subset of nodes.

five representative problems

Variations on a theme: independent set

some representative problems (1)

efficient implementation of gale-shapley

efficient implementation

Efficient implementation: We describe an \(O(n^2)\) time implementation.


Representing hospitals and students:

Representing the matching:

efficient implementation

Hospitals proposing:

efficient implementation

Students rejecting/accepting:

1st 2nd 3rd 4th 5th 6th 7th 8th
pref[]: 8 3 7 1 4 5 6 2
for i = 1 to n
    inverse[pref[i]] = i
1 2 3 4 5 6 7 8
inverse[] 4th 8th 2nd 5th 6th 7th 3rd 1st

Student prefers hospital 3 to 6 since inverse[3] < inverse[6]

Some representative problems (1)

gale-shapley practice

practice

1st 2nd 3rd 4th 5th
Victor Bertha Amy Diane Erika Claire
Wyatt Diane Bertha Amy Claire Erika
Xavier Bertha Erika Claire Diane Amy
Yancey Amy Diane Claire Bertha Erika
Zeus Bertha Diane Amy Erika Claire


1st 2nd 3rd 4th 5th
Amy Zeus Victor Wyatt Yancey Xavier
Bertha Xavier Wyatt Yancey Victor Zeus
Claire Wyatt Xavier Yancey Zeus Victor
Diane Victor Zeus Yancey Xavier Wyatt
Erika Yancey Wyatt Zeus Xavier Victor
1st 2nd 3rd 4th 5th
Victor Bertha Amy Diane Erika Claire
Wyatt Diane Bertha Amy Claire Erika
Xavier Bertha Erika Claire Diane Amy
Yancey Amy Diane Claire Bertha Erika
Zeus Bertha Diane Amy Erika Claire


1st 2nd 3rd 4th 5th
Amy Zeus Victor Wyatt Yancey Xavier
Bertha Xavier Wyatt Yancey Victor Zeus
Claire Wyatt Xavier Yancey Zeus Victor
Diane Victor Zeus Yancey Xavier Wyatt
Erika Yancey Wyatt Zeus Xavier Victor
×