Skip to content

Commit

Permalink
Ajout ballot scores pour equal_shares
Browse files Browse the repository at this point in the history
- TODO : Ajouter priorité
  • Loading branch information
Berkho committed Jun 25, 2024
1 parent a5489d3 commit 33c644f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions tests/participatory_budgeting/test_equal_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
from whalrus.participatories_budgeting.equal_shares import EqualShares
import copy

def test():
def test_approval():


p = Profile(['p1 > p2 > p3','p1 > p2 > p3','p3 > p2 > p1'])

pb = EqualShares(p, base_rule = RuleBorda(), project_cost = {"p1": 100, "p2": 50, "p3": 50}, budget = 150)
print(pb.shares_)
p = Profile([{"A":1,"B":1,"C":0,"D":0,"E":0},
{"A":1,"B":1,"C":1,"D":0,"E":0},
{"A":1,"B":1,"C":0,"D":0,"E":0},
Expand Down Expand Up @@ -46,3 +42,10 @@ def test():
project_cost = {'A':700, 'B':400, 'C':250, 'D':200, 'E':100}, budget = 1100)

assert pb.shares_ == ['B','C','D']

def test_utility():

p = Profile(['p1 > p2 > p3','p1 > p2 > p3','p3 > p2 > p1'])

pb = EqualShares(p, base_rule = RuleBorda(), project_cost = {"p1": 100, "p2": 50, "p3": 50}, budget = 150)
assert pb.shares_ == ['p1','p3']
8 changes: 4 additions & 4 deletions whalrus/participatories_budgeting/equal_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def shares_(self):
del remaining[c]
continue

supporters[c].sort(key = lambda i : budget_voter[i])
supporters[c].sort(key = lambda i : budget_voter[i]/self.voters_utilities[i][c])
amount_so_far = 0
d = remaining[c]

Expand All @@ -77,7 +77,7 @@ def shares_(self):
else:
remaining[c] = eff_vote_count

if eff_vote_count >= best_eff_vote_count:
if eff_vote_count > best_eff_vote_count:
best_eff_vote_count = eff_vote_count
best = c

Expand All @@ -91,8 +91,8 @@ def shares_(self):
best_max_payment = self.project_cost[best] / best_eff_vote_count

for voter in supporters[best]:

budget_voter[voter] = max(0, budget_voter[voter] - best_max_payment)
payment = best_max_payment*self.voters_utilities[voter][best]
budget_voter[voter] = max(0, budget_voter[voter] - payment)



Expand Down

0 comments on commit 33c644f

Please sign in to comment.