def test_stable_marriage_produces_symmetric_matchings(caplog, build_func, searches): caplog.set_level(logging.INFO) ranks = build_func(searches) matches = algorithm.StableMarriage().find(ranks) for search in matches: opponent = matches[search] assert matches[opponent] == search
def test_stable_marriage_unmatch(player_factory): s1 = Search([player_factory(503, 64, name="p1")]) s2 = Search([player_factory(504, 64, name="p2")]) s3 = Search([player_factory(504, 64, name="p3")]) s4 = Search([player_factory(505, 64, name="p4")]) searches = [s1, s2, s3, s4] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[s1] == s4 # quality: 0.96622 assert matches[s2] == s3 # quality: 0.96623
def test_stable_marriage_unmatch(p): s1 = Search([p(503, 64, name='p1')]) s2 = Search([p(504, 64, name='p2')]) s3 = Search([p(504, 64, name='p3')]) s4 = Search([p(505, 64, name='p4')]) searches = [s1, s2, s3, s4] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[s1] == s4 # quality: 0.96622 assert matches[s2] == s3 # quality: 0.96623
def test_stable_marriage_matches_new_players_with_new_and_old_with_old_if_different_mean( player_factory): new1 = Search([player_factory(1500, 500, name="new1", ladder_games=1)]) new2 = Search([player_factory(1400, 500, name="new2", ladder_games=2)]) old1 = Search([player_factory(2300, 75, name="old1", ladder_games=100)]) old2 = Search([player_factory(2350, 75, name="old2", ladder_games=200)]) searches = [new1, new2, old1, old2] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[new1] == new2 assert matches[old1] == old2
def test_stable_marriage_matches_new_players_with_new_and_old_with_old_if_same_mean( player_factory): # Assumes that both new players initialized with mean 1500 will be matched # as if they had mean 500 new1 = Search([player_factory(1500, 500, name="new1", ladder_games=0)]) new2 = Search([player_factory(1500, 500, name="new2", ladder_games=0)]) old1 = Search([player_factory(500, 75, name="old1", ladder_games=100)]) old2 = Search([player_factory(500, 75, name="old2", ladder_games=100)]) searches = [new1, new2, old1, old2] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[new1] == new2 assert matches[old1] == old2
def test_stable_marriage(player_factory): s1 = Search([player_factory(2300, 64, name="p1")]) s2 = Search([player_factory(1200, 72, name="p2")]) s3 = Search([player_factory(1300, 175, name="p3")]) s4 = Search([player_factory(2350, 125, name="p4")]) s5 = Search([player_factory(1200, 175, name="p5")]) s6 = Search([player_factory(1250, 175, name="p6")]) searches = [s1, s2, s3, s4, s5, s6] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[s1] == s4 assert matches[s2] == s5 assert matches[s3] == s6
def test_stable_marriage(p): s1 = Search([p(2300, 64, name='p1')]) s2 = Search([p(1200, 72, name='p2')]) s3 = Search([p(1300, 175, name='p3')]) s4 = Search([p(2350, 125, name='p4')]) s5 = Search([p(1200, 175, name='p5')]) s6 = Search([p(1250, 175, name='p6')]) searches = [s1, s2, s3, s4, s5, s6] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) assert matches[s1] == s4 assert matches[s2] == s5 assert matches[s3] == s6
def test_stable_marriage_better_than_greedy(player_factory): s1 = Search([player_factory(2300, 64, name="p1")]) s2 = Search([player_factory(2000, 64, name="p2")]) s3 = Search([player_factory(2100, 64, name="p3")]) s4 = Search([player_factory(2200, 64, name="p4")]) s5 = Search([player_factory(2300, 64, name="p5")]) s6 = Search([player_factory(2400, 64, name="p6")]) searches = [s1, s2, s3, s4, s5, s6] ranks = algorithm._MatchingGraph.build_full(searches) matches = algorithm.StableMarriage().find(ranks) # Note that the most balanced configuration would be # (s1, s6) quality: 0.93 # (s2, s3) quality: 0.93 # (s4, s5) quality: 0.93 # However, because s1 is first in the list and gets top choice, we end with # the following stable configuration assert matches[s1] == s5 # quality: 0.97 assert matches[s2] == s3 # quality: 0.93 assert matches[s4] == s6 # quality: 0.82