Correct handling of exhausted votes during random sample surplus distribution
This commit is contained in:
parent
ae0d1d8411
commit
46e895ee5a
@ -181,8 +181,6 @@ where
|
|||||||
count_card.votes.assign(state.quota.as_ref().unwrap());
|
count_card.votes.assign(state.quota.as_ref().unwrap());
|
||||||
checksum -= surplus;
|
checksum -= surplus;
|
||||||
|
|
||||||
count_card.finalised = true; // Mark surpluses as done
|
|
||||||
|
|
||||||
// Update loss by fraction
|
// Update loss by fraction
|
||||||
state.loss_fraction.transfer(&-checksum);
|
state.loss_fraction.transfer(&-checksum);
|
||||||
}
|
}
|
||||||
@ -209,6 +207,7 @@ where
|
|||||||
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
|
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
|
||||||
state.exhausted.transfer(&surplus);
|
state.exhausted.transfer(&surplus);
|
||||||
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
|
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,31 +235,35 @@ where
|
|||||||
|
|
||||||
while &state.candidates[elected_candidate].votes > state.quota.as_ref().unwrap() {
|
while &state.candidates[elected_candidate].votes > state.quota.as_ref().unwrap() {
|
||||||
// Transfer one vote to next available preference
|
// Transfer one vote to next available preference
|
||||||
let vote = numbered_votes.remove(&index).unwrap();
|
match numbered_votes.remove(&index) {
|
||||||
transfer_ballot(state, opts, elected_candidate, vote, opts.transferable_only)?;
|
Some(vote) => {
|
||||||
if state.num_elected == state.election.seats {
|
transfer_ballot(state, opts, elected_candidate, vote, opts.transferable_only)?;
|
||||||
return Ok(());
|
if state.num_elected == state.election.seats {
|
||||||
}
|
return Ok(());
|
||||||
|
}
|
||||||
index += skip_value;
|
}
|
||||||
if index >= total_ballots {
|
None => {
|
||||||
iteration += 1;
|
|
||||||
index = iteration + skip_value - 1;
|
|
||||||
|
|
||||||
if iteration >= skip_value {
|
|
||||||
// We have run out of ballot papers
|
// We have run out of ballot papers
|
||||||
// Remaining ballot papers exhaust
|
// Remaining ballot papers exhaust
|
||||||
|
|
||||||
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
|
let surplus = &state.candidates[elected_candidate].votes - state.quota.as_ref().unwrap();
|
||||||
state.exhausted.transfer(&surplus);
|
state.exhausted.transfer(&surplus);
|
||||||
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
|
state.candidates.get_mut(elected_candidate).unwrap().transfer(&-surplus);
|
||||||
break;
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user