コード例 #1
0
function findStv($ballots, $seats)
{
    $candidates = getCandidates($ballots);
    $num_ballots = count($ballots);
    $droop = calculateDroop($num_ballots, $seats);
    $committee = array();
    foreach (range(1, 100) as $num) {
        $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;
        }
    }
    return $committee;
}
コード例 #2
0
        $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;
            }
        }
        $result[$year] = $committee;
    }
}
print json_encode($result);
function debug($str)
{
    print "\n\nDEBUG: {$str}\n\n";