|
|
|
@ -71,6 +71,7 @@ impl<N: Number> Election<N> { |
|
|
|
|
let new_ballot = Ballot { |
|
|
|
|
orig_value: N::one(), |
|
|
|
|
preferences: ballot.preferences.clone(), |
|
|
|
|
has_equal_rankings: ballot.has_equal_rankings, |
|
|
|
|
}; |
|
|
|
|
normalised_ballots.push(new_ballot); |
|
|
|
|
n += &one; |
|
|
|
@ -81,7 +82,7 @@ impl<N: Number> Election<N> { |
|
|
|
|
|
|
|
|
|
/// Convert ballots with equal rankings to strict-preference "minivoters"
|
|
|
|
|
pub fn realise_equal_rankings(&mut self) { |
|
|
|
|
if !self.ballots.iter().any(|b| b.has_equal_rankings()) { |
|
|
|
|
if !self.ballots.iter().any(|b| b.has_equal_rankings) { |
|
|
|
|
// No equal rankings
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -582,17 +583,14 @@ pub struct Ballot<N> { |
|
|
|
|
pub orig_value: N, |
|
|
|
|
/// Indexes of candidates preferenced at each level on the ballot
|
|
|
|
|
pub preferences: Vec<Vec<usize>>, |
|
|
|
|
/// Whether multiple candidates are preferenced at the same level
|
|
|
|
|
pub has_equal_rankings: bool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl<N: Number> Ballot<N> { |
|
|
|
|
/// Check if this ballot has any equal rankings
|
|
|
|
|
pub fn has_equal_rankings(&self) -> bool { |
|
|
|
|
return self.preferences.iter().any(|p| p.len() > 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Convert ballot with equal rankings to strict-preference "minivoters"
|
|
|
|
|
pub fn realise_equal_rankings_into(self, dest: &mut Vec<Ballot<N>>) { |
|
|
|
|
if !self.has_equal_rankings() { |
|
|
|
|
if !self.has_equal_rankings { |
|
|
|
|
dest.push(self); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -631,7 +629,8 @@ impl<N: Number> Ballot<N> { |
|
|
|
|
for minivoter in minivoters { |
|
|
|
|
dest.push(Ballot { |
|
|
|
|
orig_value: weight_each.clone(), |
|
|
|
|
preferences: minivoter |
|
|
|
|
preferences: minivoter, |
|
|
|
|
has_equal_rankings: false, |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|