[][src]Enum tallystick::borda::Variant

pub enum Variant<C> {
    Borda,
    ClassicBorda,
    Dowdall,
    ModifiedClassicBorda,
    Custom(Box<dyn Fn(usize, usize, usize) -> C>),
}

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 ballotCandiatePoints
0Alice3
1Bob2
2Carlos1
3Dave0
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 ballotCandiatePoints
0Alice4
1Bob3
2Carlos2
3Dave1
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 ballotCandiatePoints
0Alice1
1Bob½
2Carlos
3Dave¼

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

Methods

impl<C: Numeric + Num + NumCast> Variant<C>[src]

pub fn points(
    &self,
    candidate_position: usize,
    num_candidates: usize,
    num_marked: usize
) -> C
[src]

Get the number of points for a candidate at a certain position on a ballot.

  • candidate_position is the position of the candidate on the marked ballot. It is 0 for the 1st candidate, 1 for the second candidate etc.
  • num_candidates is the total number of candidates in this election.
  • num_marked is the total number of candidates marked on the ballot.

This method will panic if using Variant::Dowdall with an integer based vote-count type.

Auto Trait Implementations

impl<C> !RefUnwindSafe for Variant<C>

impl<C> !Send for Variant<C>

impl<C> !Sync for Variant<C>

impl<C> Unpin for Variant<C>

impl<C> !UnwindSafe for Variant<C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.