(rev. 2020/12/13)
Notes On The Stable Matching Problem
- 0. The main loop of the Gale-Shapley algorithm is configured to continue while
"some man is unmatched and hasn't proposed to every woman."
We can write this a little more formally as
"∃ man m | m is unmatched and m has not proposed to every woman."
The logical negative of that statement is the condition that makes the loop stop,
and it can be expressed as
"∀ man m | m is engaged or m has proposed to every woman."
- 1. In other words, the stopping condition of the main loop is this:
Every man m is either engaged, or m has proposed
to every woman (or both).
- 2. In each iteration of the loop, there is a proposal of a man to a woman.
Because each man goes down his preference list, each proposal is
new, meaning that the same man will never again propose to the same
woman. If there are N men and N women, there cannot be more than
N2 of these new proposals during the execution of the
algorithm, simply because N2 is how many proposals there
will be if there are no repeats and every man proposes to
every woman.
- 3. According to (1) the loop stops if every man has proposed to every woman.
According to (2), after N2 iterations of the loop, every
conceivable proposal of a man to a woman would have happened, so
every man would have proposed to every woman. Therefore, no matter what
the input is, the main loop of the algorithm stops after no more than
N2 iterations. (In actual fact, the loop always stops
after fewer than N2 iterations.)
(This proves that the loop never becomes an infinite loop,
and moreover it tells us something about how
efficient the algorithm
may be. ( O(N2) loop iterations )
- 4. "Once a woman has become engaged, she remains engaged."
What does this mean? After becoming engaged for the first time,
a woman may separate from her current fiancé,
but she will immediately become
engaged to someone else. After becoming engaged for the first time,
thereafter she will be engaged at the end of each iteration
of the main loop. She will be engaged to someone, though she may change
from one fiancé to another by "trading up."
- 5. It is a logical consequence of (4) that once all women have
received a proposal, all N women are engaged.
- 6. Claim: If all N women are engaged, then all N men are engaged.
[Proof: The way the algorithm works, a man can only be engaged
to one woman at a time. So when the N women are all engaged,
each is engaged to a different man.
Because the total number of men is N, the N different men to whom the women
are engaged are all the men.]
- 7. Claim: If all N men are engaged, then all N women are engaged.
[Proof: The way the algorithm works, a woman can only be engaged
to one man at a time, so the proof of this claim is just like
the previous proof of (6).]
- 8. Claim: When the Gale-Shapley algorithm stops, all the men and women
are engaged, proving that the Gale-Shapley algorithm always
creates a perfect matching of the men to the women.
[Proof: First of all, we can tell from the way that the algorithm works
that it always creates a match (a one-to-one and onto mapping)
between a set of some of the men, and a set of some
of the women. Therefore, to prove our claim above,
it will be enough to prove that all of the men and
all of the women are engaged when the algorithm stops.
In (1) we showed that the following is true when the loop stops:
"Every man is either engaged, or has proposed to every woman (or both)."
Because it turns out to make the proof a little easier, let's begin by
asking this question: What if one of the men has proposed to every woman
when the loop stops? If so, then by (5), all the women are engaged,
and so by (6) all the men are engaged. So, in that case the
claim we wish to prove is true.
What if none of the men has proposed to all of the women when the loop
stops? The stopping condition says that every man is either engaged
or has proposed to every woman. So, when the loop stops, if none of the
men has proposed to every women, then all of the men must be engaged.
According to (7), then all the women are engaged too.
We've shown that all the men and all the women are engaged when the loop stops,
so that completes the proof.]
The alert reader may have noticed that in proving the claim above, we've
also demonstrated that the loop condition we were given is "over constrained."
It should be clear now that the condition for continuing in the loop could be
simply that there is a free man. We now know that if a man is free, he has not
proposed to every woman.
The next thing we want to find out is whether this perfect matching
that we get from the Gale-Shapely algorithm is guaranteed to be
stable. Here is the idea: Suppose that
- 9. Alice is matched to Bill, and
- 10. Charlotte is matched to David.
Is it possible that (David, Alice) is an unstable pair? In other words, is it possible that both the following things are true?
- 11. Does David like Alice better than his match, Charlotte?
- 12. Does Alice like David better than her match, Bill?
If so then Alice and David both have an incentive to 'run off'
with each other. This would be an instability
in the matching.
- 13. Well, suppose that 9, 10, and 11 are true. Consider the following
logical consequences of that.
- 14. Because 11 is true (David likes Alice better than Charlotte),
Alice is higher on David's list than Charlotte,
and so David must have proposed to Alice before he proposed
to Charlotte.
- 15. By 9, Alice is not with David now, and because of
the way the algorithm works, she must have rejected David. Either she
turned David down when he proposed to her (because she was already
engaged to someone higher on her list), or she was once
engaged to David, and then dumped him to "trade up."
- 16. Either way, after Alice rejected David, she was engaged to
someone, mr. X, whom she liked more than David. After that,
she never "traded down." The only possibility is that she
did some more "trading up."
- 17. Because of the reasoning in step 16, above, we can conclude that
Bill, the guy with whom Alice ended up, is someone she likes more than
David.
- 18. To sum up the logic, if 9, 10, and 11 are true, then
"Alice does not like David more than Bill."
In other words, if 9, 10, and 11 are true, then 12 is false.
- By showing that "if 9, 10, and 11 are true then 12 is false,"
we have shown that 9, 10, 1l, and 12 can't all be true.
This proves that the algorithm
creates a matching with no instabilities.
- So, we've reached an important milestone! We have now proved
that the Gale-Shapley algorithm really works. No matter
what the inputs are, the algorithm always outputs a stable matching,
which, by definition is a perfect matching
with no unstable pairs.
- Our text goes on to define what it means for a man and woman
(m, w) to be valid partners. It means there exists
a stable matching in which m and w are one of the matches.
It is important to understand that there may be stable matchings
that cannot be created by the Gale-Shapley algorithm.
Keep that in mind when you think about
valid partners. A man and woman (m,w) are valid partners if there is
any stable matching that matches those two with each other.
- After defining valid partners, the text proves that
19. The Gale-Shapley algorithm always matches each man with his
"best valid partner"
- the valid partner who is highest on his preference list.
- Make sure you understand the idea of a "best valid partner."
It definitely does not mean "the first choice."
Given a set of n men and n women, and all their preference lists,
there are many different ways to make a perfect matching. We know
that at least one of those prefect matchings is stable
(the output of the Gale-Shapley
algorithm). There could be more than one stable matching for
those men and women and their preferences. How many stable matchings
there are depends on exactly what the preferences are.
It's possible that a given pair (m,w) are not
matched in any of the stable matchings that may exist for the 2n people
and their preferences.
In that case,
we say that m and w are not valid partners. For every man m, there is
at least one valid partner (the one he gets
from the Gale-Shapley algorithm). Maybe there are more valid partners of
m that he gets in other stable matchings. The best valid
partner of m is whichever of his valid partners who is highest on his
list. That best valid partner could be the actual first woman
on m's list, but she could be a woman further down the list,
because the first woman on the list may not be a valid partner
for m. (Maybe there's no stable
matching in which m is matched up with the first woman on his list.)
It's even possible that
m's best valid partner is the last woman on his list! Depending
on what exactly the preferences are, it could work out that way!
- Anyway, it seems pretty amazing that the Gale-Shapley algorithm
simultaneously gives all the men the "best" match
they could hope to receive in any stable matching.
Also this fact shows that the algorithm always gives the same
matching as its output, no matter what particular men are chosen
during the execution to make the next proposal! No matter what,
the algorithm will match each guy to his one and only
best valid partner!
The central idea of the proof is to demonstrate that when the algorithm runs
no man is rejected by a valid partner.
- The text also proves that
20. The G-S algorithm pairs each woman with her worst
valid partner.
- I made proofs of 19 and 20 that are somewhat different from the proofs
in our text. Those proofs are included in one of the other
documents in my set of notes for this chapter. At the time I'm
writing this, the title of that document is "BVP_pf.html."