/** * Searches the solution space starting from the specified initial node. * * @param object ISolution $initial The root node of the solution space. */ protected function search(ISolution $solution) { if ($solution->isComplete()) { $this->updateBest($solution); } else { foreach ($solution->getSuccessors() as $successor) { $this->search($successor); } } }
/** * Searches the solution space starting from the specified initial node. * * @param object ISolution $initial The root node of the solution space. */ protected function search(ISolution $solution) { if ($solution->isComplete()) { $this->updateBest($solution); } else { foreach ($solution->getSuccessors() as $successor) { if ($successor->isFeasible() && $successor->getBound() < $this->bestObjective) { $this->search($successor); } } } }
/** * Records the specified solution as the "best" solution * if it is a feasible solution and if the value of its objective function * is less than the current "best" solution. * This method is called by the search method * for every complete solution it generates. * * @param object ISolution $solution The specified complete solution. */ public function updateBest(ISolution $solution) { if ($solution->isComplete() && $solution->isFeasible() && $solution->getObjective() < $this->bestObjective) { $this->bestSolution = $solution; $this->bestObjective = $solution->getObjective(); } }