/**
  * 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);
 }
 second(s).</em>	</strong>
	</strong>

<br><br><hr>

<?php 
foreach (Condorcet::getAuthMethods() as $method) {
    ?>

		<h2>Ranking by <?php 
    echo $method;
    ?>
:</h2>

		<?php 
    $result = $election->getResult($method);
    $lastTimer = $election->getLastTimer();
    if ($method === 'Kemeny–Young' && !empty($result->getWarning(\Condorcet\Algo\Methods\KemenyYoung::CONFLICT_WARNING_CODE))) {
        $kemeny_conflicts = explode(';', $result->getWarning(\Condorcet\Algo\Methods\KemenyYoung::CONFLICT_WARNING_CODE)[0]['msg']);
        echo '<strong style="color:red;">Arbitrary results: Kemeny-Young has ' . $kemeny_conflicts[0] . ' possible solutions at score ' . $kemeny_conflicts[1] . '</strong>';
    }
    ?>

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

		<em style="color:green;">computed in <?php 
    echo $lastTimer;
	</strong>

<br><br><hr>

<h2>Some pratices about default method :</h2>

	<h3>Use default method :</h3>
	
	<strong>Defaut:</strong> <?php 
echo Condorcet::getDefaultMethod();
?>
 <br>

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

	<h3>Change it to MiniMax_Margin :</h3>
	<?php 
Condorcet::setDefaultMethod('Minimax_Margin');
?>

	<strong>Defaut:</strong> <?php 
echo Condorcet::getDefaultMethod();
?>
 <br>

	 <pre>
	<?php 
$myElection = new Election();
$myElection->addCandidate(new Candidate('A'));
$myElection->addCandidate(new Candidate('B'));
$myElection->addCandidate(new Candidate('C'));
$myElection->addCandidate(new Candidate('D'));
$myElection->addCandidate(new Candidate('E'));
$myElection->addCandidate(new Candidate('F'));
// II - Setup external drivers
/* We will use PDO SQLITE, but can be MySQL or else */
unlink(__DIR__ . '/bdd.sqlite');
$pdo_object = new \PDO('sqlite:' . __DIR__ . '/bdd.sqlite');
$database_map = ['tableName' => 'Entitys', 'primaryColumnName' => 'id', 'dataColumnName' => 'data'];
$driver = new PdoHandlerDriver($pdo_object, true, $database_map);
// true = Try to create table
$myElection->setExternalDataHandler($driver);
// III - Add hundred of thousands votes
set_time_limit(60 * 5);
$howMany = 100000;
$voteModel = $myElection->getCandidatesList();
for ($i = 0; $i < $howMany; $i++) {
    shuffle($voteModel);
    $myElection->addVote($voteModel);
}
// IV - Get somes results
$myElection->getWinner();
$myElection->getResult('Schulze');
print 'Success!  
Process in: ' . round(microtime(true) - $start_time, 2) . "s\n";
echo ' Peak of memory allocated : ' . round(memory_get_peak_usage() / pow(1024, $i = floor(log(memory_get_peak_usage(), 1024))), 2) . ' ' . ['b', 'kb', 'mb', 'gb', 'tb', 'pb'][$i] . '<br>';
// Close external driver and and retrieve data into classical internal RAM memory.
/* $myElection->closeHandler(); */