def ordinal_multi_winner(): global k, candidates, sntv, committee_sntv, borda, committe_borda, bloc, committee_bloc, pav, committee_PAV, drop_down_list_orders k = 4 # Committe size orders = ordinal_randomizer(4, 4, 4) candidates = range(0, 4) preferences = [Ordinal(o) for o in orders] preferences_for_PAV = [Approval(a) for a in orders] print("Instances: " + str(orders)) profile = Profile(candidates, preferences) Profile_approval_for_PAV = Profile(candidates, preferences_for_PAV) sntv = SNTV() committee_sntv = sntv.find_committee(k, profile) print(str("Committee by SNTV rule:") + " " + str(committee_sntv)) borda = Borda() committe_borda = borda.find_committee(k, profile) print(str("Committee by Borda rule:") + " " + str(committe_borda)) bloc = Bloc() committee_bloc = bloc.find_committee(k, profile) print(str("Committee by Bloc rule:") + " " + str(committee_bloc)) pav = PAV() committee_PAV = list( pav.find_committee(k, Profile_approval_for_PAV, method='Bruteforce')) print(str("Committee by PAV rule:") + " " + str(committee_PAV)) return [ committee_sntv, committe_borda, committee_bloc, committee_PAV, orders ]
def test_is_valid_with_invalid_candidates(): order = [5, 4, 3, 4, 1] ordinal = Ordinal(order) expect(ordinal.is_valid(5)).to(be_false)
from pmp.rules import MultigoalCCBorda, Borda, ChamberlinCourant from pmp.preferences import Ordinal, Profile k = 4 orders = [ [1, 5, 4, 3, 2, 0], [2, 3, 1, 0, 4, 5], [4, 3, 2, 5, 0, 1], [1, 2, 5, 4, 0, 3], [1, 5, 0, 2, 3, 4] ] preferences = [Ordinal(o) for o in orders] candidates = [0, 1, 2, 3, 4, 5] profile = Profile(candidates, preferences) # No thresholds needed for approximation cc = ChamberlinCourant() b = Borda() ccb = MultigoalCCBorda((None, None)) committee_cc = list(cc.find_committee(k, profile)) committee_b = list(b.find_committee(k, profile)) committee_ccb_greedy = list(ccb.find_committee(k, profile, method='Approx_Greedy')) committee_ccb_p = list(ccb.find_committee(k, profile, method='Approx_P')) score_cc = cc.committee_score(committee_cc, profile) score_b = b.committee_score(committee_b, profile) score_ccb_greedy = ccb.committee_score(committee_ccb_greedy, profile) score_ccb_p = ccb.committee_score(committee_ccb_p, profile)
def _ordinal(size): order = [i + 1 for i in range(size)] weights = [i + 1 for i in range(size)] return Ordinal(order, weights)
def ordinal(): order = [5, 4, 3, 2, 1] weights = [1, 2, 3, 4, 5] return Ordinal(order, weights)