scirs2-graph-0.1.0-alpha.1 has been yanked.
SciRS2 Graph
Graph theory and network analysis module for the SciRS2 scientific computing library. This module provides data structures and algorithms for working with graphs and networks.
Features
- Graph Data Structures: Efficient representations for directed and undirected graphs
- Graph Algorithms: Shortest paths, minimum spanning trees, flow algorithms
- Graph Measures: Centrality measures, clustering coefficients, graph similarity
- Spectral Methods: Spectral clustering, graph Laplacian, eigenvalue decomposition
- I/O Functions: Tools for reading and writing graphs in various formats
Usage
Add the following to your Cargo.toml:
[dependencies]
scirs2-graph = { workspace = true }
Basic usage examples:
use scirs2_graph::{base, algorithms, measures, spectral};
use scirs2_core::error::CoreResult;
fn create_undirected_graph() -> CoreResult<()> {
let mut graph = base::UndirectedGraph::new();
graph.add_node(1);
graph.add_node(2);
graph.add_node(3);
graph.add_edge(1, 2, 1.0)?;
graph.add_edge(2, 3, 2.0)?;
graph.add_edge(1, 3, 3.0)?;
println!("Graph has {} nodes and {} edges", graph.node_count(), graph.edge_count());
let path = algorithms::shortest_path::dijkstra(&graph, 1, 3)?;
println!("Shortest path from 1 to 3: {:?}", path);
let centrality = measures::centrality::degree_centrality(&graph)?;
println!("Degree centrality: {:?}", centrality);
Ok(())
}
fn spectral_clustering_example() -> CoreResult<()> {
let adj_matrix = ndarray::arr2(&[
[0.0, 1.0, 1.0, 0.0, 0.0, 0.0],
[1.0, 0.0, 1.0, 0.0, 0.0, 0.0],
[1.0, 1.0, 0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0, 1.0, 1.0],
[0.0, 0.0, 0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 0.0, 1.0, 1.0, 0.0],
]);
let n_clusters = 2;
let clusters = spectral::spectral_clustering(&adj_matrix, n_clusters, None, None)?;
println!("Cluster assignments: {:?}", clusters);
Ok(())
}
Components
Graph Base
Core graph data structures:
use scirs2_graph::base::{
Graph, DirectedGraph, UndirectedGraph, WeightedGraph, Node, Edge, Path, };
Graph Algorithms
Various graph algorithms:
use scirs2_graph::algorithms::{
dijkstra, bellman_ford, floyd_warshall, a_star,
prim, kruskal,
ford_fulkerson, edmonds_karp, dinic,
is_connected, connected_components, strongly_connected_components,
breadth_first_search, depth_first_search, topological_sort,
maximum_bipartite_matching, minimum_vertex_cover, };
Graph Measures
Functions for measuring graph properties:
use scirs2_graph::measures::{
degree_centrality, betweenness_centrality, closeness_centrality, eigenvector_centrality, pagerank,
clustering_coefficient, transitivity,
eccentricity, diameter, radius,
graph_edit_distance, graph_kernel, };
Spectral Methods
Spectral graph theory algorithms:
use scirs2_graph::spectral::{
laplacian_matrix, normalized_laplacian, spectral_clustering, spectral_embedding, fiedler_vector, algebraic_connectivity, };
Graph I/O
Functions for reading and writing graphs:
use scirs2_graph::io::{
read_edgelist, write_edgelist, read_adjacency_matrix, write_adjacency_matrix, read_gml, write_gml, read_graphml, write_graphml, };
Contributing
See the CONTRIBUTING.md file for contribution guidelines.
License
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.