Doctrine\OrientDB\Graph\Algorithm\Dijkstra::solve PHP Метод

solve() публичный Метод

public solve ( )
    public function solve()
    {
        if (!$this->getStartingVertex() || !$this->getEndingVertex()) {
            throw new LogicException("Cannot solve the algorithm without both starting and ending vertices");
        }
        $this->calculatePotentials($this->getStartingVertex());
        $this->solution = $this->getShortestPath();
        return $this->solution;
    }

Usage Example

Пример #1
0
 /**
  * @see http://it.wikipedia.org/wiki/File:Ricerca_operativa_percorso_minimo_09.gif
  */
 public function testWikipediaExample()
 {
     $graph = new Graph();
     $home = new Vertex('home');
     $a = new Vertex('a');
     $b = new Vertex('b');
     $c = new Vertex('c');
     $d = new Vertex('d');
     $e = new Vertex('e');
     $office = new Vertex('office');
     $graph->add($home);
     $graph->add($a);
     $graph->add($b);
     $graph->add($c);
     $graph->add($d);
     $graph->add($e);
     $graph->add($office);
     $home->connect($a, 2);
     $home->connect($d, 8);
     $a->connect($b, 6);
     $a->connect($c, 2);
     $b->connect($office, 5);
     $c->connect($d, 2);
     $c->connect($e, 9);
     $d->connect($e, 3);
     $e->connect($office);
     $algorithm = new Dijkstra($graph);
     $algorithm->setStartingVertex($home);
     $algorithm->setEndingVertex($office);
     $this->assertEquals(array($home, $a, $c, $d, $e, $office), $algorithm->solve());
 }