Correct handling of exhausted votes during random sample surplus distribution

This commit is contained in:
RunasSudo 2021-08-09 00:17:14 +10:00
parent ae0d1d8411
commit 46e895ee5a
No known key found for this signature in database
GPG Key ID: 7234E476BF21C61A
1 changed files with 18 additions and 15 deletions

View File

@ -181,8 +181,6 @@ where
count_card.votes.assign(state.quota.as_ref().unwrap());
checksum -= surplus;
count_card.finalised = true; // Mark surpluses as done
// Update loss by fraction
state.loss_fraction.transfer(&-checksum);
}
@ -209,6 +207,7 @@ where
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
state.exhausted.transfer(&surplus);
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
break;
}
}
}
@ -236,30 +235,34 @@ where
while &state.candidates[elected_candidate].votes > state.quota.as_ref().unwrap() {
// Transfer one vote to next available preference
let vote = numbered_votes.remove(&index).unwrap();
match numbered_votes.remove(&index) {
Some(vote) => {
transfer_ballot(state, opts, elected_candidate, vote, opts.transferable_only)?;
if state.num_elected == state.election.seats {
return Ok(());
}
index += skip_value;
if index >= total_ballots {
iteration += 1;
index = iteration + skip_value - 1;
if iteration >= skip_value {
}
None => {
// We have run out of ballot papers
// Remaining ballot papers exhaust
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
state.exhausted.transfer(&surplus);
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
break;
}
}
index += skip_value;
if index >= total_ballots {
iteration += 1;
index = iteration + skip_value - 1;
}
}
}
}
let count_card = state.candidates.get_mut(elected_candidate).unwrap();
count_card.finalised = true; // Mark surpluses as done
return Ok(());
}