Skip to content

WIP: Further improved stable marriage in python #726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jdonszelmann
Copy link
Contributor

@jdonszelmann jdonszelmann commented Jul 5, 2020

In Discord we discussed the original implementation of gale shapley, and the improvement @Amaras made (#687 ). This is just a draft which improves it further, making it more similar to the rust implementation. It's very different to the original one so you'll just have to say what you think about it.

@jdonszelmann jdonszelmann force-pushed the stable_marriage_python branch from b977f2e to 0401a67 Compare July 5, 2020 11:19
@jdonszelmann jdonszelmann changed the title Further improved stable marriage in python WIP: Further improved stable marriage in python Jul 5, 2020
partner = possible_partner
break
else:
raise Exception(f"Couldn't find a partner for {person}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure if this should be an error

Copy link
Contributor Author

@jdonszelmann jdonszelmann Jul 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nor if else is the right construct here, it's quite obscure

@jdonszelmann
Copy link
Contributor Author

We determined that this algorithm doesn't show as clearly as previous implementations, how marriages are formed. Add to that the fact that it might not work, I don't think this PR should ever be merged, and I might close it soon.

@Amaras
Copy link
Member

Amaras commented Jul 5, 2020

The first time I ran the algorithm, I got this output:

A: b, c, e, d, a
B: a, e, b, c, d
C: b, a, d, e, c
D: c, b, e, d, a
E: b, c, e, d, a

Preferences of the women:
a: E, C, A, D, B
b: D, B, A, E, C
c: C, D, E, A, B
d: E, D, C, A, B
e: E, D, A, B, C


The algorithm gave this solution:
A + b
B + a
C + d
D + c
E + e

Problem is: C prefers a over d, and a prefers C over B.
This pairing is thus unstable, so the algorithm is wrong.
As it's inspired by the Rust PR (#715), I recommend a careful analysis of the output code before considering merging it.

@lazyprop
Copy link
Contributor

lazyprop commented Jul 5, 2020

Let Alice and Bob both be engaged, but not to each other. Upon completion of the algorithm, it is not possible for both Alice and Bob to prefer each other over their current partners. If Bob prefers Alice to his current partner, he must have proposed to Alice before he proposed to his current partner. If Alice accepted his proposal, yet is not married to him at the end, she must have dumped him for someone she likes more, and therefore doesn't like Bob more than her current partner. If Alice rejected his proposal, she was already with someone she liked more than Bob.

This is from the Gale-Shapely WIkipedia page

Stability here means that there are no free men left. This is because engaged men do not propose and a change of partners only takes place if there is a free man who proposes to a woman and the woman likes him over her current partner.
The men propose in the order of their preference. And if they did get dumped, that must have been for a reason. So if the algorithm ends, the produced matching must be stable.

@Amaras
Copy link
Member

Amaras commented Jul 5, 2020

Stability here means that there are no free men left.

No, that's not what stability means. It means that you can't find a pair like C - a where they prefer each other over their partner.

It is right that in the GS algorithm, the fact that there is no free man left means that the algorithm must stop, and thus that (as a consequence of the construction of the pairing) the pairing is stable. It doesn't mean that "all men have a partner" implies that "the pairing is stable".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants