def test_urn(num_cand, num_voters, setsize, replace): random.seed(0) profile = genprofiles.random_urn_profile(num_cand, num_voters, setsize, replace) assert len(profile) == num_voters assert profile.num_cand == num_cand for voter in profile: assert len(voter.approved) == setsize
def generate_profile(num_voters, num_cand, committeesize, prob_distribution, setsize): while True: if prob_distribution == "IC": profile = genprofiles.random_IC_profile(num_cand, num_voters, setsize) elif prob_distribution.startswith("Mallows"): dispersion = float(prob_distribution[7:]) profile = genprofiles.random_mallows_profile(num_cand, num_voters, setsize, dispersion=dispersion) elif prob_distribution.startswith("Urn"): replace = float(prob_distribution[3:]) profile = genprofiles.random_urn_profile(num_cand, num_voters, setsize, replace=replace) elif prob_distribution == "IC-party": profile = genprofiles.random_IC_party_list_profile(num_cand, num_voters, num_parties=3) else: raise ValueError try: check_enough_approved_candidates(profile, committeesize) return profile except ValueError: pass
def output(prof, gen_profile_name): print("Randomly generated profile via " + gen_profile_name + ":") print(str(prof)) print("****************************************") """ For some methods, it might happen that fewer than committeesize many candidates are approved (in total by all voters). We thus recommended to verify this before computing the rule. """ while True: profile = genprofiles.random_urn_profile(num_cand, 5, 2, 0.4) try: check_enough_approved_candidates(profile, committeesize) break except ValueError: pass output(profile, "random_urn") while True: profile = genprofiles.random_urn_party_list_profile(num_cand, 3, 2, 0.4, uniform=False) try: check_enough_approved_candidates(profile, committeesize)