Giter Club home page Giter Club logo

tallystick's Introduction

tallystick

docs crates.io Build Status codecov patreon flattr

tallystick is a work-in-progress rust library for tallying votes.

Current state is very unstable. It is not currently recommended for use. See checkboxes below for a list of features that are complete.

Goals

  1. Ergonomic - Easy to use.
  2. Fast - Be the fastest general-purpose vote tallying library in the world.
  3. Secure - Have no undefined behavior.
  4. Complete - Support all well-known voting methods.
  5. Deterministic - Running the same tally twice should never produce different results.
  6. Generic - Generic over both candidate and count types.

Features

  • wasm support for use in the browser, or in blockchain smart contracts.
  • rational support for perfectly-precise tallies by using rational fractions instead of floats.
  • fixed_point support for decimal fixed-point tallies, required by some statutes.
  • ffi support for calling from other programming languages.
  • alloc support for embedded and other applications where there is an allocator, but no standard library.

Supported Tally Methods

Status¹ Tally Method Supported Variants Performance² Notes
Plurality 120 million v/s First Past the Post (FPTP)
Score 3 million v/s
Approval 4 million v/s
STV Newland-Britton, Meek, Warren 3 million v/s Single Transferable Vote
CPO-STV
Instant Runoff
Contingent
Supplementary
Condorcet 2 million v/s
Copeland
Schulze Winning, Margin, Ratio 2 million v/s
Schulze STV
Kemeny–Young
Minimax
Borda Classic, Dowdall, Modified 3 million v/s
Borda - Nanson Classic, Dowdall, Modified
Borda - Baldwin Classic, Dowdall, Modified
Dodgson Quick, Tideman
Ranked pairs Margin, Winning
STAR
Majority judgment
D'Hondt Sainte-Laguë, Huntington-Hill, Quota
  1. ✓ means done, ⚠ means in-progress, blank means not started but support is planned.
  2. Single threaded performance measured in votes tallied per second. Benchmarked on a 2017 Macbook Pro.

Contributors

tallystick's People

Contributors

dependabot-preview[bot] avatar kbuilds avatar phayes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tallystick's Issues

Licensing

Hello! I'm planning to use your library in my betterpoll project. Before I make the API publicly available, I'd like to know how tallystick is licensed. I don't see any LICENSE file; if you plan to license tallystick under a copyleft license I'd like to know that so I can license my project accordingly. (I'm currently planning to use the MIT license, but I'm happy to change that.)

Thanks!

Schulze with single canidate doesn't output a winner

Noticed this by chance in my own testing. While trivial to work around I figured I'd report it. I haven't checked if other methods have similar issues.

Here is a failing test:

    #[test]
    fn schulze_single_canidate() -> Result<(), TallyError> {

        let candidates = vec!["A".to_string()];

        let votes_raw = "A";

        let votes = Cursor::new(votes_raw);
        let votes = util::read_votes(votes).unwrap();

        // Margin
        let mut tally = DefaultSchulzeTally::with_candidates(1, Variant::Margin, candidates.clone());
        for (vote, weight) in votes.iter() {
            match vote {
                util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
                util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
            }
        }
        assert_eq!(tally.winners().into_unranked()[0], "A".to_string());

        // Winning
        let mut tally = DefaultSchulzeTally::with_candidates(1, Variant::Winning, candidates.clone());
        for (vote, weight) in votes.iter() {
            match vote {
                util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
                util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
            }
        }
        assert_eq!(tally.winners().into_unranked()[0], "A".to_string());

        // Ratio
        let votes = Cursor::new(votes_raw);
        let votes = util::read_votes(votes).unwrap(); // reparse votes as f64
        let mut tally = SchulzeTally::<_, f64>::with_candidates(1, Variant::Ratio, candidates.clone());
        for (vote, weight) in votes.iter() {
            match vote {
                util::ParsedVote::Ranked(v) => tally.ranked_add_weighted(v, *weight)?,
                util::ParsedVote::Unranked(v) => tally.add_weighted(v, *weight)?,
            }
        }
        assert_eq!(tally.winners().into_unranked()[0], "A".to_string());

        Ok(())
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.