def read_profile(inputfile): inf = open(inputfile, 'r') cmap, rmaps, rmapscounts, nvoters = prefpy_io.read_election_file(inf) inf.close() profile = Profile(cmap, preferences=[]) Profile.importPreflibFile(profile, inputfile) # Currently, we expect the profile to contain complete ordering over candidates. Ties are allowed however. elecType = profile.getElecType() if elecType != "soc" and elecType != "soi" and elecType != "csv": print("ERROR: unsupported election type") exit() return profile
print('***************NOT STARTING FROM DEFAULT*********************') agent = RP_RL_agent(model) print("inputfile\tPUT-winners\tnum nodes\tdiscovery states\tmax discovery state\tdiscovery times\tmax discovery times\tstop condition hits\tsum stop cond hits\tnum hashes\tnum initial bridges\tnum redundant edges\tnum sampled\tsampled\tsamples discovered\tmax sample discovery\truntime") for inputfile in filenames: inf = open(inputfile, 'r') cmap, rmaps, rmapscounts, nvoters = prefpy_io.read_election_file(inf) inf.close() profile = Profile(cmap, preferences=[]) Profile.importPreflibFile(profile, inputfile) # Currently, we expect the profile to contain complete ordering over candidates. Ties are allowed however. elecType = profile.getElecType() if elecType != "soc" and elecType != "soi" and elecType != "csv": print("ERROR: unsupported election type") exit() start = time.perf_counter() rp_results = MechanismRankedPairs().outer_loop_lp(profile, agent) end = time.perf_counter() PUT_winners = rp_results[0] stats = rp_results[1] samples_discovered = rp_results[2] max_discovery_state = max(stats.discovery_states.values()) max_discovery_time = max(stats.discovery_times.values()) num_stop_condition_hits = sum(list(stats.stop_condition_hits.values())) max_sample = max(samples_discovered.values())
preferences.append(preference2) # 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))