Beispiel #1
0
print(misc.header("Example 5", "*"))

# Approval profile
num_cand = 4
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

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("****************************************")
Beispiel #3
0
"""Example 4 (PAV)
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 4", "*"))

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

committees = abcrules.compute_pav(ex1.profile, 4)

# verify correctness
a, b, c, d, e, f, g = range(7)  # a = 0, b = 1, c = 2, ...
assert committees == [{a, b, c, f}]
Beispiel #4
0
"""Example 4 (PAV)
from the survey: "Approval-Based Multi-Winner Voting:
Axioms, Algorithms, and Applications"
by Martin Lackner and Piotr Skowron
"""

from __future__ import print_function
import sys
sys.path.insert(0, '..')
from abcvoting import abcrules
from survey import example01 as ex1
from abcvoting import misc

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

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

committees = abcrules.compute_pav(ex1.profile, 4, verbose=2)

# verify correctness
a, b, c, d, e, f, g = list(range(7))  # a = 0, b = 1, c = 2, ...
assert committees == [[a, b, c, f]]
Beispiel #5
0
print(misc.header("Example 5", "*"))

# Approval profile
num_cand = 4
a, b, c, d = list(range(4))  # a = 0, b = 1, c = 2, ...
names = "abcd"

apprsets = [[a, b]] * 3 + [[a, d]] * 6 + [[b]] * 4 + [[c]] * 5 + [[c, d]] * 5
profile = Profile(num_cand, names=names)
profile.add_preferences(apprsets)

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

committees_pav = abcrules.compute_pav(profile, 2, verbose=2)

committees_seqpav = abcrules.compute_seqpav(profile, 2, verbose=2)

committees_revseqpav = abcrules.compute_revseqpav(profile, 2, verbose=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:", "*"))