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>
impl<'a> Meek<'a>
sourcepub fn new(tally: &'a VoteTree) -> Self
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.
sourcepub fn seed(&mut self, seed: u32) -> &mut Self
pub fn seed(&mut self, seed: u32) -> &mut Self
Alters the random seed potentially used by the election algorithm to break ties.
sourcepub fn seats(&mut self, seats: u32) -> &mut Self
pub fn seats(&mut self, seats: u32) -> &mut Self
Alters the number of seats (candidates to be elected).
sourcepub fn digits(&mut self, digits: u32) -> &mut Self
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.
sourcepub fn quota(&mut self, quota: Quota) -> &mut Self
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.
sourcepub fn transfer(&mut self, transfer: Transfer) -> &mut Self
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.
sourcepub fn withdraw<I>(&mut self, withdraw: I) -> &mut Selfwhere
I: IntoIterator<Item = u32>,
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.
sourcepub fn run(&self) -> Result<GenericOutcome<'a>, ElectionError>
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 givendigits
value, or whendigits
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
).