Also bulk elect based on guarded candidates

This commit is contained in:
RunasSudo 2021-06-27 23:20:35 +10:00
parent c12743285a
commit d697871414
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -929,11 +929,6 @@ where
/// Declare all continuing candidates elected, if the number equals the number of remaining vacancies /// Declare all continuing candidates elected, if the number equals the number of remaining vacancies
fn bulk_elect<N: Number>(state: &mut CountState<N>, opts: &STVOptions) -> Result<bool, STVError> { fn bulk_elect<N: Number>(state: &mut CountState<N>, opts: &STVOptions) -> Result<bool, STVError> {
if state.election.candidates.len() - state.num_excluded <= state.election.seats {
state.kind = None;
state.title = "Bulk election".to_string();
// Bulk elect all remaining candidates
let mut hopefuls: Vec<&Candidate> = state.election.candidates.iter() let mut hopefuls: Vec<&Candidate> = state.election.candidates.iter()
.filter(|c| { .filter(|c| {
let cc = state.candidates.get(c).unwrap(); let cc = state.candidates.get(c).unwrap();
@ -941,6 +936,11 @@ fn bulk_elect<N: Number>(state: &mut CountState<N>, opts: &STVOptions) -> Result
}) })
.collect(); .collect();
if state.num_elected + hopefuls.len() <= state.election.seats {
state.kind = None;
state.title = "Bulk election".to_string();
// Bulk elect all remaining candidates
while !hopefuls.is_empty() { while !hopefuls.is_empty() {
let max_votes = hopefuls.iter() let max_votes = hopefuls.iter()
.max_by(|a, b| state.candidates.get(**a).unwrap().votes.cmp(&state.candidates.get(**b).unwrap().votes)) .max_by(|a, b| state.candidates.get(**a).unwrap().votes.cmp(&state.candidates.get(**b).unwrap().votes))