Content
- Stable Matching
- Gale-Shapley Algorithm
- Proof of Correctness
- (Exclusive) Optimality
- Context
- Five Representative Problems
Algorithm II
1. Stable Matching
WU Xiaokun 吴晓堃
xkun.wu [at] gmail
Consider job recruiting procedure:
Similar situations: PhD admission, apartment renting, marriage, etc.
Can anything goes wrong?
Instability. Consider an “arranged pair” m and w:
Whenever there’s a chance, they break up.
Stable assignment. Assignment with no instability.
How to formulated this story into a problem mathematically?
Entities. Set M = \{m_1, m_2, ..., m_n\} and W = \{w_1, w_2, ..., w_n\}
Preference. Each m \in M ranks W into R_m, and each w \in W ranks M into R_w.
Let M \times W: set of all possible ordered pairs of the form (m, w), where m \in M and w \in W.
Matching. a subset of M \times W, where each m \in M and w \in W appears in at most one pair.
A matching P is perfect if |P| = |M| = |W| = n.
A stable matching is a perfect matching with no instability.
Stable Matching Problem. Given preference lists, find a stable matching (if exists).
Note: X, Y, Z are not most satisfied, any clue?
Clearly, each entity has two states in our current formulation:
free
, or matched
.
If w got proposed:
We need a third state: engaged
.
free
.free
: engage.engaged
to m':
check its preference list R_w:
free
.engaged
, claim it the final
matching.INPUT: M, W, R_m, R_w
P = \varnothing; mark m \in M and w \in
W free
;
WHILE some m \in M is
free
free
free
;RETURN P;
Observation 1. Each m proposes in decreasing order of preference (getting worse and worse).
Observation 2. Once w engaged, it’s never free again, but “trades up” (getting better and better).
Claim. G-S algorithm terminates after at most n^2 iterations.
Pf. One of M proposes
to a new candidate in each iteration, and there are at most n^2 possible proposals.
Claim (injection). G-S algorithm outputs a
matching.
Pf. [from observations]
Claim (surjection). In G-S matching, all M get matched.
Pf. [by contradiction]
free
upon termination.Claim (bijection). G-S algorithm outputs a perfect
matching.
Pf. [by counting]
Claim. [Gale–Shapley 1962] G-S algorithm outputs a
stable matching P^\ast.
Pf. Consider a pair (m, w)
\notin P^\ast:
In either case, current matching is more stable.
Do all executions of Gale–Shapley lead to the same stable matching?
We only show the matching will not change, but is it optimal? How to define optimal?
Consider the following preferences:
1st | 2nd | 1st | 2nd | |||
---|---|---|---|---|---|---|
m | w | w' | w | m' | m | |
m' | w' | w | w' | m | m' |
It’s possible for an instance to have more than one stable matching.
Def. We say m is a valid partner of w, if there exists any stable matching that contains the pair (m, w).
1st | 2nd | 3rd | 1st | 2nd | 3rd | |||
---|---|---|---|---|---|---|---|---|
A | X | Y | Z | X | B | A | C | |
B | Y | X | Z | Y | A | B | C | |
C | X | Y | Z | Z | A | B | C |
Can you see the stable matchings?
Def. w is the best-valid partner of m: if (m, w) is valid, and no one else has a higher rank than w is also valid.
M-optimal assignment. S^\ast denote the set of pairs \{(m, best(m)) : m \in M\}.
Claim. Every executions of G-S yield S^\ast.
Claim. Every executions of G-S yield S^\ast.
Pf. suppose one of M
matched non-best-valid in S.
Claim. Every executions of G-S yield S^\ast.
Pf. suppose one of M
matched non-best-valid in S.
M-optimality come at the expense of the other side.
Def. m is the worst-valid partner of w: if (m, w) is valid, and no one else has a lower rank than m is also valid.
Claim. In S^\ast,
each w \in W is paired with worst(w).
Pf. suppose (m, w) \in
S^\ast, but m \ne worst(w).
When preferences clash completely:
Someone is destined to end up unhappy.
The lessen also applies to real life:
We made many assumptions in the problem formulation.
Lloyd Shapley. Stable matching theory and Gale–Shapley algorithm.
Alvin Roth. Applied Gale–Shapley to matching med-school students with hospitals, students with schools, and organ donors with patients.
While talking algorithms, it’s not just about computer science.
The course is structured by fundamental design techniques.