phpalgorithms / dijkstra
Dijkstra算法的实现。
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-09-12 00:44:58 UTC
README
我对著名的图中最短路径算法的实现。由Edsger Dijkstra发现。
Composer
在您的控制台中使用
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