From c2621b29654d4b64cb2cf66550226c2592610709 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 20 Apr 2022 20:12:50 +1000 Subject: [PATCH] Improve messages for --constraint-mode repeat_count --- src/constraints.rs | 51 +++++++++++++++++++++++++++++------------- src/stv/gregory/mod.rs | 6 ++--- src/stv/mod.rs | 12 +++++----- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/constraints.rs b/src/constraints.rs index b893f20..4232e8f 100644 --- a/src/constraints.rs +++ b/src/constraints.rs @@ -918,9 +918,16 @@ where let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap(); dummy_count_card.parcels.append(&mut exhausted.parcels); - state.title = StageKind::RollbackExhausted; - state.logger.log_literal(String::from("Distributing exhausted ballots.")); - stv::exclude_candidates(state, opts, vec![dummy_candidate])?; + // Nasty hack to check if continuing distribution!! + if let StageKind::RollbackExhausted = state.title { + // Continuing + state.logger.log_literal(String::from("Continuing distribution of exhausted ballots.")); + } else { + state.title = StageKind::RollbackExhausted; + state.logger.log_literal(String::from("Distributing exhausted ballots.")); + } + + stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?; let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap(); exhausted.parcels.append(&mut dummy_count_card.parcels); @@ -961,18 +968,25 @@ where } else { candidate_distributing = Some(electable_candidates_old[0]); } + + state.logger.log_smart( + "Distributing ballots of {}.", + "Distributing ballots of {}.", + vec![candidate_distributing.unwrap().name.as_str()] + ); + } else { + state.logger.log_smart( + "Continuing distribution of ballots of {}.", + "Continuing distribution of ballots of {}.", + vec![candidate_distributing.unwrap().name.as_str()] + ); } let candidate_distributing = candidate_distributing.unwrap(); let dummy_candidate = state.election.candidates.iter().find(|c| c.name == candidate_distributing.name && c.is_dummy).unwrap(); state.title = StageKind::BallotsOf(candidate_distributing); - state.logger.log_smart( - "Distributing ballots of {}.", - "Distributing ballots of {}.", - vec![candidate_distributing.name.as_str()] - ); - stv::exclude_candidates(state, opts, vec![dummy_candidate])?; + stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) }; return Ok(true); @@ -1010,18 +1024,25 @@ where } else { candidate_distributing = Some(unelectable_candidates_old[0]); } + + state.logger.log_smart( + "Distributing ballots of {}.", + "Distributing ballots of {}.", + vec![candidate_distributing.unwrap().name.as_str()] + ); + } else { + state.logger.log_smart( + "Continuing distribution of ballots of {}.", + "Continuing distribution of ballots of {}.", + vec![candidate_distributing.unwrap().name.as_str()] + ); } let candidate_distributing = candidate_distributing.unwrap(); let dummy_candidate = state.election.candidates.iter().find(|c| c.name == candidate_distributing.name && c.is_dummy).unwrap(); state.title = StageKind::BallotsOf(candidate_distributing); - state.logger.log_smart( - "Distributing ballots of {}.", - "Distributing ballots of {}.", - vec![candidate_distributing.name.as_str()] - ); - stv::exclude_candidates(state, opts, vec![dummy_candidate])?; + stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?; state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) }; return Ok(true); diff --git a/src/stv/gregory/mod.rs b/src/stv/gregory/mod.rs index a764d74..288ce28 100644 --- a/src/stv/gregory/mod.rs +++ b/src/stv/gregory/mod.rs @@ -150,7 +150,7 @@ where state.logger.log_smart( "{} meets the quota and is elected.", "{} meet the quota and are elected.", - vec![&elected_candidate.name] + vec![elected_candidate.name.as_str()] ); constraints::update_constraints(state, opts); @@ -405,7 +405,7 @@ where /// Perform one stage of a candidate exclusion according to the Gregory method, based on [STVOptions::exclusion] #[allow(clippy::branches_sharing_code)] -pub fn exclude_candidates<'a, N: Number>(state: &mut CountState<'a, N>, opts: &STVOptions, excluded_candidates: Vec<&'a Candidate>) +pub fn exclude_candidates<'a, N: Number>(state: &mut CountState<'a, N>, opts: &STVOptions, excluded_candidates: Vec<&'a Candidate>, complete_type: &'static str) where for<'r> &'r N: ops::Mul<&'r N, Output=N>, for<'r> &'r N: ops::Div<&'r N, Output=N>, @@ -677,7 +677,7 @@ where } if opts.exclusion != ExclusionMethod::SingleStage { - state.logger.log_literal("Exclusion complete.".to_string()); + state.logger.log_literal(format!("{} complete.", complete_type)); } } diff --git a/src/stv/mod.rs b/src/stv/mod.rs index 57b32e5..b7ab227 100644 --- a/src/stv/mod.rs +++ b/src/stv/mod.rs @@ -1404,7 +1404,7 @@ where } } - exclude_candidates(state, opts, excluded_candidates)?; + exclude_candidates(state, opts, excluded_candidates, "Exclusion")?; return Ok(true); } @@ -1542,7 +1542,7 @@ where } } - exclude_candidates(state, opts, excluded_candidates)?; + exclude_candidates(state, opts, excluded_candidates, "Exclusion")?; return Ok(()); } @@ -1577,7 +1577,7 @@ where names ); - exclude_candidates(state, opts, excluded_candidates)?; + exclude_candidates(state, opts, excluded_candidates, "Exclusion")?; return Ok(true); } @@ -1585,7 +1585,7 @@ where } /// Perform one stage of a candidate exclusion, according to [STVOptions::exclusion] -pub fn exclude_candidates<'a, N: Number>(state: &mut CountState<'a, N>, opts: &STVOptions, excluded_candidates: Vec<&'a Candidate>) -> Result<(), STVError> +pub fn exclude_candidates<'a, N: Number>(state: &mut CountState<'a, N>, opts: &STVOptions, excluded_candidates: Vec<&'a Candidate>, complete_type: &'static str) -> Result<(), STVError> where for<'r> &'r N: ops::Sub<&'r N, Output=N>, for<'r> &'r N: ops::Mul<&'r N, Output=N>, @@ -1595,7 +1595,7 @@ where ExclusionMethod::SingleStage => { match opts.surplus { SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => { - gregory::exclude_candidates(state, opts, excluded_candidates); + gregory::exclude_candidates(state, opts, excluded_candidates, complete_type); } SurplusMethod::Meek => { meek::exclude_candidates(state, opts, excluded_candidates); @@ -1607,7 +1607,7 @@ where } ExclusionMethod::ByValue | ExclusionMethod::BySource | ExclusionMethod::ParcelsByOrder => { // Exclusion in parts compatible only with Gregory method - gregory::exclude_candidates(state, opts, excluded_candidates); + gregory::exclude_candidates(state, opts, excluded_candidates, complete_type); } ExclusionMethod::Wright => { gregory::wright_exclude_candidates(state, opts, excluded_candidates);