phpalgorithms / dijkstra
Implementation of Dijkstra's algorithm.
v3.0.1-alpha.1
2016-06-09 09:54 UTC
Requires
- php: >=5.5.0
- phpalgorithms/graphtools: ~2@stable
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-12-19 01:51:02 UTC
README
My implementation of famous the algorithm for finding the shortest paths in a graph. Discovered by Edsger Dijkstra.
Composer
Use in your console
composer require phpalgorithms/dijkstra
How to use
Create connections between points
$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); });
Generate paths from first point
[...] print_r($dijkstra->generate(0)); // \PHPAlgorithms\Dijkstra\Path object
Generate paths for all points
[...] print_r($dijkstra->generateAll()); // array of \PHPAlgorithms\Dijkstra\Path objects
Path object important parameters
[...] print_r($pathObj->distance); // how is the path long print_r($pathObj->nodes); // all points in this path