mgrechanik/kruskal
最新稳定版本:1.0.0
Composer 安装命令:
composer require mgrechanik/kruskal
包简介
The implementation of the Kruskal algorithm to find a minimum spanning tree
关键字:
README 文档
README
Demo
Example of building a minimum spanning tree:

Installing
Installing through composer::
The preferred way to install this library is through composer.
Either run
composer require --prefer-dist mgrechanik/kruskal
or add
"mgrechanik/kruskal" : "~1.0.0"
to the require section of your composer.json.
How to use
Run the next code:
use mgrechanik\kruskal\Kruskal; $matrix = [ [ 0 , 263, 184, 335], [263, 0 , 287, 157], [184, 287, 0 , 259], [335, 157, 259, 0] ]; $kruskal = new Kruskal($matrix); if ($kruskal->run()) { // 1) var_dump($kruskal->getMinimumSpanningTree()); // 2) var_dump($kruskal->getDistance()); }
We will get:
- Spanning tree as an array of edges
Array
(
[0] => Array
(
[0] => 0
[1] => 2
)
[1] => Array
(
[0] => 2
[1] => 3
)
[2] => Array
(
[0] => 1
[1] => 3
)
)
- Distance of all tree
600
This code will find the next path:
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-03-14
