コード例 #1
0
 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
ファイル: Pdp.php プロジェクト: absent1706/php-combinatorics
 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;
 }