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.
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.
- Condorcet PHP
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.
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 return a complete ranking of all candidates.
Condorcet / Borda (+ Nauru variant) / Copeland / Dodgson (2 Approximations) / FPTP / Instant-runoff (alternative vote) / Kemeny–Young / Minimax (+ variants) / Ranked Pairs (+ variants) / Schulze (+ variants)
Random Ballot / Random Candidates
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)
Condorcet features a modular architecture allowing easy extension with new algorithms:
-
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.
Available installation methods:
- Native installation from source with Composer
- Standalone PHAR executable file
- Docker image (build or pull)
Uses namespace \CondorcetPHP\Condorcet
Installation options:
- Composer (recommended) or any native PSR-4 compatible autoloader
- Native autoloader (included)
The documentation includes comprehensive examples illustrating the library's capabilities.
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
The codebase follows PSR-12 with some flexibility, enforced via CS-Fixer throughLaravel Pint.
- 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).
- Future developments to be announced