-
-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Labels
Description
I have code like this:
$graph = new \Fhaculty\Graph\Graph();
$v1 = $graph->createVertex(1);
$v2 = $graph->createVertex(2);
$v5 = $graph->createVertex(5);
$v6 = $graph->createVertex(6);
$v1->createEdge($v2)->setWeight(4);
$v2->createEdge($v5)->setWeight(4);
$v5->createEdge($v6)->setWeight(4);
$alg = new \Fhaculty\Graph\Algorithm\ShortestPath\Dijkstra($v1);
echo $graph;
var_dump($alg->getDistance($v6));it has output as excepted:
graph G {
1 -- 2 [label=4]
2 -- 5 [label=4]
5 -- 6 [label=4]
}
int(12)
but if I change sequence of creating vertices
$v1 = $graph->createVertex(1);
$v2 = $graph->createVertex(2);
$v6 = $graph->createVertex(6); // this vertex was created as last
$v5 = $graph->createVertex(5);
// other code is the sameI get this output:
graph G {
1 -- 2 [label=4]
2 -- 5 [label=4]
5 -- 6 [label=4]
}
And distance isn't count because maximum execution time exceeded.
Graph is the same in both cases, so result has to be same too.
Reactions are currently unavailable