[][src]Struct wybr::methods::borda::Borda

pub struct Borda<'a> { /* fields omitted */ }

A builder for the setup of a Borda-style count.

See the module level documentation for more.

Default configuration can be generated with Borda::new(&tally), where tally is a VoteTree object. Count is triggered by the run() method, which returns a solitary winner, or an error.

Methods

impl<'a> Borda<'a>[src]

pub fn new(tally: &'a VoteTree) -> Self[src]

Acquire reference to a vote tally and initiate default configuration, which can be altered with other builder methods. The default configuration involves using Borda1 kind, withdraw list pulled from the tally, maximal rank equal to the actual maximal rank found in the tally, finally for seed equal to 21.

pub fn seed(&mut self, seed: u32) -> &mut Self[src]

Alters the random seed potentially used by the election algorithm to break ties.

pub fn kind(&mut self, kind: BordaKind) -> &mut Self[src]

Alter the Borda election kind; see BordaKind type for details.

pub fn max_rank(&mut self, max_rank: u32) -> &mut Self[src]

Alter the maximal rank used for election; ranks are count from zero, so when this value is x, up to (x + 1)-th vote is considered, while the later ones are discarded.

Note that withdraws act before this filter, so vote A B C with max_rank 1 and B withdrawn is interpreted as first preference is A, second is no-one.

pub fn withdraw<I>(&mut self, withdraw: I) -> &mut Self where
    I: IntoIterator<Item = u32>, 
[src]

Alter a list of withdrawn candidates, which are not considered in count.

A vote A B C with B withdrawn is interpreted as first preference is A, second is C, third is no-one.

pub fn run(&self) -> Result<GenericOutcome<'a>, ElectionError>[src]

Performs Borda election; returns the ID of a winner, or an ElectionError.

Notes

Wybr internally shifts votes leftmost, both when parsing inputs and in data representation; hence, one cannot have vote like A (no-one) B C, at most A B C (no-one) (no-one). In such case of truncated votes, the omitted ranks simply generate zero points, and no adjustments are made to the rest of the candidates on a ballot.

Dowdall/Nauru system uses multiplication instead of division to assure accurate integer calculation; counts are multiplied by lcm(1,2,..,max_rank) and then divided by rank. Consequently, Nauru with max_rank equal to 43 and more returns error immediately.

For max_rank equal to 0 (either given explicitly or calculated) and Borda0 kind, scores are multiplied by 1 rather than 0.

Errors

  • ArithmeticOverflow, when score numbers are too large to fit in u64; this is especially likely with Nauru kind and insane max_rank, like 40+.
  • NotEnoughCandidates, when there is no candidates or no votes.

Auto Trait Implementations

impl<'a> Send for Borda<'a>

impl<'a> Sync for Borda<'a>

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.