= {
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.
= [("M", "L"), ("C", "J")]
banned_pairs for hospital, resident in banned_pairs:
= hospital_prefs[hospital]
hprefs = resident_prefs[resident]
rprefs
if resident in hprefs:
hprefs.remove(resident)= hprefs
hospital_prefs[hospital] if hospital in rprefs:
rprefs.remove(hospital)= rprefs resident_prefs[resident]
resident_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']})