?> </li> <?php } echo '</ol><br></div>'; } ?> <hr style="clear:both;"> <h2>Winner by <a target="blank" href="http://en.wikipedia.org/wiki/Condorcet_method">natural Condorcet</a> :</h2> <strong style="color:green;"> <?php if (!is_null($election->getWinner())) { echo $election->getWinner(); } else { echo '<span style="color:red;">The votes of this group do not allow natural Condorcet winner because of <a href="http://fr.wikipedia.org/wiki/Paradoxe_de_Condorcet" target="_blank">Condorcet paradox</a>.</span>'; } ?> <br> <em style="color:green;">computed in <?php echo $election->getLastTimer(); ?> second(s).</em> </strong> <h2>Loser by <a target="blank" href="http://en.wikipedia.org/wiki/Condorcet_method">natural Condorcet</a> :</h2> <strong style="color:green;"> <?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(); */