function runStep($stv_ballots, $stv_candidates, $committee, $config, $droop, $logs, $step_count = 0) { /* * This is the "master" function. It can be called once, and will recurse * until committee is full, outputting resulting data * */ $seats = $config['seats']; $log = array(); $log['step_count'] = $step_count + 1; //debug($log['step_count']); $ballot_tally = getBallotTally($stv_ballots); $no_votes = array(); foreach (array_keys($stv_candidates) as $eid) { if (!isset($ballot_tally[$eid])) { $no_votes[] = $eid; } } sort($no_votes); $log['no_votes'] = $no_votes; arsort($ballot_tally); $log['ballot_tally'] = $ballot_tally; $log['droop'] = $droop; $log['tie_breaks'] = array(); # exit condition if (count($committee) == $config['seats']) { return array($stv_ballots, $stv_candidates, $committee, $logs); } else { $stv_candidates = setCandidatePoints($stv_candidates, $ballot_tally, $log['step_count']); list($stv_candidates, $stv_ballots, $committee, $log) = electOrEliminateOne($stv_candidates, $stv_ballots, $committee, $config, $droop, $log); $log['committee'] = cloneArray($committee); $logs[] = $log; # recursion return runStep($stv_ballots, $stv_candidates, $committee, $config, $droop, $logs, $log['step_count']); } }
function &cloneArray(&$old) { $new = array(); $c = count($old); $k = array_keys($old); for ($i = 0; $i < $c; $i++) { if (is_array($old[$k[$i]])) { if (isset($old[$k[$i]]['name']) && $old[$k[$i]]['name'] == 'ignme') { continue; } $new[$k[$i]] = cloneArray($old[$k[$i]]); } else { $new[$k[$i]] = $old[$k[$i]]; } } return $new; }
function myClone() { $tmparr = cloneArray($this->xmlroot); //$tmparr = $this->xmlroot; $new = new NatRule(); $new->owner = $this->owner; $new->load_from_xml($tmparr); //$new->setName($new->name.'-tmpcloned'); //$new->setName('LOL'); return $new; }
/** * Multiplie par un int * @param int $monome Le nombre à multiplier * @return Polynome Le nouveau Polynome */ public function multNumber($number) { $newMonomes = cloneArray($this->monomes); for ($i = 0; $i < count($newMonomes); $i++) { $newMonomes[$i]->coeff = $newMonomes[$i]->coeff * $number; } $res = new Polynome($newMonomes); return $res; }