algorithms / 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: 2022-02-01 12:51:48 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