daffidwilde/matching

ValueError when re-running a StableMarriage game

igarizio opened this issue · 0 comments

Hi!
I get a ValueError when solving a StableMarriage game and then trying to define it again.
My guess is that when solving the game for the first time, the preferences of some players get modified.

Code to reproduce:

This comes from the example on the README.

from matching import Player
from matching.games import StableMarriage

suitors = [Player(name="A"), Player(name="B"), Player(name="C")]
reviewers = [Player(name="D"), Player(name="E"), Player(name="F")]
(A, B, C), (D, E, F) = suitors, reviewers

A.set_prefs([D, E, F])
B.set_prefs([D, F, E])
C.set_prefs([F, D, E])
D.set_prefs([B, C, A])
E.set_prefs([A, C, B])
F.set_prefs([C, B, A])

game = StableMarriage(suitors, reviewers)
game.solve()
game = StableMarriage(reviewers, suitors)

Error:

ValueError                                Traceback (most recent call last)
<ipython-input-167-6774ac393861> in <module>
----> 1 game = StableMarriage(reviewers, suitors)

C:\ProgramData\Anaconda3\lib\site-packages\matching\games\stable_marriage.py in __init__(self, suitors, reviewers)
     35 
     36         super().__init__()
---> 37         self._check_inputs()
     38 
     39     @classmethod

C:\ProgramData\Anaconda3\lib\site-packages\matching\games\stable_marriage.py in _check_inputs(self)
    131         self._check_num_players()
    132         for suitor in self.suitors:
--> 133             self._check_player_ranks(suitor)
    134         for reviewer in self.reviewers:
    135             self._check_player_ranks(reviewer)

C:\ProgramData\Anaconda3\lib\site-packages\matching\games\stable_marriage.py in _check_player_ranks(self, player)
    151         if set(player.prefs) != set(others):
    152             raise ValueError(
--> 153                 "Every player must rank each name from the other group. "
    154                 f"{player}: {player.prefs} != {others}"
    155             )

ValueError: Every player must rank each name from the other group. D: [B] != [A, B, C]

Package version: 1.2.1

Thanks!