function findCondorcet($filepath)
{
    $ballots = json_decode(file_get_contents($filepath), 1);
    $cands = getCandidates($ballots);
    $cprobs = runBallots($cands, $ballots);
    arsort($cprobs);
    return $cprobs;
}
Ejemplo n.º 2
0
function runElections()
{
    $years = array();
    $condorcets = array();
    foreach (new DirectoryIterator('elections') as $fileInfo) {
        if ($fileInfo->isDot()) {
            continue;
        } else {
            $filepath = 'elections/' . $fileInfo->getFilename();
            $cands = getCandidates($filepath);
            $data = json_decode(file_get_contents($filepath), 1);
            $year = $data['ELECTION']['id'];
            print $year . "\n";
            $ballots = $data['BALLOTS'];
            $cprobs = runBallots($year, $cands, $ballots);
            $years[$year] = $cprobs;
        }
    }
    return $years;
}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$PRINT = 0;
$start = microtime(1);
$iters = 100000;
foreach (range(0, $iters) as $j) {
    $ballot_set_name = 'ballot_' . sprintf("%07d", $j);
    $dir = substr($ballot_set_name, -3);
    $filepath = 'sim_ballots_uneven/' . $dir . '/' . $ballot_set_name . '.json';
    //findCondorcet($filepath);
    //checkIsFile($filepath);
    print "working on {$filepath}\n";
    $cands = getCandidates($filepath);
    $ballots = json_decode(file_get_contents($filepath), 1);
    $cprobs = runBallots($cands, $ballots);
    arsort($cprobs);
    print json_encode($cprobs);
    exit;
    //$years[$year]  = $cprobs;
    $now = microtime(1);
    $num_done = $j + 1;
    $per_iter = ($now - $start) / $num_done;
    $left_to_do = $iters - $num_done;
    $time_remaining = round($per_iter * $left_to_do / 60);
    if (0 == $j % 2) {
        print $j . " iterations completed ";
        print $time_remaining . " minutes to go\n";
    }
    //temp
    if ($j == 5) {