(rule_id, resolute, committeesize, approval_sets, modvote, commsfirst, commsafter) = manip print(misc.header(abcrules.get_rule(rule_id).longname, "-")) profile = Profile(num_cand, cand_names=cand_names) profile.add_voters(approval_sets) truepref = profile[0].approved print(profile.str_compact()) committees = abcrules.compute(rule_id, profile, committeesize, resolute=resolute) print("original winning committees:\n" + misc.str_sets_of_candidates(committees, cand_names)) # verify correctness assert committees == commsfirst print("Manipulation by voter 0: " + misc.str_set_of_candidates(approval_sets[0], cand_names) + " --> " + misc.str_set_of_candidates(modvote, cand_names)) if not all(cand in truepref for cand in modvote): print(" (not a subset!)") approval_sets[0] = modvote profile = Profile(num_cand, cand_names=cand_names) profile.add_voters(approval_sets) committees = abcrules.compute(rule_id,
# Write a profile to toi file profile = Profile(5, "ABCDE") profile.add_voters([{0, 1}, {1, 3, 4}, {2}, {3}, {3}]) fileio.write_profile_to_preflib_toi_file(profile, currdir + "/toi-files/new_example.toi") # Read a directory of preflib files (using parameter relative_setsize) profiles = fileio.read_preflib_files_from_dir(currdir + "/toi-files/", relative_setsize=0.7) # Compute PAV for each profile committeesize = 2 for profile in profiles.values(): 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_sets_of_candidates(committees)) print("****************************************") # Read a preflib file (using parameter setsize) profile = fileio.read_preflib_file(currdir + "/toi-files/example.toi", setsize=1) # Compute Phragmen's sequential rule for this profile 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_sets_of_candidates(committees)) print("****************************************")