11 releases
0.2.1 | Mar 14, 2022 |
---|---|
0.2.0 | Mar 2, 2022 |
0.1.8 | Dec 30, 2021 |
0.1.4 | Nov 25, 2021 |
0.1.0 | Oct 30, 2021 |
#11 in #graph-theory
34 downloads per month
315KB
5.5K
SLoC
GRATHE
A Rust implementation of a GRAph THEory library.
Description
Grathe is a graph theory library that provides a coherent programming experience. Its main goal is to reduce the effort of translating theoretical aspect into practical computation.
How to Usage
Here is a brief example:
use anyhow::Result; // Catch any error.
use grathe::prelude::*; // Frequently used items.
fn main() -> Result<()> {
// Define an (undirected) graph given its edges.
let G = Graph::from_edges([
(0, 1), (1, 2), (3, 4)
]);
// Iterate over the vertex set.
for &x in V!(G) {
assert!(G.has_vertex(&x));
}
// Iterate over the neighbors of `1`.
for x in Ne!(G, &1) {
assert!(G.has_edge(x, &1)?);
}
// Define a graph with labels, equivalent to Graph::<String>.
let mut G = Graphl::null();
// Add a vertex to the graph.
let x = G.add_vertex("A")?;
assert!(G.has_vertex(&x));
// Handle errors in a Rust-compatible way.
assert!(
match G.add_vertex(x) {
Err(_) => true, // Error! Vertex already defined!
Ok(_) => false, // Ok! Vertex added successfully!
}
);
// Exit with no error.
Ok(())
}
How to Install
Include grathe
into Cargo.toml
as dependency.
How to Test
The openblas
library is needed. Clone the repository and run the following commands inside of it.
Linux
sudo apt-get install libopenblas-dev
MacOS
brew install openblas
Windows
cargo install cargo-vcpkg
cargo vcpkg -v build
cp target/vcpkg/installed/x64-windows/lib/libopenblas.lib target/vcpkg/installed/x64-windows/lib/openblas.lib
Finally run the tests as usual:
cargo test
References
This repository is based on the following literature:
License
Grathe is dual-licensed under the APACHE LICENSE Version 2 or the MIT LICENSE to be compatible with the Rust project.
Dependencies
~68MB
~1M SLoC