def test_IC(num_cand, num_voters, setsize): random.seed(0) profile = genprofiles.random_IC_profile(num_cand, num_voters, setsize) 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
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) break except ValueError: pass output(profile, "random_urn_party_list") profile = genprofiles.random_IC_profile(num_cand, 5, 4) output(profile, "random_IC") profile = genprofiles.random_IC_party_list_profile(num_cand, 5, 2, uniform=True) output(profile, "random_IC_party_list") profile = genprofiles.random_mallows_profile(num_cand, 4, 4, 0.7) output(profile, "random_mallows") while True: profile = genprofiles.random_2d_points_profile(num_cand, 4, "twogroups", "uniform_square", 0.5, 1.9) try: