Exemplo n.º 1
0
def test_seqphragmen_fails_ejr():
    # seq-Phragmen fails Extended Justified Representation
    # from "Phragmén's Voting Methods and Justified Representation"
    # by Markus Brill, Rupert Freeman, Svante Janson and Martin Lackner

    num_cand = 14
    # candidates
    a, b, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12 = list(range(num_cand))
    # reversed because c should be removed first in case of ties
    profile = Profile(num_cand)
    profile.add_voters([{a, b, c1}] * 2)
    profile.add_voters([{a, b, c2}] * 2)
    profile.add_voters([{c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12}] * 6)
    profile.add_voters([{c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12}] * 5)
    profile.add_voters([{c3, c4, c5, c6, c7, c8, c9, c10, c11, c12}] * 9)
    assert len(profile) == 24
    assert abcrules.compute_seqphragmen(profile, 12) == [
        {c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12}
    ]
Exemplo n.º 2
0
committeesize = 2

# directory of preflib.py
currdir = os.path.dirname(os.path.abspath(__file__))

profiles = fileio.load_preflib_files_from_dir(currdir + "/toi-files/",
                                              appr_percent=0.7)

for profile in profiles:
    print("Computing a committee of size", committeesize, end=' ')
    print("with the Proportional Approval Voting (PAV) rule")
    print("given a", profile)
    print("Output:")
    committees = abcrules.compute_pav(profile, committeesize)
    print(str_candsets(committees))
    print("****************************************")


# Example to read a single file (parameter setsize)
profile = fileio.read_preflib_file(
    currdir + "/toi-files/ex_2010.toi", setsize=1)

print("Computing a committee of size", committeesize, end=' ')
print("with Phragmen's sequential rule")
print("given a", profile)
print("Output:")
committees = abcrules.compute_seqphragmen(profile, committeesize)
print(str_candsets(committees))
print("****************************************")
Exemplo n.º 3
0
from abcvoting.output import output
from abcvoting.output import DETAILS

output.set_verbosity(DETAILS)

print(misc.header("Example 12", "*"))

# Approval profile
num_cand = 4
a, b, c, d = range(4)
approval_sets = [{c, d}, {c, d}, {c, d}, {a, b}, {a, b}, {a, c}, {a, c}, {b, 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())

committees_equal_shares = abcrules.compute_equal_shares(
    profile, 3, resolute=True, algorithm="standard-fractions"
)

committees_seqphragmen = abcrules.compute_seqphragmen(
    profile, 3, resolute=True, algorithm="standard-fractions"
)

# verify correctness
assert committees_equal_shares == [{a, c, d}]
assert committees_seqphragmen == [{b, c, d}]
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
"""Example 8 (seq-Phragmen)
from the survey: "Approval-Based Multi-Winner Voting:
Axioms, Algorithms, and Applications"
by Martin Lackner and Piotr Skowron
"""

from abcvoting import abcrules
from examples.abcsurvey import example01 as ex1
from abcvoting import misc
from abcvoting.output import output
from abcvoting.output import DETAILS

output.set_verbosity(DETAILS)

print(misc.header("Example 8", "*"))

print(misc.header("Input (election instance from Example 1):"))
print(ex1.profile.str_compact())

committees = abcrules.compute_seqphragmen(ex1.profile,
                                          4,
                                          algorithm="standard-fractions")

# verify correctness
a, b, c, d, e, f, g = range(7)  # a = 0, b = 1, c = 2, ...
assert committees == [{a, b, c, d}]
Exemplo n.º 5
0
# Approval profile
num_cand = 5
a, b, c, d, e = list(range(5))
# apprsets = [[a, b, c]] * 5 + [[a, b, c, d, e]] * 5 + [[a, b, d, e]] * 2 + [[d, e]] * 3
# apprsets = [[a, b]] + [[a, b, c]] * 3 + [[a, b, c, d, e]] * 5 + [[d, e]] * 2 + [[d]]
apprsets = [[a, b, c]] * 6 + [[a, b, c, d, e]] * 4 + [[a, b, d, e]
                                                      ] * 2 + [[d, e]] * 3
# apprsets = [[a, b, c]] * 5 + [[a, b, c, e]] + [[a, b, c, d, e]] * 4 + [[a, b, d, e]] * 2 + [[d, e]] * 2 + [[d]]
names = "abcde"

profile = Profile(num_cand, names=names)
profile.add_preferences(apprsets)

print(misc.header("Input:"))
print(profile.str_compact())

committees_rule_x = abcrules.compute_rule_x(profile,
                                            4,
                                            resolute=False,
                                            verbose=2)

committees_seqphragmen = abcrules.compute_seqphragmen(profile,
                                                      4,
                                                      resolute=False,
                                                      verbose=1)

# verify correctness
assert committees_rule_x == [[a, b, c, d], [a, b, c, e]]
assert committees_seqphragmen == [[a, b, d, e]]