Struct wybr::methods::meek::Meek

source ·
pub struct Meek<'a> { /* private fields */ }
Expand description

A builder for the setup of a Meek count.

See the module level documentation for more.

Default configuration can be generated with Meek::new(tally), where tally is a VoteTree object. Count is triggered by the run() method, which returns a vector of winners, or an error.

Implementations§

source§

impl<'a> Meek<'a>

source

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

Acquire reference to a vote tally and initiate default configuration, which can be altered with other builder methods. The default configuration involves using Hagenbach-Bischoff quota, Meek vote transfer mode, seats number and withdraw list pulled from the tally, 6 digits of fixed-point arithmetic, finally seed set to 21.

source

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

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

source

pub fn seats(&mut self, seats: u32) -> &mut Self

Alters the number of seats (candidates to be elected).

source

pub fn digits(&mut self, digits: u32) -> &mut Self

Alters the number of fixed-point digits used.

Seventeen is max (enforced in run()); also, 10 ^ digits * total votes in tally must be smaller than 2 ^ 64.

source

pub fn quota(&mut self, quota: Quota) -> &mut Self

Alter the quota calculation method; see Quota type for details.

The default is HagenbachBischoff in compatibility with Algorithm 123, but it is good to consider using Hare in order to get most of STV.

source

pub fn transfer(&mut self, transfer: Transfer) -> &mut Self

Alter the vote transfer method; see Transfer type for details.

In general, Meek algorithm is Meek with the default Transfer::Meek; with Transfer::Warren is becomes Warren STV. The naming in wybr reflects the fact that Warren proposed a relatively small change to the Meek idea; not insignificant, however. Also because this method is much more recognisable as Meek STV.

source

pub fn withdraw<I>(&mut self, withdraw: I) -> &mut Selfwhere
    I: IntoIterator<Item = u32>,

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

source

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

Performs Meek STV election, returns Vec<u32> with IDs of winners, or an ElectionError.

Aims to be compatible with Algorithm 123, though uses fixed-point arithmetic.

Errors
  • NotEnoughCandidates, in case there is less candidates then seats or no votes,
  • FixedPointDigitsTooMany, in case there is too many ballots for a given digits value, or when digits is higher than 17, which is somewhat insane.
Notes

In a pathological case, it may take a lot of time, but not infinite (at most ~ number of candidates ^ 2 * 10 ^ digits). Fixed point stuff works by multiplying almost everything by 10^base and fitting the result in u64; when you have like billions of ballots and digits of 9, it may become tight.

Votes are also compared to be greater or equal with quota, even when quota is HagenbachBischoff; when it seems that more candidates then seats are going to be elected, random tie breaking is used.

For seats==1, result will be almost certainly identical to this of irv, depending on the quota method (IRV effectively uses Hare).

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Meek<'a>

§

impl<'a> Send for Meek<'a>

§

impl<'a> Sync for Meek<'a>

§

impl<'a> Unpin for Meek<'a>

§

impl<'a> UnwindSafe for Meek<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.