graphops
Graph operators and centralities as a small Rust crate. Bring your own graph via the Graph/GraphRef traits, or use the built-in AdjacencyMatrix adapter.
[]
= "0.1.0"
PageRank
use ;
use AdjacencyMatrix;
// Adjacency matrix: edge weights (0.0 = no edge)
let adj = vec!;
let scores = pagerank;
assert_eq!;
Weighted PageRank and convergence diagnostics are available via pagerank_weighted and pagerank_run.
Personalized PageRank (PPR)
Seed-biased ranking from a set of source nodes:
use ;
use AdjacencyMatrix;
let adj = vec!;
// Personalization vector: bias toward node 0
let pv = vec!;
let scores = personalized_pagerank;
Random walks
Uniform and biased (node2vec-style) random walks, with optional parallelism:
use ;
use AdjacencyMatrix;
let adj = vec!;
let config = WalkConfig ;
let walks = generate_walks;
// walks: Vec<Vec<usize>> -- each walk is a sequence of node indices
For node2vec-style biased walks (with return parameter p and in-out parameter q), use generate_biased_walks. Parallel variants (_parallel suffix) are available with the parallel feature.
Reachability
Count how many nodes each node can reach (forward) and be reached from (backward):
use reachability_counts_edges;
let edges = vec!;
let = reachability_counts_edges;
// forward[0] = 2 (node 0 reaches nodes 1 and 2)
Partitioning
Connected components and label propagation community detection:
use ;
use AdjacencyMatrix;
let adj = vec!;
let components = connected_components;
// components: [0, 0, 1] -- two components
let communities = label_propagation;
Betweenness centrality
Requires the petgraph feature:
use betweenness_centrality;
use *;
let mut g: = new;
let a = g.add_node;
let b = g.add_node;
let c = g.add_node;
g.add_edge;
g.add_edge;
let scores = betweenness_centrality;
// scores[1] is highest (node b is on the only a->c path)
Examples
pagerank.rs -- PageRank on a 4-node directed graph with labeled output. Demonstrates the adapter pattern: define an adjacency matrix, pass it to pagerank, and inspect ranked scores. Shows how link structure determines authority (node C, the most linked-to, ranks highest).
Feature flags
| Feature | What it adds |
|---|---|
petgraph |
petgraph adapters + betweenness centrality |
parallel |
Parallel walk generation (via rayon) |
serde |
Serialize/deserialize for graph adapters |
License
MIT OR Apache-2.0