def test_monroe_indivisible(algorithm): profile = Profile(4) profile.add_voters([[0], [0], [0], [1, 2], [1, 2], [1], [3]]) committeesize = 3 assert abcrules.compute_monroe( profile, committeesize, algorithm=algorithm, resolute=False ) == [{0, 1, 2}, {0, 1, 3}, {0, 2, 3}]
def test_monroe_indivisible(algorithm): if algorithm == "gurobi": pytest.importorskip("gurobipy") profile = Profile(4) profile.add_preferences([[0], [0], [0], [1, 2], [1, 2], [1], [3]]) committeesize = 3 assert (abcrules.compute_monroe(profile, committeesize, algorithm=algorithm, resolute=False) == [[0, 1, 2], [0, 1, 3], [0, 2, 3]])
def test_pareto_optimality_methods(algorithm): # profile with 4 candidates: a, b, c, d profile = Profile(4) # add voters in the profile profile.add_voters([[0]] * 2 + [[0, 2]] + [[0, 3]] + [[1, 2]] * 10 + [[1, 3]] * 10) # compute output committee from Monroe's Rule monroe_output = abcrules.compute_monroe(profile, 2) # Monroe's Rule should output winning committee {2, 3} for this input # It is not Pareto optimal because it is dominated by committee {0, 1} # Check using the methods is_pareto_optimal = properties.check_pareto_optimality(profile, monroe_output[0], algorithm=algorithm) assert monroe_output == [{2, 3}] assert abcvoting.misc.dominate(profile, {0, 1}, {2, 3}) assert not is_pareto_optimal assert properties.check_pareto_optimality(profile, {0, 1}, algorithm=algorithm)
{a, b}, {a, c}, {a, c}, {a, c}, {a, d}, {a, d}, {b, c, f}, {e}, {f}, {g}, ] profile = Profile(num_cand, cand_names="abcdefgh") profile.add_voters(approval_sets) committeesize = 4 # print(misc.header("Example 7", "*")) print(misc.header("Input (election instance from Example 1):")) print(profile.str_compact()) committees = abcrules.compute_monroe(profile, 4) # verify correctness a, b, c, d, e, f, g = range(7) # a = 0, b = 1, c = 2, ... assert len(committees) == 6 # Monroe-score of all committees is the same score = monroescore(profile, committees[0]) for committee in committees: assert score == monroescore(profile, committee)