graphrs
graphrs is a Rust package for the creation, manipulation and analysis of graphs.
It allows graphs to be created with support for:
- directed and undirected edges
- multiple edges between two nodes
- self-loops
A Graph has two generic arguments:
T: Specifies the type to use for node names.A: Specifies the type to use for node and edge attributes. Attributes are optional extra data that are associated with a node or an edge. For example, if nodes represent people andTis ani32of their employee ID then the node attributes might store their first and last names.
Documentation
The doc.rs documentation is here.
Major structs
GraphNodeEdge
Modules
algorithms::centralityalgorithms::centralityalgorithms::clusteralgorithms::communityalgorithms::componentsalgorithms::shortest_pathgeneratorsreadwrite
Examples
Create a weighted, directed graph
use ;
let nodes = vec!;
let edges = vec!;
let specs = directed;
let graph = new_from_nodes_and_edges;
Create an undirected graph from just edges
use ;
let mut graph: = new;
let result = graph.add_edges;
Create an empty graph with all possible specifications
use ;
let graph = new;
Generate graphs
use ;
let graph_complete = complete_graph;
let graph_random = fast_gnp_random_graph;
Find the shortest path between two nodes
use ;
use ;
let mut graph = new;
graph.add_edges;
let shortest_paths = single_source;
assert_eq!;
Compute the betweenness, closeness and eigenvector centrality for all nodes
use ;
let graph = karate_club_graph;
let centralities = betweenness_centrality;
let closeness = closeness_centrality;
let centralities = eigenvector_centrality;
Detect communities within a graph
use ;
let graph = karate_club_graph;
let partitions = louvain_partitions;
Read and write graphml files
use ;
let graph = read_graphml_file;
write_graphml;
Get an adjacency matrix
This is an optional feature for crate. Enable in Cargo.toml with:
graphrs = { version = "x.y.z", features = ["adjacency_matrix"] }
use generators;
let graph = karate_club_graph;
let matrix = graph.get_sparse_adjacency_matrix.unwrap;
Performance
A comparison of the performance of graphrs against NetworkX, igraph and graph-tool can be found here.
Credits
Some of the structure of the API and some of the algorithms were inspired by NetworkX.
License
MIT