From 151c9e484e1bc5d458ac1328ec274b54d1e82ec0 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 16 Jun 2021 18:24:30 +1000 Subject: [PATCH] Calculate loss by fraction in Meek STV --- src/stv/meek.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/stv/meek.rs b/src/stv/meek.rs index 50ad88d..ce79cd9 100644 --- a/src/stv/meek.rs +++ b/src/stv/meek.rs @@ -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); }