pub enum Variant<C> {
Borda,
ClassicBorda,
Dowdall,
ModifiedClassicBorda,
Custom(Box<dyn Fn(usize, usize, usize) -> C>),
}Expand description
Specifies method used to assign points to ranked candidates.
Variants§
Borda
The standard Borda count where each candidate is assigned a number of points equal to the number of candidates ranked lower than them. It is known as the “Starting at 0” Borda count since the least-significantly ranked candidate is given zero points. Each candidate is given points according to:
number-candidates - candidate-position - 1
Example point allocation for a single ballot:
| Position on ballot | Candiate | Points |
|---|---|---|
| 0 | Alice | 3 |
| 1 | Bob | 2 |
| 2 | Carlos | 1 |
| 3 | Dave | 0 |
ClassicBorda
The classic Borda count as defined in Jean-Charles de Borda’s original proposal. It is known as the “Starting at 1” Borda count since the least-significantly ranked candidate is given one point. Each candidate is given points according to:
number-candidates - candidate-position
Example point allocation for a single ballot:
| Position on ballot | Candiate | Points |
|---|---|---|
| 0 | Alice | 4 |
| 1 | Bob | 3 |
| 2 | Carlos | 2 |
| 3 | Dave | 1 |
Dowdall
In the Dowdall system, the highest-ranked candidate obtains 1 point, while the 2nd-ranked candidate receives ½ a point, the 3rd-ranked candidate receives ⅓ of a point, etc. An important difference of this method from the others is that the number of points assigned to each preference does not depend on the number of candidates. Each candidate is given points according to:
1 / (candidate-position + 1)
If Dowdall is selected, tallystick will panic if an integer count type is used in the tally. This variant should only be used with a float or rational tally.
Example point allocation for a single ballot:
| Position on ballot | Candiate | Points |
|---|---|---|
| 0 | Alice | 1 |
| 1 | Bob | ½ |
| 2 | Carlos | ⅓ |
| 3 | Dave | ¼ |
Example:
use tallystick::borda::BordaTally;
use tallystick::borda::Variant;
// Note use of `f64` as our count type.
let mut tally = BordaTally::<&str, f64>::new(1, Variant::Dowdall);
tally.add(vec!["Barak Obama", "John McCain"]);
tally.add(vec!["Barak Obama", "Mitt Romney"]);
let _winners = tally.winners();ModifiedClassicBorda
In a modified Borda count, the number of points given for a voter’s first and subsequent preferences is determined by the total number of candidates they have actually ranked, rather than the total number listed.
This is to say, typically, on a ballot of n candidates, if a voter casts only m preferences (where n ≥ m ≥ 1), a first preference gets m points, a second preference m – 1 points, and so on.
Modified Borda counts are used to counteract the problem of bullet voting.
Each candidate is given points according to:
number-marked - candidate-position
Custom(Box<dyn Fn(usize, usize, usize) -> C>)
Custom point assignment using a boxed closure. Takes a closure of the form:
fn(candidate_position: usize, num_candidates: usize, num_marked: usize) -> C
Example:
use tallystick::borda::BordaTally;
use tallystick::borda::Variant;
let boxed_func = Box::new(|candidate_position, num_candidates, num_marked| {
if num_marked == 1 {
return 1;
}
else {
return num_marked - candidate_position - 1;
}
});
let mut tally = BordaTally::<&str, usize>::new(1, Variant::Custom(boxed_func));Implementations§
Source§impl<C: Numeric + Num + NumCast> Variant<C>
impl<C: Numeric + Num + NumCast> Variant<C>
Sourcepub fn points(
&self,
candidate_position: usize,
num_candidates: usize,
num_marked: usize,
) -> C
pub fn points( &self, candidate_position: usize, num_candidates: usize, num_marked: usize, ) -> C
Get the number of points for a candidate at a certain position on a ballot.
candidate_positionis the position of the candidate on the marked ballot. It is0for the 1st candidate,1for the second candidate etc.num_candidatesis the total number of candidates in this election.num_markedis the total number of candidates marked on the ballot.
This method will panic if using Variant::Dowdall with an integer based vote-count type.