예제 #1
0
def non_d_condrcet(candidate_num, voter_num):
    """
    :param candidate_num:
    :param voter_num:
    :return: A 2D list of preference order votes that does NOT include condorcet winners. It uses copeland rule.
    """
    while True:
        ballots = impartial_culture(candidate_num, voter_num)
        is_condorcet_profile = is_condorcet_winner(
            copeland.count_in_copeland(ballots))
        if not is_condorcet_profile:
            return ballots
예제 #2
0
def get_condorcet_winner_count(candidate_num, voter_num, iteration):
    condorce_winner_count = 0
    for i in range(iteration):
        ballots = impartial_culture(candidate_num, voter_num)
        # print("Ballots:"+str(ballots))
        # print("-----------------------------------------------")
        # print("Result (Copeland) :", str(count_in_copeland(ballots)))
        found_condorcet_winner = is_condorcet_winner(
            count_in_copeland(ballots))
        # print("Condorcet winner? :", found_condorcet_winner)
        if found_condorcet_winner:
            condorce_winner_count += 1
        # print("-----------------------------------------------")
    return condorce_winner_count
def experiment(candidate_num, voter_num, iteration, buffer: DataPointBuffer):
    indentical_borda_plurality = 0
    indentical_copeland_plurality = 0
    indentical_copeland_borda = 0
    indentical_all = 0
    for i in range(iteration):
        #Get profile that does not have condorcet winner
        ballots = non_d_condrcet(candidate_num, voter_num)
        # print("------------------------")
        #     + "Profile(Voter="+str(len(ballots))+"):", str(ballots))

        copeland_winners = get_winners(copeland.count_in_copeland(ballots))
        copeland_winners.sort()

        borda_winners = get_winners(borda.count_in_borda(ballots))
        borda_winners.sort()

        plurality_winners = get_winners(plurality.count_in_plurality(ballots))
        plurality_winners.sort()

        #Count how many times all the rules elect the same candidates
        copeland_plurality_indentical_flag = False
        if is_indentical(copeland_winners, plurality_winners):
            indentical_copeland_plurality += 1
            copeland_plurality_indentical_flag = True

        if is_indentical(borda_winners, plurality_winners):
            indentical_borda_plurality += 1
            # Count up if all the rules yield the same result.
            if copeland_plurality_indentical_flag == True:
                indentical_all += 1

        if is_indentical(copeland_winners, borda_winners):
            indentical_copeland_borda += 1

        # print("Copeland winners : " + str(copeland_winners) + "\n"
        #     + "Borda winners    : " + str(borda_winners)+ "\n"
        #     + "Plurality winners: " + str(plurality_winners))

    buffer.write(
        str(candidate_num), str(voter_num),
        str(indentical_copeland_plurality) + "," +
        str(indentical_borda_plurality) + "," +
        str(indentical_copeland_borda) + "," + str(indentical_all))
def experiment(candidate_num, voter_num, iteration, buffer: DataPointBuffer):
    count = 0
    for i in range(iteration):
        ballots = d_condorcet(candidate_num, voter_num)
        # print("------------------------")
        # print("Profile(Voter="+str(len(ballots))+"):", str(ballots))

        #Get the condorcet winner using copeland
        condorcet_winner_list = get_winners(
            copeland.count_in_copeland(ballots))
        if len(condorcet_winner_list) > 1:
            raise Exception(
                "There should not be more than one condorcet winner")
        condorcet_winner = condorcet_winner_list[0]
        # print(" Condorcet winner : " + str(condorcet_winner_list))

        #Check if Plurality chooses the condorcet winner
        plurality_winners = get_winners(plurality.count_in_plurality(ballots))
        # print(" Plurality winners: " + str(plurality_winners))
        if condorcet_winner in plurality_winners:
            count += 1
    buffer.write(str(candidate_num), str(voter_num), str(count))
def experiment(candidate_num, voter_num, iteration, buffer: DataPointBuffer):
    count = 0
    for i in range(iteration):
        ballots = d_condorcet(candidate_num, voter_num)
        print("------------------------")
        print("Profile(Voter=" + str(len(ballots)) + "):", str(ballots))

        #Get the condorcet winner using copeland
        condorcet_winner_list = get_winners(
            copeland.count_in_copeland(ballots))
        if len(condorcet_winner_list) > 1:
            raise Exception(
                "There should not be more than one condorcet winner")
        condorcet_winner = condorcet_winner_list[0]
        print(" Condorcet winner: " + str(condorcet_winner_list))

        #Check if Borda chooses the condorcet winner
        borda_winners = get_winners(borda.count_in_borda(ballots))
        print(" Borda winners   : " + str(borda_winners))
        if condorcet_winner in borda_winners:
            count += 1
    buffer.write(str(candidate_num), str(voter_num), str(count))
    print("Usng D-Condorcet profile, Borda chose Condorcet winners " +
          str(count) + "/" + str(iteration) + " times.")
    #     + "All rules macth           :" + str(indentical_all) + "/" + str(iteration) + " times" + "\n")


if __name__ == '__main__':
    candidate_num = 10
    voter_num = 10000
    experiment_iterations = 100

    count = 0
    for i in range(experiment_iterations):
        #Get profile that does not have condorcet winner
        ballots = non_d_condrcet(candidate_num, voter_num)
        print("------------------------")
        print("Profile(Voter=" + str(len(ballots)) + "):", str(ballots))

        copeland_winners = get_winners(copeland.count_in_copeland(ballots))
        copeland_winners.sort()

        borda_winners = get_winners(borda.count_in_borda(ballots))
        borda_winners.sort()

        plurality_winners = get_winners(plurality.count_in_plurality(ballots))
        plurality_winners.sort()

        #Count how many times all the rules elect the same candidates
        if is_indentical(copeland_winners, borda_winners):
            if is_indentical(copeland_winners, plurality_winners):
                count += 1

        print("Copeland winners : " + str(copeland_winners))
        print("Borda winners    : " + str(borda_winners))
    #     + "(Candidates="+str(candidate_num)+ ",Voters=" +str(voter_num))


if __name__ == '__main__':
    candidate_num = 4
    voter_num = 5
    experiment_interation = 100

    count = 0
    for i in range(experiment_interation):
        ballots = d_condorcet(candidate_num, voter_num)
        print("------------------------")
        print("Profile(Voter=" + str(len(ballots)) + "):", str(ballots))

        #Get the condorcet winner using copeland
        condorcet_winner_list = get_winners(
            copeland.count_in_copeland(ballots))
        if len(condorcet_winner_list) > 1:
            raise Exception(
                "There should not be more than one condorcet winner")
        condorcet_winner = condorcet_winner_list[0]
        print(" Condorcet winner : " + str(condorcet_winner_list))

        #Check if Plurality chooses the condorcet winner
        plurality_winners = get_winners(plurality.count_in_plurality(ballots))
        print(" Plurality winners: " + str(plurality_winners))
        if condorcet_winner in plurality_winners:
            count += 1
    print("Usng D-Condorcet profile, Plurality chose Condorcet winners " +
          str(count) + "/" + str(experiment_interation) + " times.")