[][src]Struct wybr::methods::nanson::Nanson

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

Methods

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

A builder for the setup of a Nanson count.

See the module level documentation for more.

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

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 Nanson election; returns the ID of a winner, or an ElectionError.

Notes

Nanson's method is essentially an iterated Borda election; on each iteration all candidates with Borda score lower or equal than average are eliminated. All parameters of the Nanson method are identical to these of the Borda method.

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 Nanson<'a>

impl<'a> Sync for Nanson<'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.