Check the status of a matching

Verifying the validity and stability of a matching is paramount in any matching game. In matching this is done by creating an instance of a game and using the check_validity and check_stability methods of the instance.

Consider the following instance of SA.

from matching.games import StudentAllocation

student_preferences = {
    "A": ["X1", "X2"],
    "B": ["Y2", "X1"],
    "C": ["X1", "Y1"],
    "D": ["Y2", "Y1"],
}

supervisor_preferences = {"X": ["C", "A", "B"], "Y": ["C", "D", "B"]}

project_supervisors = {"X1": "X", "X2": "X", "Y1": "Y", "Y2": "Y"}
project_capacities = {project: 1 for project in project_supervisors}
supervisor_capacities = {
    supervisor: 2 for supervisor in supervisor_preferences
}


game = StudentAllocation.create_from_dictionaries(
    student_preferences,
    supervisor_preferences,
    project_supervisors,
    project_capacities,
    supervisor_capacities,
)

An easy way to get a matching is just to solve the game. From there we can verify the status of the current matching.

game.solve()

game.check_validity(), game.check_stability()
(True, True)