Improve messages for --constraint-mode repeat_count

This commit is contained in:
RunasSudo 2022-04-20 20:12:50 +10:00
parent 4aafecb857
commit c2621b2965
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 45 additions and 24 deletions

View File

@ -918,9 +918,16 @@ where
let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap();
dummy_count_card.parcels.append(&mut exhausted.parcels);
// 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])?;
}
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);

View File

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

View File

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