def test_revseqpav_fails_EJR(sizemultiplier): # from "A Note on Justified RepresentationUnder the Reverse Sequential PAV rule" # by Haris Aziz # Proposition 2 for k=5 num_cand = 12 # candidates c, x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5 = reversed(list(range(num_cand))) # reversed because c should be removed first in case of ties profile = Profile(num_cand) profile.add_voters([{c, x1, x3, x5}] * 4 * sizemultiplier) profile.add_voters([{c, x2, x4, x6}] * 4 * sizemultiplier) profile.add_voters([{x1}, {x2}, {x3}, {x4}, {x5}, {x6}] * sizemultiplier) profile.add_voters([[y1, y2, y3, y4, y5]] * 26 * sizemultiplier) assert len(profile) == 40 * sizemultiplier assert abcrules.compute_revseqpav(profile, 5) == [{y1, y2, y3, y4, y5}]
a, b, c, d = range(4) # a = 0, b = 1, c = 2, ... cand_names = "abcd" approval_sets = [[a, b]] * 3 + [[a, d]] * 6 + [[b]] * 4 + [[c]] * 5 + [[c, d] ] * 5 profile = Profile(num_cand, cand_names=cand_names) profile.add_voters(approval_sets) print(misc.header("Input:")) print(profile.str_compact()) committees_pav = abcrules.compute_pav(profile, 2) committees_seqpav = abcrules.compute_seqpav(profile, 2) committees_revseqpav = abcrules.compute_revseqpav(profile, 2) # verify correctness assert committees_pav == [{a, c}] assert committees_seqpav == [{c, d}] assert committees_revseqpav == [{c, d}] print("\n") print(misc.header("Example from Janson's survey (Example 13.3) / Thiele:", "*")) # Approval profile num_cand = 4 a, b, c, d = range(4) # a = 0, b = 1, c = 2, ... cand_names = "abcd"
""" from __future__ import print_function import sys sys.path.insert(0, '../..') from abcvoting import abcrules from abcvoting.preferences import Profile from abcvoting import misc print("Remark 3:\n*********\n") # Approval profile num_cand = 4 a = 0 b = 1 c = 2 d = 3 apprsets = [[a, b], [a, b, d], [a, b, c], [a, c, d], [a, c, d], [b], [c], [d]] names = "abcd" profile = Profile(num_cand, names=names) profile.add_preferences(apprsets) print(misc.header("Input:")) print(profile.str_compact()) committees = abcrules.compute_revseqpav(profile, 1, resolute=False, verbose=1) committees = abcrules.compute_av(profile, 1, verbose=1)
from abcvoting.output import INFO from abcvoting.output import output from abcvoting import abcrules from abcvoting.preferences import Profile from abcvoting import misc output.set_verbosity(INFO) print("Remark 3:\n*********\n") # Approval profile num_cand = 4 a = 0 b = 1 c = 2 d = 3 approval_sets = [[a, b], [a, b, d], [a, b, c], [a, c, d], [a, c, d], [b], [c], [d]] cand_names = "abcd" profile = Profile(num_cand, cand_names=cand_names) profile.add_voters(approval_sets) print(misc.header("Input:")) print(profile.str_compact()) abcrules.compute_revseqpav(profile, 1, resolute=False) abcrules.compute_av(profile, 1)