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
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

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);
}