[−][src]Struct wybr::methods::ranked_pairs::RankedPairs
A builder for the setup of a Ranked Pairs count
See the module level documentation for more.
Default configuration can be generated with RankedPairs::new(&tally)
, where tally
is a
VoteMatrix
object.
Count is triggered by the run()
method, which returns a solitary winner, or an error.
Methods
impl<'a> RankedPairs<'a>
[src]
pub fn new(tally: &'a VoteMatrix) -> Self
[src]
Acquire reference to a vote matrix tally and initiate default configuration, which can be altered with other builder methods. The default configuration involves using Winning pair scoring and random seed of 21.
pub fn pair_score(&mut self, pair_score: PairScore) -> &mut Self
[src]
Alters the pair scoring method.
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 run(&self) -> Result<GenericOutcome<'a>, ElectionError>
[src]
Performs ranked pairs (Tideman) election, returns winner ID or an ElectionError
.
The method considers each pair of candidates (i,j) and combines it with a score, which
depends on the mode. Then, pairs are ordered by decreasing score and sequentially locked,
that is added as an edge to a directed acyclic graph over candidates, or dropped, in case
adding them would have cause a cycle in the graph and violate is DAG property. The winner
is the only candidate in the resulting graph that is not beaten; if there are more unbeaten
candidates, the election is considered unresolved and DegeneratedElectionGraph
error is
emitted.
The score depends on the mode; also, for mode equal to Winning or Margin only winning pairs are considered. In case of ties in sort, first the possibly low opposition vote is used, that is the number of votes which prefer j to i, and then pseudo-random order depending on the seed.
Errors
NotEnoughCandidates
, in case there is no candidates.DegeneratedElectionGraph
, in case when there is no winner in the final graph; this may happen for instance when the graph looks like this:A->B<-C
or has isolated sub-graph, like thisA->D->C C->E
-- in both cases, A & B are equally good winners in light of ranked pairs method, but may be not equivalent in terms of actual preference, hence we don't want to use random tie breaking. Anyhow, such situation happens extremely rarely in practice, especially when indifferent votes are disallowed (this is what wybr does).
Notes
Default mode for ranked pairs is Margin
; Winning
is often seen in the
definition of this method. Opposition
mode is similar to Winning
, but affects
symmetric links (i & j so that d(i,j)=d(j,i)) -- instead of being thrown away as in other
modes, they are converted into unidirectional ones with a random direction.
Auto Trait Implementations
impl<'a> Send for RankedPairs<'a>
impl<'a> Sync for RankedPairs<'a>
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,