0% found this document useful (0 votes)
37 views29 pages

02 SM

Uploaded by

perfectzink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views29 pages

02 SM

Uploaded by

perfectzink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Stable Matchings

Stable Matching Problem


Given two sets
each agent ranks every agent in the other set.
Goal: Match each agent to exactly one agent in the other
set, respecting their preferences.
How do we “respect preferences”?
Avoid blocking pairs: unmatched pairs where prefers to their
match, and prefers to its match.
h , h𝑟
’ 𝑟 ,𝑟 ’
h

𝑟′ h′
Stable Matching, More Formally
Perfect matching:
•Each rider is paired with exactly one horse.
•Each horse is paired with exactly one rider.
Stability: no ability to exchange
an unmatched pair - is blocking if they both prefer each
other to current matches.
Stable matching: perfect matching with no blocking pairs.

Stable Matching Problem


Given: the preference lists of riders and
horses.
Find: a stable matching.
Questions
Does a stable matching always exist?
Can we find a stable matching efficiently?

We’ll answer both of those questions in the next few lectures.


Let’s start with the second one.
Idea for an Algorithm
Key idea
Unmatched riders “propose” to the highest horse on
their preference list that they have not already proposed
to.

Send in a rider to walk up to their favorite horse.


Everyone in front of a different horse? Done!
If more than one rider is at the same horse, let the horse
decide its favorite.
Rejected riders go back outside.

Repeat until you have a perfect matching.


Gale-Shapley Algorithm
Initially all in and in are free
While there is a free
Let be highest on ’s list that has not proposed to
if is free, then match
else // is not free
suppose are matched
if prefers to
unmatch
match
Algorithm Example

h 1 ,h2 ,h3 𝑟1 h 1𝑟 2 , 𝑟 3 , 𝑟 1

h 1 ,h3 ,h 2 𝑟2 h2 𝑟3 , 𝑟1 , 𝑟2

h 1 ,h2 ,h3 𝑟3 h3 𝑟3 , 𝑟1 , 𝑟2

Proposals:
Does this algorithm work?
Does it run in a reasonable amount of time?
Is the result correct (i.e. a stable matching)?

Begin by identifying invariants and measures of progress


Observation A: r’s proposals get worse for them.
Observation B: Once h is matched, h stays matched.
Observation C: h’s partners get better.
How do we justify these? A one-sentence explanation would suffice for
each of these on the homework.
How did we know these were the right observations? Practice. And editing
– we wouldn’t have found these the first time, but after reading through
early proof attempts.
Claim 1: If proposed to the last horse on
their list, then all the horses are matched.
Try to prove this claim, i.e. clearly explain why it is true. You might
want some of these observations:
Observation A: r’s proposals get worse for them.
Observation B: Once h is matched, h stays matched.
Observation C: h’s partners get better.

Hint: must have been rejected a lot – what does that mean?
Claim 1: If proposed to the last horse on
their list, then all the horses are matched.
Hint: must have been rejected a lot – what does that mean?

By Observation B, once a horse receives any proposal it is


not free for the rest of the algorithm.

So every horse on ’s list must be matched.

And every horse is on ’s list!


Claim 2: The algorithm stops after
proposals.
Hint: When do we exit the loop? (Use claim 1).

If every horse is matched, every rider must be


matched too.
-Because each horse is matched to exactly one rider and
there are an equal number of riders and horses.
It takes at most proposals to get to the end of some
rider’s list.
Claim 2 now follows from Claim 1.

Question 1 answered: The algorithm halts (quickly)!


Now question 2: does it produce a stable matching?
Wrapping up the running time
We need proposals. But how many steps does the full
algorithm execute?
Depends on how we implement it…we’re going to need some
data structures.
Gale-Shapley Algorithm
Initially all in and in are free
While there is a free
Let be highest on ’s list that has not proposed to
if is free, then match
else // is not free suppose are matched
if prefers to
unmatch
match
Are each of these operations really ?
Assume that you get two int[][] with the preferences.
Gale-Shapley Algorithm
Initially all in and in are free
While there is a free Need to maintain free . What can insert and remove
Let be highest on ’sinlist
time?
that has not proposed to
if is free, then match Maintain partial Each should know
matching where it is on its list.
else // is not free suppose are matched
if prefers to Given two riders, which horse is
preferred?
unmatch Maintain partial
match matching
Are each of these operations really ?
Assume that you get two int[][] with the preferences.
What data structures should you
use?
Initially all in and in are free
While there is a free Need to maintain free . What can insert and remove
Let be highest on ’sinlist
time?
that has not proposed to
if is free, then match Maintain partial Each should know
matching where it is on its list.
else // is not free suppose are matched
if prefers to Given two riders, which horse is
preferred?
unmatch Maintain partial
match matching
Fill out the poll everywhere for Introduce yourselves!
If you can turn your video on, please do.
Activity Credit! If you can’t, please unmute and say hi.
Go to pollev.com/cse417 and If you can’t do either, say “hi” in chat.
login with your UW identity Choose someone to share
screen, showing this pdf.
What data structures?
Need to maintain free . What can insert and remove
in time?
Queue, stack, or list (inserting at end) all would be fine.
Maintain partial
matching
Two arrays (index i has number for partner of agent i.
Each should know
where it is on its list.

int for each rider (likely store in an array)


Given two riders, which is
preferred?
Lookup in int[][] takes… in the worst case. Uh-oh.
Better idea: build “inverse” arrays (given rider, what is their rank
for horse?).
What data structures?
These aren’t the only
Need to maintain free . What can insert and remove options – you might decide
in time? on an object-based
Queue, stack, or list (inserting at end) all would be fine.
approach (can meet same
Maintain partial time bounds up to
matching constant factors)
Two arrays (index i has number for partner of agent i.
But tl;dr: You really can get
Each should know time!
where it is on its list.

int for each rider (likely store in an array)


Given two riders, which is
preferred?
Lookup in int[][] takes… in the worst case. Uh-oh.
Better idea: build “inverse” arrays (given rider, what is their rank
for horse?).
Analyzing Gale-Shapley

Efficient?
Halts in steps. ✔

Works?
Need a matching that’s:
• Perfect
• Has no blocking pairs
Claim 3: The algorithm identifies a perfect
matching.
Why?

We know the algorithm halts. Which means when it halts


every rider is matched.
But we have the same number of horses and riders, and we
matched them one-to-one.

Hence, the algorithm finds a perfect matching.


Claim 4: The matching has no blocking
pairs.
We want to prove a negative
there is no blocking pair.
That’s a good sign for proof by contradiction.
What’s proof by contradiction?
I want to know is true.
Imagine, were false. Study the world that would result.
Realize that world makes no sense (something false is
true)
But the real world does make sense! So must be true.
Claim 4: The matching has no blocking
pairs.
We want to prove a negative
there is no blocking pair.
That’s a good sign for proof by contradiction.
Suppose (for contradiction) that and are matched, but
prefers to and
prefers to …h 2 …h1 … 𝑟1 h1

𝑟2 h 2 …𝑟 1 …𝑟 2 …
Claim 4: The matching has no blocking
pairs.
…h 2 …h1 … 𝑟1 h1

𝑟2 h 2 …𝑟 1 …𝑟 2 …
How did end up matched to ?
He must have proposed to and been rejected by
(Observation A).
Why did reject ? It got a better offer from some .
If ever changed matches after that, the match was only
better for it, (Observation C) so it must prefer (its final
match) to .
A contradiction!
Result
Simple, algorithm to compute a stable matching
Corollary
A stable matching always exists.
The corollary isn’t obvious!
The “stable roommates problem” doesn’t always have
a solution:
people, rank the other
Goal is to pair them without any blocking pairs.
Multiple Stable Matchings

Suppose we take our algorithm and let the horses do the


“proposing” instead.

h 1 , h2 𝑟 1 h 1𝑟 2 , 𝑟 1

h 2 , h1 𝑟 2 h 2𝑟 1 , 𝑟 2

We got a different answer…


What does that mean?
Proposer-Optimality
Some agents might have more than one possible match in a
stable matching. Call these people the “feasible partners.”
When there’s more than one stable matching, there is a
tremendous benefit to being the proposing side.

Proposer-Optimality
Every member of the proposing side is
matched to their favorite of their feasible
partners.
Proposer-Optimality 𝑟 h′
Proposer-Optimality
Every member of the proposing side is
matched to the favorite of their feasible
partners. 𝑟′ h
Let’s prove it – again by contradiction
Suppose some rider is not matched to their favorite feasible partner.
Then some must have been the first to be rejected by their favorite
feasible partner, . (Observation A)
And there is an that (temporarily) matched to causing that rejection.

Let be a matching where are matched. The rider is matched to some .


What can we say about ? They had never been rejected by a feasible
partner. So they prefer to . 𝑟 h′
And prefers to (by the run of the algorithm).
But then are a blocking pair in 𝑟′ h
Implications of Proposer Optimality
Proposer-Optimality
Every member of the proposing side is
matched to their favorite of their feasible
partners.
We didn’t specify which rider proposes when more than one
is free
Proposer-optimality says it doesn’t matter! You always get the
proposer-optimal matching.

So what happens to the other side?


Chooser-Pessimality
A similar argument (it’s a good exercise!), will show that
choosing among proposals is a much worse position to be in.

Chooser-Pessimality
Every member of the choosing (non-
proposing) side is matched to their least
favorite of their feasible partners.
Some More Context and Takeaways
Stable Matching has another common name: “Stable
Marriage”
The metaphor used there is “men” and “women” getting
married.

When choosing or analyzing an algorithm think about


everyone involved, not just the people you’re optimizing for;
you might not be able to have it all.
Stable Matchings always exist, and we can find them
efficiently.
The GS Algorithm gives proposers their best possible partner

You might also like