graphina 0.3.0-alpha.2

A graph data science library for Rust
docs.rs failed to build graphina-0.3.0-alpha.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: graphina-0.3.0-alpha.4

Graphina

Tests Code Coverage CodeFactor Crates.io Docs.rs Docs License

Graphina is a graph data science library for Rust. It provides the common data structures and algorithms used for analyzing the graphs of real-world networks, such as social, transportation, and biological networks.

Compared to other Rust graph libraries like petgraph and rustworkx, Graphina aims to provide a more high-level API and a wide range of ready-to-use algorithms for network analysis and graph mining tasks. Graphina aims to be as feature-rich as NetworkX but with the speed and performance benefits of Rust.

Additionally, PyGraphina Python library allows users to use Graphina in Python. Check out pygraphina directory for more details.

See the ROADMAP.md for the list of implemented and planned features.

[!IMPORTANT] This project is in early development, so bugs and breaking changes are expected. Please use the issues page to report bugs or request features.


Structure

Graphina consists of two main parts: a core library and extensions. The core library provides the basic data structures and algorithms for working with graphs. The extensions are modules outside the core library that contain more advanced algorithms for specific tasks like community detection, link prediction, and calculating node and edge centrality scores.

The extensions are independent of each other. However, they depend on the core library for the basic graph operations.

Graphina Core

Module Feature or Algorithm Notes
Types Directed and undirected graphsWeighted and unweighted graphsNodeId and EdgeId wrappersNodeMap and EdgeMap type aliasesOrderedNodeMap for deterministic iteration Base types (graph, node, and edge) that Graphina supports
Error Handling Unified GraphinaError for all Graphina modulesResult type aliasError conversion helpers Error handling utilities for Graphina
Builders AdvancedGraphBuilder with validationTopologyBuilder (path, cycle, star, and complete graph builders)Type aliases (DirectedGraphBuilder, UndirectedGraphBuilder) Ergonomic graph construction utilities
IO Edge list (read and write)Adjacency list (read and write) I/O routines for reading and writing graph data
Serialization JSON serializationBinary serializationGraphML exportSerializableGraph format Multiple serialization formats for interoperability
Generators Erdős–Rényi graphWatts–Strogatz graphBarabási–Albert graphComplete graph (directed and undirected)Bipartite graphStar graphCycle graphPath graphRandom tree Graph generators for random and structured graphs
Paths Dijkstra's algorithmBellman-Ford algorithmFloyd-Warshall algorithmJohnson's algorithmA* search algorithmIterative deepening A* (IDA*) Shortest paths algorithms
Validation Graph connectivity checkDAG validationBipartite checkNegative weights detectionSelf-loops detectionComponent countingAlgorithm precondition validators Graph property validation utilities
Pool NodeSet poolNodeMap poolNodeQueue poolThread-local default pools Experimental memory pooling utilities

Extensions

Module Feature/Algorithm Notes
Centrality DegreeClosenessBetweenness (node & edge)EigenvectorPageRank (standard & personalized)KatzHarmonicLocal reachingGlobal reachingVoteRank (seed selector)LaplacianPercolation (planned) Centrality and influence measures
Metrics DiameterRadiusAverage clustering coefficientClustering coefficient (local)Average path lengthTransitivityTriangles countAssortativity coefficient Graph-level and node-level metrics
MST Prim's algorithmKruskal's algorithmBorůvka's algorithm Minimum spanning tree algorithms
Traversal Breadth-first search (BFS)Depth-first search (DFS)Iterative deepening DFS (IDDFS)Bidirectional search Graph traversal algorithms
Subgraphs Subgraph extractionInduced subgraphEgo graphK-hop neighborsFilter nodes or edgesConnected component extractionComponent subgraph Subgraph operations and filtering
Links Resource allocation indexJaccard coefficientAdamic-Adar indexPreferential attachmentCommon neighborsCN Soundarajan-HopcroftRA index Soundarajan-HopcroftWithin-inter-cluster ratioCommon neighbor centrality Link prediction algorithms
Community Label propagationLouvain methodGirvan-Newman algorithmSpectral clusteringPersonalized PageRankInfomapConnected components Community detection and clustering algorithms
Approximation Node connectivity (BFS-based)Maximum independent set (greedy)Maximum clique (greedy heuristic)Clique removalLarge clique sizeAverage clustering coefficient (approximate)Densest subgraph (greedy peeling)Diameter lower boundMinimum weighted vertex cover (greedy)Minimum maximal matching (greedy)Ramsey number R(2,t) approximationTSP approximations (greedy, simulated annealing, threshold accepting, and Christofides)Treewidth decompositions (min degree, and min fill-in) Approximation algorithms for NP-hard problems
Parallel Parallel BFSParallel degree computationParallel clustering coefficientsParallel triangles countingParallel PageRankParallel shortest pathsParallel connected components Parallel implementations of popular graph algorithms
Visualization ASCII art visualizationForce-directed layoutCircular layoutGrid layoutHierarchical layoutHTML generationSVG exportPNG exportD3.js JSON format Graph visualization algorithms

Installation

cargo add graphina

Or add this to your Cargo.toml:

[dependencies]
graphina = "0.4.0"

Or this to use Graphina with all the features enabled:

[dependencies]
graphina = { version = "0.4.0", features = ["centrality", "community", "approximation", "mst", "traversal", "subgraphs", "visualization", "parallel", "pool"] }

[!NOTE] Graphina requires Rust 1.86 or later.

Documentation

Check out the docs and docs.rs/graphina for more information, including examples and API references.

Simple Example

use graphina::core::types::Graph;

fn main() {
    // Create a new undirected graph
    let mut graph = Graph::new();

    // Add nodes and edges to the graph
    let n0 = graph.add_node(1);
    let n1 = graph.add_node(1);
    let n2 = graph.add_node(2);
    let n3 = graph.add_node(3);
    graph.add_edge(n0, n1, 1.0);
    graph.add_edge(n1, n2, 1.0);
    graph.add_edge(n2, n3, 1.0);

    // Get the neighbors of node 1
    for neighbor in graph.neighbors(n1) {
        println!("Node 1 has neighbor: {}", neighbor.index());
    }
}

Graph Builder API

use graphina::core::builders::UndirectedGraphBuilder;

// Use graph builder API to create an undirected graph
let g = UndirectedGraphBuilder::<i32, f64>::undirected()
.with_capacity(4, 3)
.add_node(1)
.add_node(2)
.add_node(3)
.add_edge(0, 1, 1.0)
.add_edge(1, 2, 2.0)
.build()
.unwrap();

Seeded Generators

use graphina::core::generators::{erdos_renyi_graph, barabasi_albert_graph};
use graphina::core::types::Undirected;

// Use 42 for pseudo-random seed (for deterministic results)
let er = erdos_renyi_graph::<Undirected>(100, 0.2, 42).unwrap();
let ba = barabasi_albert_graph::<Undirected>(1000, 3, 42).unwrap();

See the examples and tests directories for more usage examples.


Contributing

See CONTRIBUTING.md for details on how to make a contribution.

Logo

The mascot is named "Graphina the Dinosaur". As the name implies, she's a dinosaur, however, she herself thinks she's a dragon.

The logo was created using GIMP, ComfyUI, and a Flux Schnell v2 model.

Licensing

Graphina is licensed under either of these:

PyGraphina is licensed under the MIT License (LICENSE).