/** * This is the standard DeltaBlue benchmark. A long chain of equality * constraints is constructed with a stay constraint on one end. An * edit constraint is then added to the opposite end and the time is * measured for adding and removing this constraint, and extracting * and executing a constraint satisfaction plan. There are two cases. * In case 1, the added constraint is stronger than the stay * constraint and values must propagate down the entire length of the * chain. In case 2, the added constraint is weaker than the stay * constraint so it cannot be accomodated. The cost in this case is, * of course, very low. Typical situations lie somewhere between these * two extremes. */ function chainTest($n) { global $planner; $planner = new Planner(); $prev = null; $first = null; $last = null; // Build chain of n equality constraints for ($i = 0; $i <= $n; $i++) { $name = "v{$i}"; $v = new Variable($name); if ($prev != null) { new EqualityConstraint($prev, $v, Strength::Required()); } if ($i == 0) { $first = $v; } if ($i == $n) { $last = $v; } $prev = $v; } new StayConstraint($last, Strength::StrongDefault()); $edit = new EditConstraint($first, Strength::Preferred()); $edits = new OrderedCollection(); $edits->add($edit); $plan = $planner->extractPlanFromConstraints($edits); for ($i = 0; $i < 100; $i++) { $first->value = $i; $plan->execute(); if ($last->value != $i) { alert("Chain test failed."); } } }