phpalgorithms / dijkstra
Implementation of Dijkstra's algorithm.
Installs: 189
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/phpalgorithms/dijkstra
Requires
- php: >=5.5.0
- phpalgorithms/graphtools: ~2@stable
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2025-09-25 05:35:23 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