Exemplo n.º 1
0
def dump_vote(votes):
    counts = Counter(tuple(v) for v in votes)
    counts = list(counts.items())
    counts.sort(key=lambda x: (-x[1], x[0]))
    print("\\begin{itemize}")
    for vote, n in counts:
        grade = []
        k = len(vote)
        for i, c in enumerate(vote):
            base = "%s as %d" % (name(i), c)
            if i == k - 1:
                base = "and " + base
            grade.append(base)
        grade = ', '.join(grade)
        if n > 1:
            print("\item %d voters grade %s" % (n, grade))
        else:
            print("\item 1 voter grades %s" % (grade, ))
    print("\\end{itemize}")
Exemplo n.º 2
0
        if condorcet_winner(votes) != pl:
            return False
        return irv_winner(votes) != pl
    except Ambiguous:
        return False


if __name__ == '__main__':
    from vbe.construction import find_election
    print(find_election(irv_sucks))

    import sys; sys.exit(0)

    from vbe.construction import find_election
    from vbe.output import output_election, name

    result = find_election(key_irv_example, 4)

    print("\n------------\n")
    print(result)
    print("\n------------\n")

    output_election(result, 1)

    print()
    print("The Plurality winner is %s." % (name(plurality_winner(result)),))
    print()
    print("The IRV winner is %s." % (name(irv_winner(result)),))
    print()
    print("The Condorcet winner is %s." % (name(condorcet_winner(result)),))
Exemplo n.º 3
0
    a, b = candidates
    if new_scores[a] == new_scores[b]:
        raise Ambiguous()
    return max((a, b), key=new_scores.__getitem__)


def is_not_two_round(votes):
    try:
        return supplementary_winner(votes) != simple_irv_winner(votes)
    except Ambiguous:
        return False


if __name__ == '__main__':
    from vbe.output import output_election, name
    from vbe.construction import find_election

    result = find_election(is_not_two_round)

    print("\n------------\n")
    print(result)
    print("\n------------\n")

    output_election(result, 1)

    print()
    print("The Simple IRV winner is %s." % (name(simple_irv_winner(result)), ))
    print()
    print("The Supplementary winner is %s." %
          (name(supplementary_winner(result)), ))
Exemplo n.º 4
0
    from vbe.output import output_votes, name, joined_list

    result = non_condorcet_splitter

    winner = list(stv(result, 1))[0]
    house = sorted(stv(result, 2))
    assert len(house) == 2

    assert winner != condorcet_winner(non_condorcet_splitter)

    print("\n------------\n")
    print(result)
    print("\n------------\n")

    print("%d voters are choosing between %d candidates: %s." %
          (len(result), len(result[0]), joined_list(sorted(result[0]))))
    print()

    output_votes(result)

    print()

    print(("The IRV winner is %s, but when electing two candidates "
           "we elect %s and %s") %
          (name(winner), name(house[0]), name(house[1])))

    print()

    print("Note that despite this the Condorcet winner is %s, not %s." %
          (name(condorcet_winner(result)), name(winner)))
Exemplo n.º 5
0
        if n > 1:
            print("\item %d voters grade %s" % (n, grade))
        else:
            print("\item 1 voter grades %s" % (grade, ))
    print("\\end{itemize}")


if __name__ == '__main__':
    print("The first one demonstrates all three approaches producing a "
          "different result:")

    dump_vote(all_results_distinct)
    print(
        ("The Condorcet winner is %s, but the Majority Judgment winner is %s, "
         "and the range winner is %s.") % (
             name(condorcet_winner(all_results_distinct)),
             name(mj_winner(all_results_distinct)),
             name(range_winner(all_results_distinct)),
         ))

    print("It's also possible for any two of them to coincide and disagree "
          "with the third.")

    print()

    print("The following shows an example where majority jugment and range "
          "voting agree on a candidate, but it's not the Condorcet winner.")

    dump_vote(disagree_with_condorcet)
    print(("The Condorcet winner is %s, but the Majority Judgment and range "
           "winner is %s.") % (