<?php $PRINT = 0; $start = microtime(1); $iters = 100000; $seats = 8; 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'; print "working on {$filepath}\n"; checkIsFile($filepath); $ballots = json_decode(file_get_contents($filepath), 1); $ballots = evenBallotLength($ballots); $dir_path = '8seats_uneven/' . $dir; if (!is_dir($dir_path)) { mkdir($dir_path); } $result_path = $dir_path . '/' . $ballot_set_name . '.json'; if (is_file($result_path)) { continue; } //check out file_put_contents($result_path, '-'); $result = array(); $result['condorcet'] = findCondorcet($filepath); $result['approv'] = findApproval($ballots, $seats); $result['borda'] = findBorda($ballots, $seats); $result['stv'] = findStv($ballots, $seats); $result_json = json_encode($result); file_put_contents($result_path, $result_json);
seats -- integer indicating the size of the committee to be elected initial_ballot_value */ $result = array(); foreach (new DirectoryIterator('elections') as $fileInfo) { if ($fileInfo->isDot()) { continue; } else { $fn = 'elections/' . $fileInfo->getFilename(); $elec_data = json_decode(file_get_contents($fn), 1); $seats = $elec_data['ELECTION']['seats']; $year = $elec_data['ELECTION']['id']; if ('2011' != $year) { continue; } $ballots = evenBallotLength($elec_data['BALLOTS']); $candidates = getCandidates($ballots); $num_ballots = count($ballots); $droop = calculateDroop($num_ballots, $seats); $committee = array(); foreach (range(1, 100) as $num) { if (0 == $num % 100) { print $year . " : " . $num . " memory " . memory_get_usage() . "\n"; } $logs = tallyBallots($ballots, $candidates, $seats, $droop); $last_log = array_pop($logs); foreach ($last_log['committee'] as $elected) { if (!isset($committee[$elected->eid])) { $committee[$elected->eid] = 0; } $committee[$elected->eid] += 1;