示例#1
0
文件: main.php 项目: masim05/php-spp
function main($from, $to, $connections)
{
    $graph = new Graph();
    foreach ($connections as $params) {
        $graph->addEdgeForce($params[0], $params[1], $params[2]);
    }
    $algo = new DijkstraSPPSolver($graph);
    $algo->solve($from, $to);
    print_r($algo->getSolution());
}
示例#2
0
 public function testSolutionWhenSeveralVariantsArePossible()
 {
     $graph = new Graph();
     $graph->addEdgeForce('Moscow', 'Kaluga', 10);
     $graph->addEdgeForce('Kaluga', 'Ryazan', 16);
     $graph->addEdgeForce('Moscow', 'Tula', 12);
     $graph->addEdgeForce('Tula', 'Ryazan', 14);
     $solver = new DijkstraSPPSolver($graph);
     $solver->solve('Moscow', 'Ryazan');
     $solution = $solver->getSolution();
     //print_r($solution);
     $this->assertEquals(true, $solution["success"]);
     $this->assertEquals(26, $solution["cost"]);
 }