/** * 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 extractPlanFromConstraints($constraints) { $sources = new OrderedCollection(); for ($i = 0; $i < $constraints->size(); ++$i) { $c = $constraints->at($i); if ($c->isInput() && $c->isSatisfied()) { $sources->add($c); } } return $this->makePlan($sources); }