protected function canLoad($pointSequence)
 {
     // $this->_checks++;
     $canLoad = App::getSingleton('\\Litvinenko\\Combinatorics\\Pdp\\Helper')->canLoad($pointSequence, $this->getPythonFile(), $this->getLoadArea(), $this->getWeightCapacity(), $this->getPoints());
     if (!$canLoad) {
         App::dispatchEvent('cant_load', ['point_sequence' => $pointSequence]);
     }
     return $canLoad;
     // return ($this->getCheckLoading()) ? App::getSingleton('\Litvinenko\Combinatorics\Pdp\Helper')->canLoad($pointSequence, $this->getCheckLoadingCommandPrefix(), $this->getLoadArea(), $this->getWeightCapacity()) : true;
 }
 protected function _generate($object)
 {
     if ($this->objectIsComplete($object)) {
         $this->_data['generatedObjects'][] = $object;
     } else {
         foreach ($this->generateNextObjects($object) as $nextObject) {
             if ($this->getLogSteps()) {
                 App::dispatchEvent("new_path_generated", ['tuple' => $nextObject]);
             }
             $this->_generate($nextObject);
         }
     }
 }
 protected function _getSuccessiveElements($tuple)
 {
     $result = [];
     // we assume that tuple contain \Litvinenko\Combinatorics\Pdp\Point objects
     $currentPath = $this->_getCurrentPath($tuple);
     foreach ($this->getGeneratingElements() as $element) {
         $point = $element['value'];
         // if current path does not contain this point
         if (!$currentPath->doesContain($point)) {
             // add pickup point if whether vehicle can take box at this point
             if ($point->isPickup() && $currentPath->getCurrentWeight() + $point->getBoxWeight() <= $this->getWeightCapacity() && $currentPath->getCurrentVolume() + $point->getBoxVolume() <= Helper::getLoadAreaVolume($this->getLoadArea()) || $point->isDelivery() && $currentPath->doesContain($point->getPairId())) {
                 $resultContainer = new \stdClass();
                 // event observers will write info to this object
                 App::dispatchEvent('point_add_before', ['point' => $point, 'point_sequence' => $tuple, 'result_container' => $resultContainer]);
                 if (!isset($resultContainer->result) || isset($resultContainer->result) && $resultContainer->result !== false) {
                     $result[] = $element;
                 }
             }
         }
     }
     return $result;
 }
 protected function canLoad($pointSequence)
 {
     $result = true;
     if ($this->getCheckLoading()) {
         $canLoad = App::getSingleton('\\Litvinenko\\Combinatorics\\Pdp\\Helper')->canLoad($pointSequence, $this->getPythonFile(), $this->getLoadArea(), $this->getWeightCapacity(), $this->getPoints());
         if (!$canLoad) {
             $this->_logEvent('cant_load', ['point_sequence' => $pointSequence]);
         }
         $result = $canLoad;
     }
     return $result;
 }
Esempio n. 5
0
 public function solveGen($data, $config)
 {
     // $pdpPointsFile  = '../pdp_points.txt';
     // $pdpConfigFile  = '../pdp_config.ini';
     $solverClass = '\\Litvinenko\\Combinatorics\\Pdp\\Solver\\PreciseGenerationSolver';
     $metricsClass = '\\Litvinenko\\Combinatorics\\Pdp\\Metrics\\EuclideanMetric';
     $evaluatorClass = '\\Litvinenko\\Combinatorics\\Pdp\\Evaluator\\PdpEvaluator';
     $generationLogFile = '';
     $solutionLogFile = 'solution.txt';
     // $pdpPoints = \Litvinenko\Combinatorics\Pdp\IO::readPointsFromFile($pdpPointsFile);
     // $pdpConfig = \Litvinenko\Combinatorics\Pdp\IO::readConfigFromIniFile($pdpConfigFile);
     // var_dump($pdpPoints);
     $solver = App::getSingleton($solverClass);
     $solver->_construct();
     $solver->addData(array_merge($config, ['depot' => self::createPointsFromArray(array(0 => $data['depot'])), 'points' => self::createPointsFromArray($data['points']), 'evaluator' => new $evaluatorClass(['metrics' => new $metricsClass()])]));
     // echo "<pre>\n";
     try {
         App::getSingleton('\\Litvinenko\\Combinatorics\\Pdp\\Helper\\Time')->start();
         $bestPath = $solver->getSolution();
         $solutionTime = App::getSingleton('\\Litvinenko\\Combinatorics\\Pdp\\Helper\\Time')->getTimeFromStart();
         // printf('Solution was obtained in %.4F seconds', $solutionTime);
         $totalGeneratedPaths = count($solver->getGeneratedPointSequences());
         // echo "\n\ntotal paths generated:" .  $totalGeneratedPaths . "\n";
         // App::getSingleton('\Litvinenko\Combinatorics\Pdp\Helper\Time')->start();
         // if ($pdpConfig['log_solution'] && $solutionLogFile)
         // {
         //     $log =  "-------------- all paths at last step:\n";
         //     foreach ($solver->getGeneratedPointSequences() as $pointSequence)
         //     {
         //         $log .= IO::getPathAsText($pointSequence) . ' ' . $solver->_getCost($pointSequence) .   "\n";
         //     }
         //     $log .= "\n\n-------------not loaded paths:\n";
         //     foreach (App::getSingleton('\SolutionInfoCollector')->getNotLoadedPaths() as $pointSequence)
         //     {
         //         $log .= IO::getPathAsText($pointSequence) . ' ' . $solver->_getCost($pointSequence) .   "\n";
         //     }
         //     file_put_contents($solutionLogFile, $log);
         // }
         $bestCost = $solver->_getCost($bestPath);
         // echo "\n\nfinal path: " . IO::getPathAsText($bestPath) . " with cost " . $bestCost . "\n";
         // printf('All other operations took %.4F seconds', App::getSingleton('\Litvinenko\Combinatorics\Pdp\Helper\Time')->getTimeFromStart());
         $result = ['path' => $bestPath->getPointsParams('display_id'), 'path_cost' => $bestCost, 'solution_time' => $solutionTime, 'info' => ['total_generated_paths' => $totalGeneratedPaths]];
     } catch (\Exception $e) {
         $result['errors'][] = "Exception occured: \n" . $e->getMessage();
     }
     // echo PHP_EOL . json_encode($result);
     return $result;
 }