Improve messages for --constraint-mode repeat_count
This commit is contained in:
parent
4aafecb857
commit
c2621b2965
|
@ -918,9 +918,16 @@ where
|
||||||
let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap();
|
let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap();
|
||||||
dummy_count_card.parcels.append(&mut exhausted.parcels);
|
dummy_count_card.parcels.append(&mut exhausted.parcels);
|
||||||
|
|
||||||
state.title = StageKind::RollbackExhausted;
|
// Nasty hack to check if continuing distribution!!
|
||||||
state.logger.log_literal(String::from("Distributing exhausted ballots."));
|
if let StageKind::RollbackExhausted = state.title {
|
||||||
stv::exclude_candidates(state, opts, vec![dummy_candidate])?;
|
// 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();
|
let dummy_count_card = state.candidates.get_mut(dummy_candidate).unwrap();
|
||||||
exhausted.parcels.append(&mut dummy_count_card.parcels);
|
exhausted.parcels.append(&mut dummy_count_card.parcels);
|
||||||
|
@ -961,18 +968,25 @@ where
|
||||||
} else {
|
} else {
|
||||||
candidate_distributing = Some(electable_candidates_old[0]);
|
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 candidate_distributing = candidate_distributing.unwrap();
|
||||||
let dummy_candidate = state.election.candidates.iter().find(|c| c.name == candidate_distributing.name && c.is_dummy).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.title = StageKind::BallotsOf(candidate_distributing);
|
||||||
state.logger.log_smart(
|
stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?;
|
||||||
"Distributing ballots of {}.",
|
|
||||||
"Distributing ballots of {}.",
|
|
||||||
vec![candidate_distributing.name.as_str()]
|
|
||||||
);
|
|
||||||
stv::exclude_candidates(state, opts, vec![dummy_candidate])?;
|
|
||||||
|
|
||||||
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) };
|
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);
|
return Ok(true);
|
||||||
|
@ -1010,18 +1024,25 @@ where
|
||||||
} else {
|
} else {
|
||||||
candidate_distributing = Some(unelectable_candidates_old[0]);
|
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 candidate_distributing = candidate_distributing.unwrap();
|
||||||
let dummy_candidate = state.election.candidates.iter().find(|c| c.name == candidate_distributing.name && c.is_dummy).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.title = StageKind::BallotsOf(candidate_distributing);
|
||||||
state.logger.log_smart(
|
stv::exclude_candidates(state, opts, vec![dummy_candidate], "Distribution")?;
|
||||||
"Distributing ballots of {}.",
|
|
||||||
"Distributing ballots of {}.",
|
|
||||||
vec![candidate_distributing.name.as_str()]
|
|
||||||
);
|
|
||||||
stv::exclude_candidates(state, opts, vec![dummy_candidate])?;
|
|
||||||
|
|
||||||
state.rollback_state = RollbackState::RollingBack { candidates: Some(candidates), exhausted: Some(exhausted), candidate_distributing: Some(candidate_distributing), constraint: Some(constraint), group: Some(group) };
|
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);
|
return Ok(true);
|
||||||
|
|
|
@ -150,7 +150,7 @@ where
|
||||||
state.logger.log_smart(
|
state.logger.log_smart(
|
||||||
"{} meets the quota and is elected.",
|
"{} meets the quota and is elected.",
|
||||||
"{} meet the quota and are elected.",
|
"{} meet the quota and are elected.",
|
||||||
vec![&elected_candidate.name]
|
vec![elected_candidate.name.as_str()]
|
||||||
);
|
);
|
||||||
|
|
||||||
constraints::update_constraints(state, opts);
|
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]
|
/// Perform one stage of a candidate exclusion according to the Gregory method, based on [STVOptions::exclusion]
|
||||||
#[allow(clippy::branches_sharing_code)]
|
#[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
|
where
|
||||||
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
||||||
for<'r> &'r N: ops::Div<&'r N, Output=N>,
|
for<'r> &'r N: ops::Div<&'r N, Output=N>,
|
||||||
|
@ -677,7 +677,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.exclusion != ExclusionMethod::SingleStage {
|
if opts.exclusion != ExclusionMethod::SingleStage {
|
||||||
state.logger.log_literal("Exclusion complete.".to_string());
|
state.logger.log_literal(format!("{} complete.", complete_type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1404,7 +1404,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude_candidates(state, opts, excluded_candidates)?;
|
exclude_candidates(state, opts, excluded_candidates, "Exclusion")?;
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1542,7 +1542,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude_candidates(state, opts, excluded_candidates)?;
|
exclude_candidates(state, opts, excluded_candidates, "Exclusion")?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1577,7 +1577,7 @@ where
|
||||||
names
|
names
|
||||||
);
|
);
|
||||||
|
|
||||||
exclude_candidates(state, opts, excluded_candidates)?;
|
exclude_candidates(state, opts, excluded_candidates, "Exclusion")?;
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1585,7 +1585,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform one stage of a candidate exclusion, according to [STVOptions::exclusion]
|
/// 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
|
where
|
||||||
for<'r> &'r N: ops::Sub<&'r N, Output=N>,
|
for<'r> &'r N: ops::Sub<&'r N, Output=N>,
|
||||||
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
|
||||||
|
@ -1595,7 +1595,7 @@ where
|
||||||
ExclusionMethod::SingleStage => {
|
ExclusionMethod::SingleStage => {
|
||||||
match opts.surplus {
|
match opts.surplus {
|
||||||
SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => {
|
SurplusMethod::WIG | SurplusMethod::UIG | SurplusMethod::EG => {
|
||||||
gregory::exclude_candidates(state, opts, excluded_candidates);
|
gregory::exclude_candidates(state, opts, excluded_candidates, complete_type);
|
||||||
}
|
}
|
||||||
SurplusMethod::Meek => {
|
SurplusMethod::Meek => {
|
||||||
meek::exclude_candidates(state, opts, excluded_candidates);
|
meek::exclude_candidates(state, opts, excluded_candidates);
|
||||||
|
@ -1607,7 +1607,7 @@ where
|
||||||
}
|
}
|
||||||
ExclusionMethod::ByValue | ExclusionMethod::BySource | ExclusionMethod::ParcelsByOrder => {
|
ExclusionMethod::ByValue | ExclusionMethod::BySource | ExclusionMethod::ParcelsByOrder => {
|
||||||
// Exclusion in parts compatible only with Gregory method
|
// 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 => {
|
ExclusionMethod::Wright => {
|
||||||
gregory::wright_exclude_candidates(state, opts, excluded_candidates);
|
gregory::wright_exclude_candidates(state, opts, excluded_candidates);
|
||||||
|
|
Loading…
Reference in New Issue