Crates.io | electosim |
lib.rs | electosim |
version | 0.2.3 |
source | src |
created_at | 2024-06-21 18:45:44.068035 |
updated_at | 2024-10-05 21:18:55.058213 |
description | Library to compute electoral methods (as D'Hondt) and simulate elections |
homepage | |
repository | https://github.com/edugzlez/electosim-rs |
max_upload_size | |
id | 1279795 |
size | 31,096 |
ElectoSIM is a Rust library for simulating elections using different voting systems.
Add this to your Cargo.toml
:
[dependencies]
electosim = "0.2.1"
or add it directly from crates.io:
cargo add electosim
election!
use electosim::*;
fn main() {
let candidacies = vec![
candidacy!(2010, 9),
candidacy!(1018, 4),
candidacy!(86, 0),
candidacy!(77, 0),
];
let seats = 13;
let method = Method::HAGENBASCHBISCHOFF;
let cutoff = 0.1;
let mut ele = election![candidacies, seats, method, cutoff];
ele.compute().expect("Can not compute method");
ele.results.iter().for_each(|c| println!("{:?}", c));
}
use electosim::*;
use electosim::methods::divisor::compute_dhondt;
fn main() {
let mut candidacies = vec![
candidacy!(2010, 0),
candidacy!(1018, 0),
candidacy!(86, 0),
candidacy!(77, 0),
];
compute_dhondt(&mut candidacies, 13).unwrap();
candidacies.iter().for_each(|c| println!("{:?}", c));
}
This project is licensed under the MIT License - see the LICENSE file for details.