Esempio n. 1
0
# Let's set up a dictionary that associates integer representations of our candidates with their names.
candMap = dict()
candMap[1] = "john"
candMap[2] = "jane"
candMap[3] = "jill"

# Now that we have this candidate mapping and a list of Preference objects, we can construct a 
# Profile object.
profile = Profile(candMap, preferences)

# Let's print the output of some of the Profile object's methods.
print(profile.getRankMaps())
print(profile.getWmg())
print(profile.getElecType())
print(profile.getReverseRankMaps())
print(profile.getOrderVectors())

# Now let's see which candidate would win an election were we to use the Plurality rule.

# First, we construct a Mechanism object
mechanism = mechanism.MechanismPlurality()

# Let's print the ouputs of some of the Mechanism object's methods.
print(mechanism.getWinners(profile))
print(mechanism.getMov(profile))

# We can also call margin of victory functions directly without constructing a mechanism object.
# Let's print the margin of victory using Borda rule.
print(mov.movBorda(profile))

# Now we are going to use MCMC sampling to approximate the Bayesian loss of each candiate.
Esempio n. 2
0
# Let's set up a dictionary that associates integer representations of our candidates with their names.
candMap = dict()
candMap[1] = "john"
candMap[2] = "jane"
candMap[3] = "jill"

# Now that we have this candidate mapping and a list of Preference objects, we can construct a
# Profile object.
profile = Profile(candMap, preferences)

# Let's print the output of some of the Profile object's methods.
print(profile.getRankMaps())
print(profile.getWmg())
print(profile.getElecType())
print(profile.getReverseRankMaps())
print(profile.getOrderVectors())

# Now let's see which candidate would win an election were we to use the Plurality rule.

# First, we construct a Mechanism object
mechanism = mechanism.MechanismPlurality()

# Let's print the ouputs of some of the Mechanism object's methods.
print(mechanism.getWinners(profile))
print(mechanism.getMov(profile))

# We can also call margin of victory functions directly without constructing a mechanism object.
# Let's print the margin of victory using Borda rule.
print(mov.movBorda(profile))

# Now we are going to use MCMC sampling to approximate the Bayesian loss of each candiate.
Esempio n. 3
0
if __name__ == '__main__':
    # Grab and read a file.
    # os.chdir('D:\Social Choice\data\soc-3-hardcase')
    os.chdir('D:\\Social Choice\\data\\toc')
    # inputfile = input("Input File: ")
    inputfile = "ED-00006-00000038.toc"
    # inputfile = "M30N30-233.csv"
    inf = open(inputfile, 'r')
    cmap, rmaps, rmapscounts, nvoters = prefpy_io.read_election_file(inf)
    print("cmap=",cmap)
    print("rmaps=",rmaps)
    print("rmapscounts=",rmapscounts)
    print("nvoters=",nvoters)
    profile = Profile(cmap, preferences=[])
    Profile.importPreflibFile(profile, inputfile)
    print(profile.getOrderVectors())
    print(profile.getPreferenceCounts())
    ordering = profile.getOrderVectors()
    rankmaps = profile.getRankMaps()
    print("rankmaps=",rankmaps)
    print(min(ordering[0]))
    # if(min(ordering[0])==0):
    #     print("ok")
    # else:
    #     print("not ok")

    stvwinners = mechanism.MechanismSTV().STVwinners(profile)
    print("stvwinners=", stvwinners)
    baldwinners = mechanism.MechanismBaldwin().baldwin_winners(profile)
    print("baldwinners=", baldwinners)
    coombswinners = mechanism.MechanismCoombs().coombs_winners(profile)