julien-boudry / condorcet
Complete election manager, providing natively many voting methods including: Condorcet / Borda (+ Nauru variant) / Copeland / Dodgson (2 Approximations) / FTPT / Instant-runoff (alternative vote) / Kemeny–Young / Minimax (+ variants) / Ranked Pairs (+ variants) / Schulze (+ variants), Single Transfe
Fund package maintenance!
julien-boudry
Bitcoin
Installs: 8 473
Dependents: 2
Suggesters: 0
Security: 0
Stars: 123
Watchers: 12
Forks: 12
Open Issues: 9
Requires
- php: ^8.4
- ext-json: *
- ext-mbstring: *
- brick/math: ^0.13
- symfony/console: ^7.1
- symfony/yaml: ^7.2
Requires (Dev)
- ext-pdo: *
- ext-pdo_sqlite: *
- haydenpierce/class-finder: >= 0.5.3
- laravel/pint: ^1.21
- laravel/prompts: ^0.3.5
- nikic/php-parser: ^5.4
- pestphp/pest: ^3.7
- phpbench/phpbench: ^1.4
- phpstan/phpdoc-parser: ^2.1
- phpstan/phpstan: ^2.1
- rector/rector: ^2.0
Suggests
- ext-pdo: Allow to use database for very large elections.
- ext-pdo_sqlite: Use sqlite3 bases for very large elections.
- dev-master
- v5.0.0
- v5.0-rc2
- v5.0-rc1
- v4.7.1
- v4.7.0
- v4.6.1
- v4.6.0
- v4.5.1
- v4.5.0
- v4.5-rc3
- v4.5-rc1
- v4.4.1
- v4.4.0
- v4.3.1
- v4.3.0
- v4.3-rc2
- v4.3-rc1
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.2-rc3
- v4.2-rc2
- v4.2-rc1
- v4.1.1
- v4.1.0
- v4.0.0
- v4.0-beta1
- v4.0-alpha1
- v3.4-alpha1
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.3-rc1
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.2-rc2
- v3.2-rc1
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.1-rc1
- v3.1-beta2
- v3.1-beta1
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.1-beta3
- v2.1-beta2
- v2.1-beta1
- v2.1-alpha7
- v2.0.1
- v2.0.0
- v2.0.0-RC3
- v2.0.0-RC2
- v2.0.0-RC1
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.97.0
- v0.96.0
- v0.95.1
- v0.95.0
- v0.94.0
- v0.94-rc2
- v0.94-rc1
- v0.93.0
- v0.92.0
- v0.91.1
- v0.91.0
- v0.91-rc2
- v0.91-rc1
- v0.90.0
- v0.90-rc5
- v0.90-rc4
- v0.90-rc3
- v0.90-rc2
- v0.90-rc1
- v0.90-beta11
- v0.90-beta10
- v0.90-beta9
- v0.90-beta8
- v0.90-beta7
- v0.90-beta6
- v0.90-beta5
- v0.15-beta4
- v0.15-beta3
- v0.15-beta2
- v0.15-beta1
- v0.14.0
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.6-beta1
- v0.5.1
- v0.5.0
- v0.5-beta1
- dev-Version/5.0
- dev-dev-5.0
- dev-Archive/WoollyMDriver
- dev-dev-4.7
- dev-Version/4.7
- dev-WORK/SmithSet
- dev-WORK/StatsInterface
- dev-Dev/migrationToPhpDoc
- dev-WORK/pestMigration
- dev-dev-4.6
- dev-dev-4.5
- dev-Experimental/Pest
- dev-Experimental/Schulze-STV
- dev-VERSION/4.5
- dev-Experimental/FilteredPairwise
- dev-Experimental/SchulzeSTVtests
- dev-schulze
- dev-Schulze-STV
- dev-WORK/FilteredPairwisePoc
- dev-WORK/poc_free_pairwise
- dev-dev-4.4
- dev-WORK/GeckoMethod
- dev-VERSION/4.4
- dev-WORK/CivsFormat
- dev-VERSION/4.3
- dev-dev-4.3
- dev-VERSION/4.2
- dev-dev-4.2
- dev-WORK/generics
- dev-julien-boudry-patch-2
- dev-julien-boudry-patch-1
- dev-Archive/special-boudry
- dev-dev-phpdoc
- dev-dev-production-codespace
- dev-WORK/issue_110
- dev-WORK/VoteParser
- dev-dev-4.1
- dev-VERSION/4.1
- dev-Experimental/Sainte-Laguë
- dev-dev-4.0
- dev-VERSION/4.0
- dev-dev-3.2
- dev-dev-3.3
- dev-dev-3.4
- dev-Experimental/KemenyYoungWithoutStats
- dev-Experimental/BigInt
- dev-WORK/KemenyYoungLight1
- dev-WORK/CPO_STV
- dev-VERSION/3.3
- dev-VERSION/2.2
- dev-dev-2.2
- dev-WORK/weakReference
- dev-WORK/TidemanDataCollection
- dev-dependabot/composer/infection/infection-tw-0.25.3or-tw-0.26.0
- dev-VERSION/3.2
- dev-VERSION/3.1
- dev-dev-3.1
- dev-WORK/infection
- dev-WORK/newExceptions
- dev-WORK/php_81
- dev-WORK/STV
- dev-dev-3.0
- dev-VERSION/3.0
- dev-WORK/moveDocumentationToAttributes
- dev-WORK/FasterKemenyYoung
- dev-version/2.1
- dev-VERSION/2.0
- dev-dev-2.0
- dev-WORK/ElectionStateCacheHandler
- dev-Version/1.8
- dev-WORK/ranking_poc
- dev-dev-1.8.x
- dev-Version/1.7
- dev-Version/1.6
- dev-TEST/ScrutinizerPHPAnalysisEngineV2
- dev-Version/1.5
- dev-Version/1.4
- dev-Version/1.3
- dev-Version/1.0
- dev-Version/0.90
- dev-VERSION/0.14
- dev-Version/0.13
This package is auto-updated.
Last update: 2025-05-07 09:50:41 UTC
README
Main Author: Julien Boudry
License: MIT - Please say hello if you like or use this code!
Contribute: Contribution File
Donation: ₿ bc1q3jllk3qd9fjvvuqy07tawkv7t6h7qjf55fc2gh or GitHub Sponsor Page
You can also offer me a bottle of good wine.
Condorcet PHP
Presentation | Documentation Book | API Reference | Voting Methods | Tests
Condorcet is a powerful engine for managing electoral processes and calculating election results. It handles all aspects from configuration and vote collection to result calculation. The library natively implements over 20 voting methods compatible with preferential voting ballots, including Condorcet methods, Alternative Voting, STV, and many others. => See all supported voting methods
Two ways to use Condorcet:
- Command Line Application: For quick access to essential features without technical expertise. Easily compute election results and statistics.
- PHP Library: Integrate into your code to access all advanced features (custom manipulations, extensions, performance optimizations, advanced I/O methods, etc.).
Both approaches can handle massive numbers of votes (hundreds of millions) on modest hardware.
Summary
- Condorcet PHP
Project State and Specifications
Version | PHP Requirements | State | Support |
---|---|---|---|
5.0 | 8.4 | Stable | ✔ support provided |
4.7 | 8.3 | Old Stable | ✔ support provided |
4.6 | 8.2 | Old Stable | ❌ not any support |
3.x | 8.1 | Old Stable | ❌ not any support |
2.2 | 7.4 | Old Stable | ❌ support requiring some incentive |
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 for elections with hundreds of thousands of votes or more.
Supported Voting Methods
Condorcet supports both "single-winner" methods (with full ranking extrapolation) and proportional representation systems.
Full details on voting methods, options, and implementation choices
Single-Winner Methods provided natively
Single-winner methods return a complete ranking of all candidates.
Deterministic
Condorcet / Borda (+ Nauru variant) / Copeland / Dodgson (2 Approximations) / FPTP / Instant-runoff (alternative vote) / Kemeny–Young / Minimax (+ variants) / Ranked Pairs (+ variants) / Schulze (+ variants)
Lotteries
Random Ballot / Random Candidates
Proportional Methods provided natively
Methods designed for electing multiple candidates to an assembly.
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 features a modular architecture allowing easy extension with new algorithms:
Main Features
-
Complete Election Management
- Handle the full election cycle: candidate registration, vote collection, result calculation
- Support for vote ordering, tagging, deletion, and result simulation
- Multiple input formats (string, JSON, objects)
- Import/export support for Condorcet Election Format, Debian Format, David Hill Format
- Integrity verification through checksumming
- Serialization and data export for storage
- User-friendly features (vote validation, anti-spam, human-readable results)
-
Comprehensive Results and Statistics
- Identify Condorcet Winners, Losers, and Paradoxes
- Generate complete rankings using various voting methods
- Detailed statistical analysis of results
- Support for both complete and partial ballot rankings
- Vote weighting capabilities
-
Advanced Capabilities
- Object-oriented design for flexibility and extendability
- Dynamic candidate and vote management across multiple elections (simulate election easily)
- External storage drivers for handling massive elections
- Intelligent caching system (performance optimization)
- Vote constraints
-
Extensibility and Configuration
- Extend functionality without modifying core code
- Create custom vote methods, constraints, and storage drivers
- Extensive configuration options
Although not primarily designed for maximum performance, Condorcet delivers predictable, linear scaling even with very large elections. While not formally certified, comprehensive test coverage ensures reliable results.
Use Condorcet as a command line application
Install as a command line application
Available installation methods:
- Native installation from source with Composer
- Standalone PHAR executable file
- Docker image (build or pull)
Condorcet Book - Command Line
Use Condorcet as a PHP Library
Install / Autoloading
Uses namespace \CondorcetPHP\Condorcet
Installation options:
- Composer (recommended) or any native PSR-4 compatible autoloader
- Native autoloader (included)
Library Manual
The documentation includes comprehensive examples illustrating the library's capabilities.
Class & API References
PHP Library - Examples
Overview Examples:
- General Overview (tour of main features)
- Advanced Object Management
HTML Output Examples:
Specific Examples:
- Documentation Book contains numerous code examples
- Managing millions of votes with external database drivers
Performance & Coding Style Considerations
Coding Standards:
The codebase follows PSR-12 with some flexibility, enforced via CS-Fixer throughLaravel Pint.
Performance:
- Typical Use Case: Complex scenario with all voting methods, 6 candidates, 2 seats, 1,000 votes
- Memory usage: under 3MB
- Execution time (with JIT): under 160ms
- Execution time (without JIT): under 250ms
Performance varies significantly between voting methods. See method benchmarks.
Kemeny-Young Performance:
- 7 candidates: ~5MB memory, 10ms
- 8 candidates: ~6MB memory, 10ms
- 9 candidates: ~7MB memory, 1.1s
- 10 candidates: ~7MB memory, 14s
- 11 candidates: ~8MB memory, 193s
Large Elections: For elections with 50,000+ votes, consider external storage to avoid memory constraints. Condorcet includes a PDO driver that works with standard relational databases to handle hundreds of millions of votes. A simple SQLite implementation is provided.
Custom storage drivers can be implemented for NoSQL or other storage systems.
See the documentation on handling large elections
Benchmarks run on a modern Linux x64 system with PHP 8.1 (CLI).
Roadmap for Further Releases
- Future developments to be announced