From 90971e976a633b163a0a3f484fede20dd958e36d Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 4 Sep 2021 23:54:28 +1000 Subject: [PATCH] Fix --round-votes being ignored in first stage --- src/stv/gregory.rs | 11 +++++++++-- src/stv/mod.rs | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/stv/gregory.rs b/src/stv/gregory.rs index e5cd8fd..12d4dd6 100644 --- a/src/stv/gregory.rs +++ b/src/stv/gregory.rs @@ -28,7 +28,8 @@ use std::collections::HashMap; use std::ops; /// Distribute first preference votes according to the Gregory method -pub fn distribute_first_preferences(state: &mut CountState) { +pub fn distribute_first_preferences(state: &mut CountState, opts: &STVOptions) +{ let votes = state.election.ballots.iter().map(|b| Vote { ballot: b, up_to_pref: 0, @@ -45,7 +46,13 @@ pub fn distribute_first_preferences(state: &mut CountState) { }; let count_card = state.candidates.get_mut(candidate).unwrap(); count_card.parcels.push(parcel); - count_card.transfer(&entry.num_ballots); + + let mut vote_transfers = entry.num_ballots.clone(); + if let Some(dps) = opts.round_votes { + vote_transfers.floor_mut(dps); + } + count_card.transfer(&vote_transfers); + count_card.ballot_transfers += entry.num_ballots; } diff --git a/src/stv/mod.rs b/src/stv/mod.rs index 2766820..ab86db0 100644 --- a/src/stv/mod.rs +++ b/src/stv/mod.rs @@ -749,7 +749,7 @@ where { match opts.surplus { SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG | SurplusMethod::Cincinnati | SurplusMethod::Hare => { - gregory::distribute_first_preferences(state); + gregory::distribute_first_preferences(state, opts); } SurplusMethod::Meek => { meek::distribute_first_preferences(state, opts);