Giter Site home page Giter Site logo

julien-boudry / condorcet Goto Github PK

View Code? Open in Web Editor NEW
117.0 11.0 13.0 15.71 MB

Command line application and PHP library, providing an election engine with a high-level interface. Native support 20+ voting methods, easy to extend. Support simple elections with ease or billions of votes in low resource environment. Intensively tested and highly polyvalent.

Home Page: https://www.condorcet.io

License: MIT License

PHP 99.74% Dockerfile 0.15% Shell 0.12%
condorcet election-polling election election-reform copeland minimax vote ranked-pairs dodgson kemeny-young

condorcet's Introduction

Condorcet

Open in GitHub Codespaces

License Packagist Docker Pulls Packagist Download GitHub contributors

Codacy Badge GitHub code size in bytes Codacy Badge Build Status

Main Author: Julien Boudry
License: MIT - Please say hello if you like or use this code!
Contribute: Contribute File
Donation: bc1q3jllk3qd9fjvvuqy07tawkv7t6h7qjf55fc2gh or Github Sponsor Page
You can also offer me a bottle of good wine.

Condorcet PHP

Presentation | Documentation Book | API References | Voting Methods | Tests

Condorcet manages the stages of an electoral process (configuration, votes ingestion & manipulation, integrity) and calculates the results. It offers natively the implementation of more than 20 voting methods compatible with preferential voting ballots, including Condorcet methods, Alternative Voting, STV, and many others. => Supported Voting Methods

Two different ways to use Condorcet:

  • A command line application, for quick use of essential features without complicated technical knowledge. Allowing you to easily compute your election results and stats.
  • A PHP library that you can include in your code to take advantage of 100% of the advanced features (advanced manipulations & configurations, extensions & modularity, cache & high performances simulations, advanced input and output methods...).

Both approaches can handle up to hundreds of millions of votes (or more) on modest hardware. Although using it as a library will allow more configuration and control over this advanced usage.

Summary

Project State and Specifications

Releases Notes

Version PHP Requirements State Support
4.6 8.2 Stable support provided
3.x 8.1 Old Stable not any support
2.2 7.4 Old Stable support requiring some bait
2.0 7.1 Old Stable not any support
1.0 5.6 Old Stable not any support
0.9x 5.5 Old Stable ❌ ℹ Since v0.90, you should consider then it's a new project (api, engine).
0.14 5.5 Old Stable ready for the museum

All versions require Json and Mbstring extensions (or polyfill). Pdo-Sqlite is recommended if you need to activate the default provided driver for bigs elections (hundred of thousands of votes or more)

Supported Voting Methods

Support both single-winner methods (with or without the Condorcet criterion) and proportional methods.

Complete list of natively implemented methods, their options (variants), and implementation choices

Single-Winner Methods provided natively

Single Winner returns a full ranking of all candidates, even though they are generally more designed to designate only one.

Deterministic

Condorcet / Borda (+ Nauru variant) / Copeland / Dodgson (2 Approximations) / FTPT / Instant-runoff (alternative vote) / Kemeny–Young / Minimax (+ variants) / Ranked Pairs (+ variants) / Schulze (+ variants)

Lotteries

Random Ballot / Random Candidates

Proportional Methods provided natively

Designed for electing assembly, return a full ranking of elected candidates.

Single Transferable Vote (STV) / Comparison of Pairs of Outcomes by the Single Transferable Vote (CPO-STV) / Highest Averages Methods (Sainte-Laguë, Jefferson/D'Hondt, and variants) / Largest Remainder Methods (with different quotas)

Add your own voting method as a module

Condorcet is designed to be easily extensible with new algorithms (they don't need to share the same namespace).

Main features

  • Manage an election
    • Respect an election cycle: Registering candidates, registers votes, gets results from many algorithms.
    • Ordered votes, tags votes, delete votes, simulates partial results.
    • Many input types available (string, Json, objects...)
    • Import from Condorcet Election Format (and export to), Debian Format, David Hill Format
    • Integrity check (checksumming)
    • Support for storing elections (serializing Election object, export data...)
    • Some methods can be used nearly front final user (vote constraints, anti-spam check, parsing input, human-friendly results and stats...)
  • Get election results and stats
    • Get the natural Condorcet Winner, Loser, Pairwise, Paradox...
    • Get full ranking from advanced voting methods
    • Get some additional stats from these methods
    • Force ranking all candidates implicitly (default) or allow voters to not rank all candidates.
    • Put weight on a certain vote, and give more importance to certain voters.
  • Be more powerful
    • All are objects, all are abstract (But there are many higher-level functions and inputs types).
    • Candidates and Votes are objects which can take part in multiple elections at the same time and change their name or ranking dynamically. That allows powerful tools to simulate elections.
    • Manage hundred of billions of votes by activating an external driver to store (instead of RAM) an unlimited number of votes during the computation phase. A PDO driver is provided by default, an example is provided with SQLite, an interface that allows you to design other drivers.
    • Smart cache system, allows calling multiple time computation methods without performance issues.
  • Extend it! Configure it!
    • Modular architecture to extend it without fork Condorcet PHP! Just make your module on your own namespace.
      • Election, Candidate, and Vote classes are extensible.
      • Add your own ranking algorithm.
      • Create your own vote constraints.
      • Use your own datastore driver to manage very large elections on your way without ram limit.
    • Many configuration options and methods.

Condorcet PHP is not designed for high performance. But can handle virtually unlimited voting without limit or degrading performance, it's a linear and predictable scheme.
And has no certification or proven implementation that would guarantee a very high level of reliability. However, there are many written tests for each voting method and feature. This ensures an excellent level of confidence in the results.


Use Condorcet as a command line application

Install as a command line application

Can be installed natively from source (with composer), from PHAR file, from Docker image (build or pull).

Condorcet as a command line application, installation instructions

Condorcet Book - Command Line

Use Condorcet as a PHP Library

Install / Autoloading

Namespace \CondorcetPHP\Condorcet is used.

Can be installed as you prefer with: Composer / Natively provided autoloader / Any PSR-4 compatible autoloader.

Condorcet as a PHP library, installation instruction

Library Manual

Visit the Documentation Book

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

Class & API References

The precise documentation of methods can be found in the form of Markdown in the "Documentation" folder for each release.

Class & API References

PHP Library - Examples

Overview

With Html output basics examples

Specifics examples

Performance & Coding style considerations

Coding standards:

The code is very close to the respect of PSR-12 (lacks only the naming of methods) when it is not unnecessarily authoritarian or conservative and follows some additional rules. Code is checked and fixed with CS-Fixer custom rules through Laravel Pint.

Performance:

  • Complete and huge use case with all voting methods chained, 6 candidates, 2 seats, and one thousand votes (many with implicit ranking).
    • Memory usage: less than 3M
    • Execution time (after Jit compiling): less than 160ms
    • Execution time (without JIT): less than 250ms

But essentially because some voting methods are slow by design and others (like Schulze) are very fast. Have a look on methods benchmarks.

Kemeny-Youg case:

1 000 randoms votes. Memory consumption comes from votes more than combinations.

  • use Kemeny-Young 7 candidates: ~5MB - 10ms
  • use Kemeny-Young 8 candidates: ~6MB - 10ms
  • use Kemeny-Young 9 candidates: ~7MB - 1.1s
  • use Kemeny-Young 10 candidates: ~7MB - 14s
  • use Kemeny-Young 11 candidates: ~8MB - 193s
Massive election case:

Extending PHP memory_limit allows you to manage hundreds of thousands of votes, but it can be a bit slower than outsourcing this data (PHP doesn't like that) and it's not extensive to infinity.

If you need to manage an election with more than 50 000 votes. You should consider externalizing your data, Condorcet provides a simple PDO driver to store data outside RAM between processing steps, this driver stores it into a classical relational database system, and it supports hundreds of millions of votes (or more). A very simple example with Sqlite is provided and very easy to activate.

You can also develop your homemade datastore driver (to store into NoSQL... all your fantasy), the modular architecture allows you to link it easily.

Have a look at the documentation book

Benchmark on a modern machine (linux - x64 - php 8.1 - cli).

Roadmap for further releases

  • ...

Related projects / They use Condorcet

See the list of known projects, add yours!

condorcet's People

Contributors

christelle-r avatar cyberkurumin avatar dependabot[bot] avatar julien-boudry avatar kynoptic avatar liamm32 avatar orthographic-pedant avatar toddy15 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

condorcet's Issues

Boring Kemeny-Young... more than 6 candidates...

I am looking for a way to create pre-computed data sets for Kemeny-Young, and election support having more than 6 candidates.

Unfortunately, my solution for calculating permutations sets PHP has its limits. Also, I'm looking at pre-determined this type of data sets:

a: 2: {i: 1; a: 2: {i: 1; s: 2: "C0"; i: 2; s: 2: "C1";} i: 2; a: 2: {i: 1; s: 2: "C1"; i: 2; s: 2: "C0";}}
(Kemeny-Young for two candidates)

It's actually all the possible designation of an election for X candidates.

I schedule to test alternative impentative in Ruby to generate this pre-computed data. Aim it's so boring ... And there he has a chance of easy success?

If someone want to help, he is welcome!

Condorcet/lib/Condorcet/algorithms/KemenyYoung-Data

Rewrite Ranked Pairs (Still experimental to date)

Since his introduction into version 0.10, Randked Pairs method implementation is know as experimental (and clearly marked into the documentation). It's working well in a large majority of case, and in any honest election with many various vote.

But it fail because it can't output tie and chose arbitrary result in this case.

Randked pairs mus be largely rewrite to success this tests :
http://ericgorr.net/condorcet/rankedpairs/example3/
http://ericgorr.net/condorcet/rankedpairs/example4/

One should also consider adding a Randked Pairs variant using the margin in place of the winning majority.

Don't forget the doc :
image

Implement PHP 8.1 new features

  • Readonly Properties

  • Final Class Constants

  • Never return Type (especially for tests)

  • New in initializers?

  • Deprecation & Others minors changes

  • Enum for Election State?

  • Enum with STV Quotas

  • Restrict method options to Enum|int value?

  • Fix documentation for Enum

  • Update Wiki documentation for StvQuotas

  • Github Workflow

  • Composer Requierements

  • Docker File (final release, not RC)

JIT tracing bug with STV in conjunction with non proportional method (only PHP 8.0 with JIT tracing mode enabled)

Q A
Type Bug / Support / Suggestion / Other
Condorcet version 3.1.0 && 3.2.0
PHP version 8.0.10 (NTS, x64, Linux + Windows) && PHP 8.1-RC6
Installation Method __CondorcetAutoload.php

See this failing code

just git clone from actual master branch for 3.2 branch with PHP 8.1 ; branch dev-3.1 for 3.1 with PHP 8.0

Linux:
php -dzend_extension=opcache -dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M -dopcache.jit=tracing Dev/bugs/JitBug.php

Windows:
php -d zend_extension=opcache -d opcache.enable_cli=1 -d opcache.jit_buffer_size=100M -d opcache.jit=tracing Dev/bugs/JitBug.php

Unable to reproduce in theoric PHP (after many trials), it's a JIT optimization bug that only happens in Condorcet when using STV in conjunction with a non-proportional method.

  • The bug only with jit "tracing" mode (working with jit "function" mode) (test on PHP 8.0.10 NTS on x64)
  • Working with or without opcache, the bug only if using jit tracing mode (which is the default for JIT)
  • It's working fine with PHP 8.1-RC1... and it's buggy with RC6
  • No bug if you remove named parameter from the call (new Result ([...])

The bug:

PHP Fatal error:  Uncaught TypeError: CondorcetPHP\Condorcet\Result::__construct(): Argument #6 ($seats) must be of type ?int, CondorcetPHP\Condorcet\Election given, called in C:\dev_scripts\Condorcet\lib\Algo\Method.php on line 84 and defined in C:\dev_scripts\Condorcet\lib\Result.php:89
Stack trace:
#0 C:\dev_scripts\Condorcet\lib\Algo\Method.php(84): CondorcetPHP\Condorcet\Result->__construct()
#1 C:\dev_scripts\Condorcet\lib\Algo\Methods\STV\SingleTransferableVote.php(91): CondorcetPHP\Condorcet\Algo\Method->createResult()
#2 C:\dev_scripts\Condorcet\lib\Algo\Method.php(63): CondorcetPHP\Condorcet\Algo\Methods\STV\SingleTransferableVote->compute()
#3 C:\dev_scripts\Condorcet\lib\ElectionProcess\ResultsProcess.php(80): CondorcetPHP\Condorcet\Algo\Method->getResult()
#4 C:\dev_scripts\Condorcet\Dev\bugs\JitBug.php(37): CondorcetPHP\Condorcet\Election->getResult()
#5 {main}

It looks impossible if you have a look on Condorcet\lib\Algo\Method.php(84): CondorcetPHP\Condorcet\Result->__construct() and Election->getNumberOfSeats() which is typed to integer.

Pb with symphony Command/Command.php

Q A
Type Bug
Condorcet version 2.2.3
PHP version 7.4.3
Installation Method Composer

Using

./vendor/bin/condorcet election --candidates listeLigne.txt --votes voteCA.txt -r

I get the following error:

PHP Fatal error:  Uncaught Error: Call to a member function getName() on null in /home/mc/Bureau/Condorcet-master/Condorcet/vendor/julien-boudry/condorcet/lib/Console/Commands/ElectionCommand.php:254
Stack trace:
#0 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/symfony/console/Command/Command.php(299): CondorcetPHP\Condorcet\Console\Commands\ElectionCommand->execute()
#1 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/symfony/console/Application.php(978): Symfony\Component\Console\Command\Command->run()
#2 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/symfony/console/Application.php(295): Symfony\Component\Console\Application->doRunCommand()
#3 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun()
#4 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/julien-boudry/condorcet/lib/Console/CondorcetApplication.php(25): Symfony\Component\Console\Application->run()
#5 /home/mc/Bureau/Condorcet-master/Condorcet/vendor/julien-boudry/condorcet/bin in /home/mc/Bureau/Condorcet-master/Condorcet/vendor/julien-boudry/condorcet/lib/Console/Commands/ElectionCommand.php on line 254

My files are the following (on a simple test, everything works well):

listeLigne.txt

association-gut.eu;association-gut.fr;association-gut.info;association-gut.net;association-gut.org;association-gutenberg.eu;association-gutenberg.info;associationgutenberg.eu;associationgutenberg.fr;associationgutenberg.info;associationgutenberg.net;associationgutenberg.org;asso-gut.eu;asso-gut.fr;asso-gut.info;asso-gut.net;asso-gut.org;asso-gutenberg.eu;asso-gutenberg.info;fr.tug.org;francogut.eu;francogut.fr;francogut.info;francogut.net;francogut.org;francotug.eu;francotug.fr;francotug.info;francotug.net;francotug.org;groupetex.eu;groupetex.fr;groupetex.info;groupetex.net;groupetex.org;grtex.eu;grtex.fr;grtex.info;grtex.net;grtex.org;grutex.eu;grutex.fr;grutex.info;grutex.net;grutex.org;gutambergue.eu;gutambergue.fr;gutambergue.info;gutambergue.net;gutambergue.org;gutanbergue.eu;gutanbergue.fr;gutanbergue.info;gutanbergue.net;gutanbergue.org;gut-asso.eu;gut-asso.fr;gut-asso.info;gut-asso.net;gut-asso.org;gut-association.eu;gut-association.fr;gut-association.info;gut-association.net;gut-association.org;gutemberg.eu;gutemberg.info;gutenber.eu;gutenber.fr;gutenber.info;gutenber.net;gutenberg.fr;gutenberg-asso.eu;gutenberg-asso.fr;gutenberg-asso.info;gutenberg-asso.net;gutenberg-asso.org;gutenberg-association.eu;gutenberg-association.fr;gutenberg-association.info;gutenberg-association.net;gutenberg-association.org;gutenberg-france.eu;gutenberg-france.fr;gutenberg-france.info;gutenberg-france.net;gutenberg-france.org;gutenberg-latex.eu;gutenberg-latex.fr;gutenberg-latex.info;gutenberg-latex.net;gutenberg-latex.org;gutenberglatex.eu;gutenberglatex.fr;gutenberglatex.info;gutenberglatex.net;gutenberglatex.org;gutenberg-tex.eu;gutenberg-tex.fr;gutenberg-tex.info;gutenberg-tex.net;gutenberg-tex.org;gutenferg.eu;gutenferg.fr;gutenferg.info;gutenferg.net;gutenferg.org;gutenfr.eu;gutenfr.fr;gutenfr.info;gutenfr.net;gutenfr.org;gutenvers.eu;gutenvers.fr;gutenvers.info;gutenvers.net;gutenvers.org;gutex.fr;gutexberg.eu;gutexberg.fr;gutexberg.info;gutexberg.net;gutexberg.org;gut-fr.eu;gut-fr.fr;gut-fr.info;gut-fr.net;gut-fr.org;gut-latex.eu;gut-latex.fr;gut-latex.info;gut-latex.net;gut-latex.org;gutnber.eu;gutnber.fr;gutnber.info;gutnber.net;gutnber.org;gutnberg.eu;gutnberg.fr;gutnberg.info;gutnberg.net;gut-tex.eu;gut-tex.fr;gut-tex.info;gut-tex.net;gut-tex.org;jgutenberg.eu;jgutenberg.fr;jgutenberg.info;jgutenberg.net;jgutenberg.org;texgutenberg.eu;texgutenberg.fr;texgutenberg.info;texgutenberg.net;texgutenberg.org;tug-fr.eu;tug-fr.fr;tug-fr.info;tug-fr.net;tug-fr.org;tug-french.eu;tug-french.fr;tug-french.info;tug-french.net;tug-french.org

and voteCA.txt

associationgutenberg.fr>associationgutenberg.net>associationgutenberg.org>gutenberg-asso.fr>gutenberg-asso.net>gutenberg-asso.org>gutenberg-association.fr>gutenberg-association.net>gutenberg-association.org>gut-asso.fr>gut-asso.net>gut-asso.org>association-gut.fr>association-gut.net>association-gut.org;
association-gutenberg.info>gutenberg-association.fr>gutenberg-association.org>gutenberg-association.info>gutenberg-association.net>asso-gutenberg.info>gutenberg-asso.fr>gutenberg-asso.org>gutenberg-asso.info>gutenberg-asso.net>gutenberg-latex.fr>gutenberg-latex.org>gutenberg-latex.info>gutenberg-latex.net>gutenberg-tex.fr>gutenberg-tex.org>gutenberg-tex.info>gutenberg-tex.net>associationgutenberg.fr>associationgutenberg.org>associationgutenberg.info>associationgutenberg.net;
associationgutenberg.fr>gutenberg-association.fr>gutenberg-latex.fr>association-gutenberg.info>associationgutenberg.org>associationgutenberg.net>associationgutenberg.info>gutenberg-latex.info>gutenberg-latex.net>gutenberg-latex.org>gutenberg-association.org>gutenberg-association.net>gutenberg-association.info>tug-fr.org>tug-fr.net>groupetex.org;
association-gutenberg.fr>association-gut.fr>asso-gutenberg.fr>asso-gut.fr>gut-asso.fr>gutenberg-association.fr>association-gutenberg.org>association-gut.org>asso-gutenberg.org>asso-gut.org>gut-asso.org>gutenberg-association.org>gutenberg-asso.org;
asso-gut.org>asso-gut.fr>gut-asso.org>gut-asso.fr>association-gut.org>gut-association.org>gut-association.fr>gut-latex.org>gut-latex.fr>gutenberg-latex.org>gutenberg-latex.fr>gutenberg-tex.org>gutenberg-tex.fr>asso-gutenberg.eu
association-gut.fr>association-gut.org>association-gutenberg.fr>association-gutenberg.org>asso-gut.fr>asso-gut.org>asso-gutenberg.fr>asso-gutenberg.org>gutenberg.fr>gutenberg.org>gutenberg-asso.fr>gutenberg-asso.org>gutenberg-association.fr>gutenberg-association.org;
gutenberg.fr>gutex.fr>groupetex.fr>groupetex.org>gutenberg.eu.org>jgutenberg.eu>jgutenberg.fr>jgutenberg.org>grtex.fr>grutex.org;
associationgutenberg.fr>associationgutenberg.org>gutenberg-association.fr>gutenberg-association.org>gutenberg-asso.fr>gutenberg-asso.org>gutenberg-tex.fr>gutenberg-tex.org>association-gut.fr>association-gut.org;
associationgutenberg.fr>associationgutenberg.org>gutenberg-association.fr>gutenberg-association.org>gutenberg-asso.fr>gutenberg-asso.org>gutenberg-asso.fr>gutenberg-asso.org>gutenberg-latex.fr>gutenberg-latex.org>gutenberg-tex.fr>gutenberg-tex.org>gutenberg-latex.net>gutenberg-tex.net>association-gut.fr>association-gut.org>gut-asso.fr>gut-asso.org

Any idea? Maybe is it due to the dots and the dashes in each domain name?

Thx

Typos

The result page on https://www.condorcet.vote possibly contains typos:

  1. Optionnal -> Optional
  2. personnal -> personal
  3. This URL can be use by anyone to vote -> This URL can be used by anyone to vote
  4. Schulze (Winning variant, recommand by M.Schulze itself) . -> Schulze (Winning variant, recommended by M. Schulze himself).
  5. Vote tag or number separated by semicolon. -> Vote tags or numbers separated by semicolons.

How to have = using a vote form?

Q A
Type Support
Concorcet version 2.x
PHP version 7.4
Installation Method __CondorcetAutoload.php

Consider this form:

<html>
    <body>
        <form method="post">
        Wingspan: <select name="item[Wingspan]" id="Wingspan">
                         <option value="1">1</option>
                         <option value="2">2</option>
                         <option value="3">3</option>
                         <option value="4">4</option>
                 </select><br />
        Scythe:  <select name="item[Scythe]" id="Scythe">
                         <option value="1">1</option>
                         <option value="2">2</option>
                         <option value="3">3</option>
                         <option value="4">4</option>
                 </select><br />
        Spirit Island: <select name="item[Spirit Island]" id="Spirit Island">
                         <option value="1">1</option>
                         <option value="2">2</option>
                         <option value="3">3</option>
                         <option value="4">4</option>
                  </select><br />
        Everdell: <select name="item[Everdell]" id="Everdell">
                         <option value="1">1</option>
                         <option value="2">2</option>
                         <option value="3">3</option>
                         <option value="4">4</option>
                  </select<br />
        <input type="submit" name="submit" value="submit">
        </form>
    </body>
</html>

Then this code

foreach ($_POST['item'] as $game => $priority) {
        $games[] = $game;
}

This outputs:

Array
(
    [0] => Wingspan
    [1] => Scythe
    [2] => Spirit Island
    [3] => Everdell
)

Then this Condorcet:

    Condorcet::setDefaultMethod('Schulze'); // Argument: A supported method  

    $election = new Election ();

    $election->addCandidate(new Candidate ('Wingspan'));
    $election->addCandidate(new Candidate ('Scythe'));
    $election->addCandidate(new Candidate ('Spirit Island'));
    $election->addCandidate(new Candidate ('Everdell'));


$vote = new Vote ( $games );
$election->addVote($vote);  
print_r($vote->getSimpleRanking());

echo 'Schulze winner is : ' . $election->getWinner('Schulze')->getName() . '<br />';

However it works great but what if two candidates got the same rank? and what if have to have = ? I know the solution is with foreach() but I am stuck with it?

incompatible offsetUnset with ArrayManager in VotesManager

Fatal error: Declaration of Condorcet\DataManager\VotesManager::offsetUnset($offset): void must be compatible with Condorcet\DataManager\ArrayManager::offsetUnset($offset): bool in vendor/julien-boudry/condorcet/lib/DataManager/VotesManager.php on line 18

fetched votes from db and taking the vote

Q A
Type Support
Concorcet version 2.x
PHP version 7.4
Installation Method Composer

I have this:

    use CondorcetPHP\Condorcet\Condorcet;
    use CondorcetPHP\Condorcet\Election;
    use CondorcetPHP\Condorcet\Candidate;
    use CondorcetPHP\Condorcet\CondorcetUtil;
    use CondorcetPHP\Condorcet\Vote;

    require_once ("./vendor/autoload.php");
    
    Condorcet::setDefaultMethod('Schulze'); 

    $election = new Election ();

   $votes = $em->getRepository('Entities\Vote')->findBy(['categoryId' => $_GET['id']]);
   foreach ($votes as $vote){
            $result[] = $vote->getVote();
            $vote1 = new Vote ( $vote->getVote() );
            $election->addVote($vote1); 
   }
   
 
 print_r($election->countVotes ());

print("<br />");
foreach ($election->getResult('Schulze') as $rank => $candidates) :

    echo 'Rank ' . $rank . ': ';
    echo implode(', ', $candidates);
    echo '<br />';
    
endforeach;

echo 'Schulze winner is : ' . $election->getWinner('Schulze')->getName() . '<br />';

//print_r($result);

This $vote->getVote() returns votes from db with this format:
Brass Birmingham = Scythe > Concordia = Gaia Project = On Mars > Power Grid = Terraforming Mars > A Feast for Odin = Everdell = Spirit Island = Through the Ages > Terra Mystica = Wingspan > Gloomhaven

I get:
Uncaught CondorcetPHP\Condorcet\Throwable\CondorcetException: [20]: You need to specify one or more candidates before voting (line: /home2/phplicen/public_html/shultze/vendor/julien-boudry/condorcet/lib/Election.php:320) thrown in vendor/julien-boudry/condorcet/lib/Election.php on line 320

Does this mean that I should define each individual candidate items again? why for getting the final result I should define individual candidates again?

How do you output election results as a file when using the command line?

Q A
Type Support
Condorcet version 3.0.2
PHP version n/a
Installation Method Docker container public image

When running a simple election command from the command line, is there a way to output the results as a file? I would like to output a simple CSV with rank,candidate headers. Is this possible?

Is it possible to use ranking for a single candidate?

Q A
Type Support
Concorcet version 2.2.3
PHP version 7.4
Installation Method __CondorcetAutoload.php

Imagine we have only one candidate and users vote for it from 1= worst to 5 = the best. Then how to use Condorcet? I used below but it seems I am wrong, please advise.

    $election->addCandidate(new Candidate ('Candidate1'));
    $json_votes = json_encode([
	['vote' => '1'], // A user voted 1 as the worst.
	['vote' => '2'],
	['vote' => '3']]); // Another user voted 5 as the best.
   $vote = new Vote('Candidate1');
   $ranking = $vote->setRanking ($json_votes);

Zip download is missing most of the folders

Q A
Type Bug
Concorcet version 1.6.0
PHP version N/A
Installation Method N/A

I just downloaded the current zip file and the only folder included it "lib". All other folders including "Examples" appear to be missing from the zip.

Election.php file giving Parse errors

| Q Election.php throwing Parse Error
| --------------------| ---------------
| Type | Support
| Condorcet version | 3.1.0
| PHP version | 7.3.29
| Installation Method | __CondorcetAutoload.php

protected static ?int $_maxParseIteration = null; protected static ?int $_maxVoteNumber = null;

These two lines are causing the below error. I tried doing some debugging and different methods to fix but had simillar issues across the file. What may be causing me to get this issue and any suggestions on how to fix it? I was given a partially done research project to try and working without any prior instructions other than the errors telling me it couldn't find the __CondorcetAutoload.php so I started trying to get this working.

Thanks!

Parse error: syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST) in C:\Users\mcurr\Documents\GitHub\CondorcetPHP\lib\Election.php on line 28

condorcet.vote is unfinished

I think condorcet.vote is quite unfinished. You're only allowed to enter alphanumeric characters, and the translation is horrible.

Kemeny-Young : Multiple best score

(Since Version 0.8)

I do not know how in the very unlikely event that several possible classifications have the same highest score.
In the current state, one of them is chosen arbitrarily.

Gets stuck at "Results per Methods" when running the program using InstantRunoff

Q A
Type Bug
Condorcet version 3.0.0
PHP version 8.0.0
Installation Method Composer
condorcet election -c c.txt -w w.txt InstantRunoff

Sum Up
------

21 Candidates(s) Registered  ||  32 Vote(s) Registered
==========================
 ------------------------------------------------------------- -------
  Is vote weight allowed?                                       FALSE
 ------------------------------------------------------------- -------
  Votes are evaluated according to the implicit ranking rule?   TRUE
 ------------------------------------------------------------- -------
  Is vote tie in rank allowed?                                  FALSE
 ------------------------------------------------------------- -------

Results per Methods
-------------------

Then it gets stuck. CPU use raises to 30%, and memory use raises as well.

simple explanation

Q A
Type Support
Concorcet version 2.x
PHP version 7.4
Installation Method Composer

Please give simple explanation what are weight and tag and what are their purposes?

Add Vote method: Ranking from a simple string

Q A
Type Support
Concorcet version 3
PHP version 7.4
Installation Method Composer

I need clarification about below. For example if candidate1 gets 1 from a voter and gets 2 from another voter, how should I use > among them? How do I know if this is A > B or B >A?

  // Add some votes, by some ways
  $myElection1->addVote(  [
                              $candidate2, // 1
                              [$candidate1, $candidate4] // 2 - Tie
                              // Last rank is optionnal. By default, it will be implicitly completed in $candidate3. This behaviour can be changed by election, before, during or after the vote. The initial submission being preserved.
                          ]
  );

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

  $myElection1->parseVotes(
              'Candidate 1 > Candidate 2 = Candidate 4 > Candidate 3 * 4
              Candidate 3 > Candidate 1 * 3'
  );

Syntax Error L.1123 -> Condorcet.php

Parse error: syntax error, unexpected '[' in C:\xampp\htdocs\condorcet\lib\Condorcet\Condorcet.php on line 1123

return $this->getResult($algo)[1] ;

Dodgson

When I use examples from Some Remarks on Dodgson’s Voting Rule then www.condorcet.vote delivers different results than expected. Is it because the implementation provides optimistic estimates on the count of "swaps"? If so, it should be noted in the documentation.

Example 1:

D>A>B>C*1
A>D>B>C*1
A>B>C>D*2
D>B>C>A*2
C>A>B>D*2
B>C>A>D*2
D>C>A>B*2

Expected winner: A
Delivered winner: D

Example 2:

B>A>C>D*5
A>C>B>D*5
A>B>D>C*9
B>D>C>A*9
C>A>D>B*15

Expected winner: A
Delivered winner: C

Typo in the issue template

Q A
Type Bug / Support / Suggestion / Other
Concorcet version x.y.z
PHP version x.y.z
Installation Method Composer / __CondorcetAutoload.php / Custom

Probably missing attribute classes?

Q A
Type Bug
Concorcet version 3.0.1
PHP version 8.0.3
Installation Method Custom

Hi,

first, thanks a lot for this very nice library. I'm looking into the source code and cloned your repository. While browsing your sources, I noticed that you're using the new attributes feature of PHP8.

However, you write e.g. this:
use CondorcetPHP\Condorcet\CondorcetDocAttributes\{Description, Examples, FunctionReturn, PublicAPI, Related};

There are no corresponding classes, there is not even a "CondorcetDocAttributes" folder in your project. Maybe you've created those files locally and did not yet add them to the git repository?

Regards,
Tobias

English

Improvement of the english of the documentation.

getWinner & getName: various questions

Q A
Type Bug / Support
Concorcet version 2.x
PHP version 7.4
Installation Method __CondorcetAutoload.php

Beside my another question regarding = in my another issue, I have another problem too:

if (isset($_POST) && $_POST != "") {

    arsort($_POST['item']);
    foreach ($_POST['item'] as $game => $priority) {
         $games[] = $game;
    }
    Condorcet::setDefaultMethod('Schulze'); // Argument: A supported method  

    $election = new Election ();

    $election->addCandidate(new Candidate ('Wingspan'));
    $election->addCandidate(new Candidate ('Scythe'));
    $election->addCandidate(new Candidate ('Spirit Island'));
    $election->addCandidate(new Candidate ('Everdell'));

    $vote1 = new Vote ( $games );
    $election->addVote($vote1);  

    $vote2 = new Vote ( 'Scythe > Spirit Island = Everdell = Wingspan' );
    $election->addVote($vote2);

   $result = $election->getResult();

   echo 'Schulze winner is : ' . $election->getWinner('Schulze')->getName() . '<br />';
}

If I have only one $vote, it works fine, but if I have both vote as above, I get this error:
Fatal error: Uncaught Error: Call to a member function getName() on array

Isn't it a bug? or I did a mistake?

change of pdo_sqlite to pdo_mysql

Q A
Type Bug / Support
Concorcet version 2.x.x
PHP version 7.4
Installation Method __CondorcetAutoload.php

I changed this

$pdo_object = new \PDO ('sqlite:'.__DIR__.'/bdd.sqlite');

to this:

    $pdo_object = new \PDO('mysql:host=127.0.0.1;dbname=dbtest', 'dbuser', 'dbpass');

and I got below. What should I do?

[26-Apr-2021 07:53:34 America/Chicago] PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AUTO_INCREMENT INTEGER PRIMARY KEY NOT NULL , data BLOB NOT NULL )' at line 1 in vendor/julien-boudry/condorcet/lib/DataManager/DataHandlerDrivers/PdoDriver/PdoHandlerDriver.php:70
Stack trace:
#0 vendor/julien-boudry/condorcet/lib/DataManager/DataHandlerDrivers/PdoDriver/PdoHandlerDriver.php(70): PDO->exec('CREATE TABLE IF...')
#1 vendor/julien-boudry/condorcet/lib/DataManager/DataHandlerDrivers/PdoDriver/PdoHandlerDriver.php(48): CondorcetPHP\Condorcet\DataManager\DataHandlerDrivers\PdoDriver\PdoHandlerDriver->createTable()
#2 vendor/julien-boudry/condorcet/Examples/Specifics_Examples/use_large_election_external_database_drivers.php(44): CondorcetPHP\Condo in vendor/julien-boudry/condorcet/lib/DataManager/DataHandlerDrivers/PdoDriver/PdoHandlerDriver.php on line 70

EDIT:
The query '...AUTO_INCREMENT INTEGER PRIMARY KEY NOT NULL , data BLOB
NOT NULL...' doesn't seem to be valid on MySQL.

You mentioned "We will use PDO SQLITE, but can
be MySQL or else" but it doesn't seem to be true if the project uses
queries that are not supported.

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.