Skip to content

Instantly share code, notes, and snippets.

@rsha256
Last active March 10, 2021 18:56
Show Gist options
  • Save rsha256/418870154db10f407c53729e6297516d to your computer and use it in GitHub Desktop.
Save rsha256/418870154db10f407c53729e6297516d to your computer and use it in GitHub Desktop.
Job-optimal stable matching pairing solver template
class StableMatching():
def solve(self, job_prefs: dict, candidates_prefs: dict) -> list(tuple(str, int)):
"""
Returns a job-optimal stable matching pairing that gives equilibria (¬∃ x=(C*, J*) s.t. x ∉ solution set).
---------------------
| Jobs | Candidates |
---------------------
| 1 | A > B > C |
---------------------
| 2 | B > A > C |
---------------------
| 3 | A > B > C |
---------------------
---------------------------
| Candidates | Jobs |
---------------------------
| A | 2 > 1 > 3 |
---------------------------
| B | 1 > 3 > 2 |
---------------------------
| C | 1 > 2 > 3 |
---------------------------
>>> job_prefs = {1: ('A', 'B', 'C'), 2: ('B', 'A', 'C'), 3: ('A', 'B', 'C')}
>>> candidates_prefs = {'A': (2, 1, 3), 'B': (1, 3, 2), 'C': (1, 2, 3)}
>>> StableMatching().solve(job_prefs, candidates_prefs).sort()
[('A', 2), ('B', 1), ('C', 3)]
"""
rejects = 0
output = []
for candidate in candidates_prefs:
output.append([candidate])
while rejects == 0:
# morning
# TODO
# afternoon
# TODO
# evening
# TODO
return [tuple(x) for x in output]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment