GithubHelp home page GithubHelp logo

shikaga / socialchoice Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kybernetikos/socialchoice

0.0 2.0 0.0 361 KB

Experimenting with voting systems

Home Page: http://kybernetikos.github.io/SocialChoice

JavaScript 93.12% CSS 6.88%

socialchoice's Introduction

layout permalink title
main
/index.html
SocialChoice
<script type="text/javascript" src="target/single/SocialChoice.js"></script>

SocialChoice

A playground for exploring vote counting methods.

  • This document is available nicely formatted here.
  • Tests are here.
  • Source code is here.
  • Demo is here.
  • You can also get it with the following command if you're using node.

    npm install git+http://github.com/kybernetikos/SocialChoice.git#gh-pages

Getting Started

You can set up an election with the following code:

	var SocialChoice = require('SocialChoice');

	var vote = new SocialChoice({
		options: ["a", "b", "c", "d", "x", "y"]
	});

Options must have a unique toString.

Now you can vote for some of the options. Voting can be done by ranking, or by assigning a score, or by 'approving' some options. If you have a restriction that you can only approve a single option then this becomes a simple plurality election.

	vote.rank(10, ["a", "x"], "b");
	vote.rank(4, ["a", "x"], ["c", "y"]);
	vote.rank(2, "d", ["a", "x"], ["c", "y"], "b");
	vote.rank(19, ["c", "y"], "b", ["a", "x"]);

	vote.score(4, {
		"a": 3,
		"x": 99,
		"y": 52
	});

	vote.approve(3, "a", "y", "b");

You can get various kinds of results:

		console.log(vote.getSumResult());

		var r = vote.getRankingResult();
		console.log("ranked pairs", r.rankedPairs().join(" "));

		var i = vote.getRunOffResult();
		console.log("instant run-off", i.ranks.join(" "));

The whole system is very flexible and extensible. You can apply restrictions which check votes are valid for the particular election you are running, and ballot transforms which can modify votes.

A default restriction (called noWriteIns) is applied when you specify options in your configuration, which stops votes from ranking things not specified in the configured options.

A common ballot transform used by default (called missing) scores anything not mentioned in a ballot as 0 or ranks it last.

Some of the result objects have parameters too, for example it's possible to change the way the ranked pairs algorithm determines which pair-wise contests are most significant by passing a function parameter.

socialchoice's People

Contributors

kybernetikos avatar shikaga avatar

Watchers

 avatar James Cloos avatar

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.