resident_prefs = {
"A": ["C"],
"S": ["C", "M"],
"D": ["C", "M", "G"],
"J": ["C", "G", "M"],
"L": ["M", "C", "G"],
}
hospital_prefs = {
"M": ["D", "L", "S", "J"],
"C": ["D", "A", "S", "L", "J"],
"G": ["D", "J", "L"],
}Remove banned pairs
Sometimes you may wish to ban certain pairs of players from a matching. This can be done by removing them from the game all together.
Consider the following preferences from an instance of HR.
The pairs to be removed can be described as a list of hospital-resident tuples. This list needs to be iterated, and the preferences updated.
banned_pairs = [("M", "L"), ("C", "J")]
for hospital, resident in banned_pairs:
hprefs = hospital_prefs[hospital]
rprefs = resident_prefs[resident]
if resident in hprefs:
hprefs.remove(resident)
hospital_prefs[hospital] = hprefs
if hospital in rprefs:
rprefs.remove(hospital)
resident_prefs[resident] = rprefsresident_prefs, hospital_prefs({'A': ['C'],
'S': ['C', 'M'],
'D': ['C', 'M', 'G'],
'J': ['G', 'M'],
'L': ['C', 'G']},
{'M': ['D', 'S', 'J'], 'C': ['D', 'A', 'S', 'L'], 'G': ['D', 'J', 'L']})