/** * Update the walkabout strengths and stay flags of all variables * downstream of the given constraint. Answer a collection of * unsatisfied constraints sorted in order of decreasing strength. */ function removePropagateFrom($out) { $out->determinedBy = null; $out->walkStrength = Strength::Weakest(); $out->stay = true; $unsatisfied = new OrderedCollection(); $todo = new OrderedCollection(); $todo->add($out); while ($todo->size() > 0) { $v = $todo->removeFirst(); for ($i = 0; $i < $v->constraints->size(); $i++) { $c = $v->constraints->at($i); if (!$c->isSatisfied()) { $unsatisfied->add($c); } } $determining = $v->determinedBy; for ($i = 0; $i < $v->constraints->size(); $i++) { $next = $v->constraints->at($i); if ($next != $determining && $next->isSatisfied()) { $next->recalculate(); $todo->add($next->output()); } } } return $unsatisfied; }
function recalculate() { $in = $this->input(); $out = $this->output(); $out->walkStrength = Strength::weakestOf($this->strength, $in->walkStrength); $out->stay = $in->stay && $this->scale->stay && $this->offset->stay; if ($out->stay) { $this->execute(); } // stay optimization }