Fix rounding of subtransfers by parcel

Was erroneously segmenting transfers by outgoing parcel rather than incoming parcel
This commit is contained in:
RunasSudo 2023-06-11 21:01:29 +10:00
parent 9fc0457844
commit c140ef0a90
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 12 additions and 13 deletions

View File

@ -241,7 +241,7 @@ where
let mut exhausted_ballots = N::new();
let mut exhausted_votes = N::new();
for parcel in parcels {
for (parcel_num, parcel) in parcels.into_iter().enumerate() {
// Count next preferences
let result = super::next_preferences(state, parcel.votes);
@ -253,7 +253,14 @@ where
exhausted_ballots += &result.exhausted.num_ballots;
exhausted_votes += &result.exhausted.num_ballots * &parcel.value_fraction;
parcels_next_prefs.push((parcel.value_fraction, parcel.source_order, result));
// Determine which column of the transfer table to use
let table_column_num = match opts.round_subtransfers {
RoundSubtransfersMode::ByValueAndSource => Some(parcel.source_order),
RoundSubtransfersMode::ByParcel => Some(parcel_num),
_ => Some(0)
};
parcels_next_prefs.push((parcel.value_fraction, table_column_num, result));
}
// Calculate and print surplus fraction
@ -320,16 +327,12 @@ where
surplus.clone(), surplus_fraction.clone(), surplus_numer.clone(), surplus_denom.clone()
);
for (value_fraction, source_order, result) in parcels_next_prefs {
for (value_fraction, table_column_num, result) in parcels_next_prefs {
for (candidate, entry) in result.candidates.into_iter() {
// Record transfers
transfer_table.add_transfers(
&value_fraction,
match opts.round_subtransfers {
RoundSubtransfersMode::ByValueAndSource => Some(source_order),
RoundSubtransfersMode::ByParcel => None, // Force new column per parcel
_ => Some(0)
},
table_column_num,
candidate,
&entry.num_ballots
);
@ -366,11 +369,7 @@ where
// Record exhausted votes
transfer_table.add_exhausted(
&value_fraction,
match opts.round_subtransfers {
RoundSubtransfersMode::ByValueAndSource => Some(source_order),
RoundSubtransfersMode::ByParcel => None, // Force new column per parcel
_ => Some(0)
},
table_column_num,
&result.exhausted.num_ballots
);