/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $election = new Election();
     $candidates = [1 => new Candidate('Bjørnar Moxnes'), 2 => new Candidate('Kari Elisabeth Kaski'), 3 => new Candidate('Lan Marie Nguyen Berg'), 4 => new Candidate('Abid Raja'), 5 => new Candidate('Per Sandberg')];
     foreach ($candidates as $candidate) {
         $election->addCandidate($candidate);
     }
     $votes = [[$candidates[1], $candidates[3], $candidates[2]], [$candidates[1], $candidates[3], $candidates[4]], [$candidates[1], $candidates[2], $candidates[4]], [$candidates[1], $candidates[2]], [$candidates[1], $candidates[2], $candidates[4]], [$candidates[5]], [$candidates[1], $candidates[2], $candidates[5]], [$candidates[1], $candidates[5]], [$candidates[1]], [$candidates[1]], [$candidates[2], $candidates[1], $candidates[3], $candidates[4]], [$candidates[2], $candidates[3], $candidates[4], $candidates[1], $candidates[5]], [$candidates[5], $candidates[4], $candidates[3]]];
     foreach ($votes as $vote) {
         $election->addVote($vote);
     }
     $result = $election->getResult('RankedPairs');
     Condorcet::format($result);
 }
Exemple #2
0
 protected function condorcetBasicSubstitution($substitution) : string
 {
     if ($substitution) {
         if ($substitution === true) {
             $substitution = Condorcet::getDefaultMethod();
         }
         if (Condorcet::isAuthMethod($substitution)) {
             $algo = $substitution;
         } else {
             throw new CondorcetException(9, $substitution);
         }
     } else {
         $algo = Condorcet::CONDORCET_BASIC_CLASS;
     }
     return $algo;
 }
use Condorcet\CondorcetException;
use Condorcet\Election;
use Condorcet\Result;
// Registering native Condorcet Methods implementation
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\Copeland');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\KemenyYoung');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\MinimaxWinning');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\MinimaxMargin');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\MinimaxOpposition');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\RankedPairs');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\SchulzeWinning');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\SchulzeMargin');
Condorcet::addMethod(__NAMESPACE__ . '\\Algo\\Methods\\SchulzeRatio');
// Set the default Condorcet Class algorithm
Condorcet::setDefaultMethod('Schulze');
abstract class Condorcet
{
    /////////// CONSTANTS ///////////
    const VERSION = '1.1.0';
    const ENV = 'STABLE';
    const CONDORCET_BASIC_CLASS = 'Condorcet\\Algo\\Methods\\CondorcetBasic';
    protected static $_defaultMethod = null;
    protected static $_authMethods = [self::CONDORCET_BASIC_CLASS => ['CondorcetBasic']];
    /////////// STATICS METHODS ///////////
    // Return library version numer
    public static function getVersion(string $options = 'FULL') : string
    {
        switch ($options) {
            case 'MAJOR':
                $version = explode('.', self::VERSION);
 <br><br><hr>
 
<h2>Debug Data :</h2>

 <h4>Defaut method (not used explicitly before) :</h4>

 <pre>
<?php 
Condorcet::format(Condorcet::getDefaultMethod());
?>
 </pre>


 <h4>About object :</h4>

 <pre>
<?php 
Condorcet::format($election->getConfig());
?>
 </pre>

<!-- <h4>Condorcet::format (for debug only) :</h4>

 <pre>
<?php 
// Condorcet::format($election);
?>
 </pre> -->

 </body>
 </html> 
Exemple #5
0
 public function getLoser()
 {
     Condorcet::format($this[count($this)], false, false);
 }