My implementation of famous the algorithm for finding the shortest paths in a graph. Discovered by Edsger Dijkstra.
Use in your console
composer require phpalgorithms/dijkstra
$dijkstra = new \PHPAlgorithms\Dijkstra(function (\PHPAlgorithms\Dijkstra\Creator $creator) {
$creator->addPoint('start');
$creator->addPoint('another one')
->addDoubleRelation($creator->getPoint(0), 10)
->addRelation($creator->addPoint(), 3);
});
[...]
print_r($dijkstra->generate(0)); // \PHPAlgorithms\Dijkstra\Path object
[...]
print_r($dijkstra->generateAll()); // array of \PHPAlgorithms\Dijkstra\Path objects
[...]
print_r($pathObj->distance); // how is the path long
print_r($pathObj->nodes); // all points in this path