Last active
June 23, 2023 08:58
-
-
Save mostafatouny/d759e048450460881b8813e5aae833dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matching.games import HospitalResident | |
# Source. https://matching.readthedocs.io/en/latest/discussion/hospital_resident/ | |
customers_preferences = { | |
"Layla": ["Earbuds", "Playstation", "iPhone"], | |
"Donia": ["Jewelry", "iPhone", "Perfume"], | |
"Samar": ["Perfume", "Playstation", "Earbuds"], | |
"Jameela": ["Earbuds", "Jewelry"], | |
"Sarah": ["Earbuds"] | |
} | |
# Assume the business preference of customers is: Layla, Donia, Samar, Jameela, Sarah | |
business_preferences = { | |
"Earbuds": [], | |
"Playstation": [], | |
"iPhone": [], | |
"Jewelry": [], | |
"Perfume": [] | |
} | |
for r in customers_preferences: | |
for h in customers_preferences[r]: | |
business_preferences[ h ].append(r) | |
#business_preferences | |
#{'Earbuds': ['Layla', 'Samar', 'Jameela', 'Sarah'], | |
# 'Playstation': ['Layla', 'Samar'], | |
# 'iPhone': ['Layla', 'Donia'], | |
# 'Jewelry': ['Donia', 'Jameela'], | |
# 'Perfume': ['Donia', 'Samar']} | |
items_quantity = { | |
"Earbuds": 2, | |
"Playstation": 3, | |
"iPhone": 5, | |
"Jewelry": 7, | |
"Perfume": 11 | |
} | |
game = HospitalResident.create_from_dictionaries( | |
customers_preferences, business_preferences, items_quantity | |
) | |
matching = game.solve(optimal="hospital") | |
#matching | |
#{Earbuds: [Layla, Jameela], Playstation: [], iPhone: [], Jewelry: [Donia], Perfume: [Samar]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment