bmichotte/dijkstra

PHP 7+ 版本的 Dijkstra 算法实现

1.0.2 2019-07-19 09:28 UTC

This package is auto-updated.

Last update: 2024-09-17 19:36:32 UTC


README

Build Status Quality Score Code Coverage StyleCI Github Action

关于该算法的更多信息: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

您可以在 example 目录中找到一个示例。此示例的结果应类似于 最短路径

安装

运行 composer require bmichotte/dijkstra

用法

// create some points
$point1 = new \Bmichotte\Dijkstra\Point(/* x */ 1, /* y */ 1);
$point2 = new \Bmichotte\Dijkstra\Point(2, 2);
$point3 = new \Bmichotte\Dijkstra\Point(3, 3);

$all_points = [$point1, $point2, $point3];

// "join" them
$point1->addPoint($point2);
$point1->addPoint($point3);
$point2->addPoint($point3);

// find the shortest path
$dijkstra = new \Bmichotte\Dijkstra\Dijkstra($all_points, /* from */ $point1, /* to */ $point3);
$shortest_path = $dijkstra->findShortestPath();

// $shortest_path[0] == $point1
// $shortest_path[1] == $point3