Calculate loss by fraction in Meek STV

This commit is contained in:
RunasSudo 2021-06-16 18:24:30 +10:00
parent ca54b94953
commit 151c9e484e
No known key found for this signature in database
GPG Key ID: 7234E476BF21C61A
1 changed files with 8 additions and 0 deletions

View File

@ -239,10 +239,14 @@ where
}
// Recalculate transfers
let mut checksum = N::new();
for (candidate, count_card) in state.candidates.iter_mut() {
count_card.transfers = &count_card.votes - &orig_candidates.get(candidate).unwrap().votes;
checksum += &count_card.transfers;
}
state.exhausted.transfers = &state.exhausted.votes - &orig_exhausted.votes;
checksum += &state.exhausted.transfers;
state.loss_fraction.transfer(&-checksum);
// Remove intermediate logs on quota calculation
state.logger.entries.clear();
@ -294,8 +298,12 @@ where
distribute_preferences(state);
// Recalculate transfers
let mut checksum = N::new();
for (candidate, count_card) in state.candidates.iter_mut() {
count_card.transfers = &count_card.votes - &orig_candidates.get(candidate).unwrap().votes;
checksum += &count_card.transfers;
}
state.exhausted.transfers = &state.exhausted.votes - &orig_exhausted.votes;
checksum += &state.exhausted.transfers;
state.loss_fraction.transfer(&-checksum);
}