Sequentially Spent Score: Difference between revisions

(→‎Variants: add sorted surplus handling variant)
Line 41:
 
#Find number of voters
V = S_wrkballots.shape[0]
quota = V/W
ballot_weight = pd.Series(np.ones(V),name='weights')
 
#Populate winners in a loop
Line 47 ⟶ 49:
while len(winner_list) < W:
 
#Select winner
w = S_wrkballots.sum().idxmax()
 
#Add winner to list
winner_list.append(w)
 
#Check for Surplus
surplus_factor = max( S_wrkballots[w].sum() *W/Vquota , 1.0)
 
#Score spent on winner by each voter
score_spent = S_wrk ballots[w] / surplus_factor
#Total score left to be spent by each voter
ballot_weight = np.clip(ballot_weight-score_spent,0.0,1.0)
 
#remove winner from ballot
#Total score left to be spent by each voter
ballots.drop(w, axis=1, inplace=True)
ballot_weight = np.clip(ballot_weight-score_spent,0.0,1.0)
 
#Update Ballots as the minimum of original score and score remaining
mins = np.minimum(S_wrkballots.values,ballot_weight.values[:, np.newaxis])
S_wrk ballots = pd.DataFrame(mins, columns = S_wrkballots.columns)
</source>
 
763

edits