Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titsuki/raku-algorithm-kruskal
Algorithm::Kruskal is a perl6 implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length
https://github.com/titsuki/raku-algorithm-kruskal
Last synced: about 2 months ago
JSON representation
Algorithm::Kruskal is a perl6 implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length
- Host: GitHub
- URL: https://github.com/titsuki/raku-algorithm-kruskal
- Owner: titsuki
- License: artistic-2.0
- Created: 2016-03-22T14:41:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-08T13:12:07.000Z (5 months ago)
- Last Synced: 2024-10-11T20:54:38.607Z (3 months ago)
- Language: Raku
- Size: 16.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
[![Actions Status](https://github.com/titsuki/raku-Algorithm-Kruskal/actions/workflows/test.yml/badge.svg)](https://github.com/titsuki/raku-Algorithm-Kruskal/actions)
NAME
====Algorithm::Kruskal - a Raku implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length
SYNOPSIS
========use Algorithm::Kruskal;
my $kruskal = Algorithm::Kruskal.new(vertex-size => 4);
$kruskal.add-edge(0, 1, 2);
$kruskal.add-edge(1, 2, 1);
$kruskal.add-edge(2, 3, 1);
$kruskal.add-edge(3, 0, 1);
$kruskal.add-edge(0, 2, 3);
$kruskal.add-edge(1, 3, 5);my %forest = $kruskal.compute-minimal-spanning-tree();
%forest.say; # 3
%forest.say; # [[1 2] [2 3] [3 0]]DESCRIPTION
===========Algorithm::Kruskal is a Raku implementation of Kruskal's Algorithm for constructing a spanning subtree of minimum length
CONSTRUCTOR
-----------my $kruskal = Algorithm::Kruskal.new(%options);
### OPTIONS
* `vertex-size => $vertex-size`
Sets vertex size. The vertices are numbered from `0` to `$vertex-size - 1`.
METHODS
-------### add-edge(Int $from, Int $to, Real $weight)
$kruskal.add-edge($from, $to, $weight);
Adds a edge to the graph. `$weight` is the weight between vertex `$from` and vertex `$to`.
### compute-minimal-spanning-tree() returns List
my %forest = $kruskal.compute-minimal-spanning-tree();
%forest.say; # display edges
%forest.say; # display weightComputes and returns a minimal spanning tree and its weight.
AUTHOR
======titsuki
COPYRIGHT AND LICENSE
=====================Copyright 2016 titsuki
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
This algorithm is from Kruskal, Joseph B. "On the shortest spanning subtree of a graph and the traveling salesman problem." Proceedings of the American Mathematical society 7.1 (1956): 48-50.