Condorcet is a PHP Class to computing many Condorcet voting methods

Installs: 30

Dependents: 0

Suggesters: 0

Stars: 21

Watchers: 5

Forks: 1

Open Issues: 1


Condorcet Class

A PHP class implementing the Condorcet voting system and others Condorcet methods like the Schulze method.

This library provide you :

  • Great vote management system. With stats, security, cache, exports, sleeping support and a powerfull vote and candidate management object-oriented.
  • Support for the pairwise computation and implementing of the original method from the Marquis of Condorcet.
  • Native implementation of more complex algortihms meeting the criteria Condorcet (Schulze, Copeland, RankedPair, Kemeny-Young, MiniMax Family... see below)
  • Modular architecture to easily implement yours own algorithms or extend existing.

This class is not designed for high performances, very high fiability exigence, massive voters or candidates


  1. Project Overview
    a. Contributors and License
    b. Specifications and standards
    c. Project State
    d. Related projects / They use Condorcet
    e. Key Features
  2. How to use it?
    a. Condorcet Wiki Manual
    b. Class & Methods reference
    c. Examples Have a look on Examples !
    d. Really quick and simple example

Contributors and License

Created by: Julien Boudry (born 22/10/1988 - France) @JulienBoudry - (complete list of contributors)
License: MIT (read de LICENSE file at the root folder) Including code, examples, logo and documentation

As a courtesy, I will thank you to inform me about your project using this code, produced with love and selflessness. You can also offer me a bottle of good wine.
Or finance my studies: 1LhZZVxmNCTPWftKFTUKbRiUKzA67RPWez

Specifications and standards

Stable Version: 0.97
PHP Requirement: PHP 5.5 with Ctype, MB_String, Json common extensions. (tested up to PHP 5.6)


This project is consistent with the standard PSR-4 and can be loaded easily and without modification in most frameworks or Composer autoloader. Namespace \Condorcet is used. The examples also provides easy example of free implementation with or without autoloader (Condorcet provide as fallback his hown PSR-4 like autoloader).

Coding standards:

The code is very close to the respect of PSR-1 (lacks only the naming of methods), and freely influenced by PSR-2 when it is not unnecessarily authoritarian.


Benchmark on a modern machine (linux - x64 - php 5.6) of a large use of methods and algorithms. With relatively complex voting scenarios excluding cache use.
In pratice, Condorcet knows proceed more aggressive (cache, partial computation ...).

Memory usage : less than 2M
Execution time : less than 120ms

Kemeny-Youg case :

use Kemeny-Young 6 candidates : 5MB - 220ms
use Kemeny-Young 7 candidates : 32MB - 900ms
use Kemeny-Young 8 candidates : 135MB - 3500ms

Project State

To date, we have a stable version, and support is provided.

  • Since version 0.90, significant structural changes have strong evolutionary implementation of the API. Including a full object management of the Votes and Candidate, in addition to the old and easier string conceptualization.
  • Some support and fix can be done for 0.14 version on demand.

External testers are more than welcome.

Related projects / They use Condorcet
  • From August 2014: Condorcet.Vote Web services to create and store online Condorcet election. Including intérractives and collaborative features.
    It is based in large part on this project, and uses the library as a real election manager for computing, storage & stats.
  • Mahler-S2-BlindTest-Condorcet (french interface) Web wrapper to compute and show result for classical music blind challenge with the Condorcet Class full potential (can also be used and adapted for any elections).
    Look like the examples provided here, but better : Gustav Mahler blind listening test

Key Features


  • Advanced Management for votes and candidates. Support both simple calls or full object management.
  • Voting management and inter-elections candidates. Many input supported (array, Json, object, string representation...)
  • Computing Pairwise, Natural Condorcet Winner or Loser
  • Algorithms implements (fully or partially) the criteria of the Marquis de Condorcet.
  • Support for storing elections
  • Ready to be extend, or support your own algorithms.
  • [...]

Supported Condorcet Methods

More information on Condorcet Wiki

Add new one?

This class is designed to be easily extensible with new algorithms. A modular schematic is already used for all algorithms provided, so you can easily help, do not forget to make a pull request!
More explanations in the documentation below

Roadmap for futher releases

  • Better cache system to prevent any full computing of the Pairwise on new vote / remove vote
  • Improve & test Ranked pair implementation (help needed!)
  • Add tie breaking on Schulze Core, by the official way recommended by Markus Schulze. (help needed!)
  • In future results could be provided as a new object Coondorcet\Result rather than an array. Will be fun.
  • Looking for testers!
  • Research reference librarians!!

How to use it?

I have undertaken and continues to undertake efforts to reform and improve the documentation. Thereof is not yet satisfactory plainement nor perfectly updated. Your help is welcome! Consider reading the functional examples that are very explicit, test your even the entire function package, and especially to ask questions!

Condorcet Wiki Manual

Living and learning examples, giving an overview but not exhaustive of the possibilities of the library.

Class & Methods reference

The precise documentation of methods is not a wiki. It can be found in the form of Markdown in the "doc" folder for each release.


Condorcet Class Implementation

This example of implementation in others project can very nice or strange... They can be current, or otherwise affect older versions of Condorcet.

Great overview With html output basics examples Really quick and simple example

OK : sacrifice to the local tradition of lazy.

  use Condorcet\Condorcet;
  use Condorcet\Election;
  use Condorcet\Candidate;
  use Condorcet\Vote;

  $myElection1 = new Election () ;

  // Create your own candidate object
  $candidate1 = new Candidate ('Candidate 1'); 
  $candidate2 = new Candidate ('Candidate 2');
  $candidate3 = new Candidate ('Candidate 3');

  // Register your candidates
  $candidate4 = $myElection1->addCandidate('Candidate 4');

  // Add some votes, by some ways
  $myElection1->addVote( array(
                              $candidate2, // 1
                              [$candidate1, $candidate4] // 2 - Tie
                              // Last rank is optionnal. Here it's : $candidate3

  $myElection1->addVote('Candidate 2 > Candidate 3 > Candidate 4 = Candidate 1'); // last rank can also be omitted

              'tagX || Candidate 1 > Candidate 2 = Candidate 4 > Candidate 3 * 4
              tagX, tagY || Candidate 3 > Candidate 1 * 3'
  ); // Powerfull, it add 7 votes

  $myElection1->addVote( new Vote ( array(
                                        // You can ignore the over. They will be at the last rank in the contexte of each election.
  )  ));

  // Get Result

    // Natural Condorcet Winner
    $myWinner = $myElection1->getWinner(); // Return a candidate object
          echo 'My winner is ' . $myWinner->getName() . '<br>' ;

    // Natural Condorcet Loser
    $myLoser = $myElection1->getLoser(); // Return a candidate object
          echo 'My loser is ' . $myLoser->getName() ;

    // Schulze Ranking
    $myResultBySchulze = $myElection1->getResult('Schulze'); // Return a multi-dimensional array, filled with objects Candidate (multi-dimensional if tie on a rank)
      # Echo it easily 

    // Get Schulze advanced computing data & stats
    $mySchulzeStats = $myElection1->getResultStats('Schulze');

    // Get Copeland Ranking
    $myResultByCopeland = $myElection1->getResult('Copeland');

    // Get Pairwise
    $myPairwise = $myElection1->getPairwise();

  // How long computation time behind us?
  $timer = $myElection1->getGlobalTimer();

  // SHA-2 checksum and sleep
  $myChecksum = $myElection1->getChecksum();
  $toStore = serialize($myElection1);  // You can now unset you $candidate1 & co. On wake up, Condorcet election will build distinct with new reference.

  # And many many more than that. Read the doc. & look advanced examples.