maximal-lottery 0.1.1

A Rust library for computing maximal lotteries from preference profiles.
use maximal_lottery::ballot::RankedBallot;
use maximal_lottery::display::{print_ballot, print_lottery, print_margins};
use maximal_lottery::prelude::*;

fn main() {
    let n = 3;
    let c = Candidate;

    // Voter 1: 0 > 1 > 2
    let ballot1 = RankedBallot::total(&[c(0), c(1), c(2)], n).unwrap();

    // Voter 2: 1 > 2 > 0
    let ballot2 = RankedBallot::total(&[c(1), c(2), c(0)], n).unwrap();

    // Voter 3: 2 > 0 > 1
    let ballot3 = RankedBallot::total(&[c(2), c(0), c(1)], n).unwrap();

    let profile = PreferenceProfile::try_new(vec![ballot1, ballot2, ballot3]).unwrap();

    println!("Ballots:\n");
    for (i, ballot) in profile.ballots().iter().enumerate() {
        print_ballot(ballot, &format!("Ballot {}:", i + 1));
    }

    let margins = profile.tally_margins();
    print_margins(&margins);

    let lottery = CentroidSolver
        .solve(&margins)
        .expect("failed to compute maximal lottery");
    print_lottery(&lottery, &margins);
}