| Crates.io | graphalgs |
| lib.rs | graphalgs |
| version | 0.2.0 |
| created_at | 2021-01-23 11:49:12.524925+00 |
| updated_at | 2024-11-25 14:51:59.022485+00 |
| description | Graph algorithms based on the Rust 'petgraph' library. |
| homepage | https://github.com/starovoid/graphalgs |
| repository | https://github.com/starovoid/graphalgs |
| max_upload_size | |
| id | 345608 |
| size | 188,815 |
Graph algorithms based on the Rust "petgraph" library.
Petgraph is a great tool for working with graphs in Rust, but not all algorithms make sense to put there, so the graphalgs library will be a repository for a variety of algorithms implemented on the basis of petgraph.
Basic graph characteristics based on the concept of distance between vertices.
Generating various graphs.
Algorithms that simplify work with such type of graphs as a tournament.
As a library
use graphalgs::shortest_path::floyd_warshall;
use graphalgs::metrics::{ weighted_radius, weighted_diameter };
use petgraph::Graph;
let inf = f32::INFINITY;
// Create a graph with `f32` edge weights.
let graph = Graph::<(), f32>::from_edges(&[
(0, 1, 2.0), (1, 2, 10.0), (1, 3, -5.0),
(3, 2, 2.0), (2, 3, 20.0),
]);
// Calculate the distance matrix using the Floyd-Warshall algorithm.
assert_eq!(
floyd_warshall(&graph, |edge| *edge.weight()),
Ok(vec![vec![0.0, 2.0, -1.0, -3.0],
vec![inf, 0.0, -3.0, -5.0],
vec![inf, inf, 0.0, 20.0],
vec![inf, inf, 2.0, 0.0]])
);
// Calculate the radius and diameter of this graph,
// taking into account the weights of the edges.
assert_eq!(weighted_radius(&graph, |edge| *edge.weight()), Some(2.0));
assert_eq!(weighted_diameter(&graph, |edge| *edge.weight()), Some(inf));
If you have any comments or suggestions, or you suddenly found an error, please start a new issue or pool request.