ElectoSIM
ElectoSIM is a library that allows you to simulate simple elections using different methods.
Methods
The following methods are available:
- D'Hondt
- Webster/Sainte-Laguë
- Adams
- Imperiali
- Huntington-Hill
- Danish
- Hare-Niemeyer
- Hagenbach-Bischoff
- Imperiali - Quotient
- Droop
- Winner Takes All
Usage
use *;
The first statement in the main function creates a new [SimpleElection] with the candidates, the number of seats available, and the method to be used. The compute method is then called to compute the election results. Finally, the results are printed to the console.
compute_ functions
A method is a function with type fn(&mut Vec<T>, u16) -> Result<(), &str> where T is a type that implements the [WithVotes][interface::WithVotes] and [WithSeats][interface::WithSeats] traits.
You can use the compute_ functions directly if you want to compute the election results without using the [SimpleElection] struct. For example:
use *;
use compute_dhondt;
There are some implementations of the compute_ functions in the [methods::divisor] (ex: D'hondt) and [methods::remainder] (ex: Hare) modules.