scirs2_graph/
lib.rs

1#![allow(clippy::field_reassign_with_default)]
2#![allow(clippy::needless_range_loop)]
3//! # SciRS2 Graph - Graph Algorithms and Network Analysis
4//!
5//! **scirs2-graph** provides comprehensive graph algorithms and data structures for network analysis,
6//! offering shortest paths, centrality measures, community detection, spectral methods, and graph
7//! embeddings with parallel processing and memory-efficient implementations.
8//!
9//! ## 🎯 Key Features
10//!
11//! - **Graph Representations**: Directed, undirected, weighted, multi-graphs
12//! - **Classic Algorithms**: BFS, DFS, Dijkstra, A*, Bellman-Ford, Floyd-Warshall
13//! - **Centrality Measures**: Betweenness, closeness, eigenvector, PageRank
14//! - **Community Detection**: Louvain, label propagation, spectral clustering
15//! - **Spectral Methods**: Graph Laplacian, spectral clustering, graph embeddings
16//! - **Network Metrics**: Clustering coefficient, diameter, average path length
17//! - **Performance**: Parallel algorithms, memory profiling
18//!
19//! ## 📦 Module Overview
20//!
21//! | SciRS2 Module | NetworkX/igraph Equivalent | Description |
22//! |---------------|----------------------------|-------------|
23//! | `algorithms` | `networkx.algorithms` | Core graph algorithms (BFS, DFS, shortest paths) |
24//! | `measures` | `networkx.centrality` | Centrality and network metrics |
25//! | `spectral` | `scipy.sparse.linalg` | Spectral graph theory and embeddings |
26//! | `generators` | `networkx.generators` | Graph generation (random, regular, etc.) |
27//! | `io` | `networkx.readwrite` | Graph I/O (GML, GraphML, edge lists) |
28//!
29//! ## 🚀 Quick Start
30//!
31//! ```toml
32//! [dependencies]
33//! scirs2-graph = "0.1.2"
34//! ```
35//!
36//! ```rust,no_run
37//! use scirs2_graph::{Graph, breadth_first_search, betweenness_centrality};
38//!
39//! // Create graph and run BFS
40//! let mut g: Graph<i32, f64> = Graph::new();
41//! let n0 = g.add_node(0);
42//! let n1 = g.add_node(1);
43//! g.add_edge(0, 1, 1.0);
44//! ```
45//!
46//! ## 🔒 Version: 0.1.2 (January 15, 2026)
47//!
48//! ## API Stability and Versioning
49//!
50//! scirs2-graph follows strict semantic versioning with clear stability guarantees:
51//!
52//! ### Stability Classifications
53//! - ✅ **Stable**: Core APIs guaranteed until next major version (2.0.0)
54//! - ⚠️ **Experimental**: May change in minor versions, marked with `#[cfg(feature = "experimental")]`
55//! - 📋 **Deprecated**: Will be removed in next major version, use alternatives
56//!
57//! ### Version Guarantees
58//! - **MAJOR** (1.x.x → 2.x.x): Breaking changes to stable APIs allowed
59//! - **MINOR** (1.0.x → 1.1.x): New features, deprecations only (no breaks to stable APIs)
60//! - **PATCH** (1.0.0 → 1.0.1): Bug fixes only, no API changes
61//!
62//! ### Stable Core APIs (v0.1.2+)
63//! - Graph data structures (`Graph`, `DiGraph`, `MultiGraph`)
64//! - Basic algorithms (traversal, shortest paths, connectivity)
65//! - Graph generators and I/O operations
66//! - Community detection with `_result` suffix functions
67//! - Error handling and core types
68
69#![warn(missing_docs)]
70
71// Temporarily commenting out OpenBLAS to fix build issues
72// extern crate blas;
73// extern crate openblassrc;
74
75pub mod advanced;
76pub mod algorithms;
77pub mod attributes;
78pub mod base;
79pub mod embeddings;
80pub mod error;
81pub mod generators;
82pub mod graph_memory_profiler;
83pub mod io;
84pub mod layout;
85pub mod measures;
86pub mod memory;
87pub mod numerical_accuracy_validation;
88pub mod performance;
89pub mod spectral;
90pub mod temporal;
91pub mod weighted;
92
93// Re-export stable APIs for 1.0
94pub use algorithms::{
95    articulation_points,
96    astar_search,
97    astar_search_digraph,
98    // Centrality measures - stable for 1.0
99    betweenness_centrality,
100    bidirectional_search,
101    bidirectional_search_digraph,
102
103    // Core traversal algorithms - stable for 1.0
104    breadth_first_search,
105    breadth_first_search_digraph,
106    bridges,
107    center_nodes,
108    closeness_centrality,
109    complement,
110    // Connectivity analysis - stable for 1.0
111    connected_components,
112    cosine_similarity,
113
114    depth_first_search,
115    depth_first_search_digraph,
116    // Graph properties - stable for 1.0
117    diameter,
118    // Shortest path algorithms - stable for 1.0
119    dijkstra_path,
120    // Flow algorithms - stable for 1.0
121    dinic_max_flow,
122    edge_subgraph,
123    eigenvector_centrality,
124    eulerian_type,
125    floyd_warshall,
126    floyd_warshall_digraph,
127    fluid_communities_result,
128    greedy_coloring,
129    greedy_modularity_optimization_result,
130    hierarchical_communities_result,
131    infomap_communities,
132    is_bipartite,
133
134    // Similarity measures - stable for 1.0
135    jaccard_similarity,
136    k_core_decomposition,
137
138    k_shortest_paths,
139
140    label_propagation_result,
141    line_digraph,
142    line_graph,
143    // Community detection algorithms - stable for 1.0
144    louvain_communities_result,
145    maximal_matching,
146    // Matching algorithms - stable for 1.0
147    maximum_bipartite_matching,
148    maximum_cardinality_matching,
149    minimum_cut,
150
151    // Spanning tree algorithms - stable for 1.0
152    minimum_spanning_tree,
153
154    minimum_weight_bipartite_matching,
155    modularity,
156
157    modularity_optimization_result,
158    pagerank,
159    personalized_pagerank,
160
161    push_relabel_max_flow,
162    radius,
163    random_walk,
164    stable_marriage,
165
166    strongly_connected_components,
167    subdigraph,
168    // Graph transformations - stable for 1.0
169    subgraph,
170    tensor_product,
171    // Other algorithms - stable for 1.0
172    topological_sort,
173    transition_matrix,
174
175    weight_filtered_subgraph,
176
177    // Result types - stable for 1.0
178    AStarResult,
179    BipartiteMatching,
180    BipartiteResult,
181    CommunityResult,
182    CommunityStructure,
183    EulerianType,
184    GraphColoring,
185    InfomapResult,
186    MaximumMatching,
187    MotifType,
188};
189
190// Parallel algorithms - stable for 1.0 when parallel feature is enabled
191#[cfg(feature = "parallel")]
192pub use algorithms::{
193    parallel_label_propagation_result, parallel_louvain_communities_result, parallel_modularity,
194};
195
196// Parallel spectral operations - stable for 1.0 when parallel feature is enabled
197#[cfg(feature = "parallel")]
198pub use spectral::{parallel_laplacian, parallel_spectral_clustering};
199
200// Experimental algorithms - unstable, may change in future versions
201pub use algorithms::{
202    // Isomorphism and advanced matching - experimental
203    are_graphs_isomorphic,
204    are_graphs_isomorphic_enhanced,
205    // Complex graph products - experimental
206    cartesian_product,
207
208    // NP-hard problems - experimental (may be moved or optimized)
209    chromatic_number,
210    find_isomorphism,
211    find_isomorphism_vf2,
212    find_motifs,
213    find_subgraph_matches,
214    graph_edit_distance,
215
216    has_hamiltonian_circuit,
217    has_hamiltonian_path,
218};
219
220// Core graph types - stable for 1.0
221pub use base::{
222    BipartiteGraph, DiGraph, Edge, EdgeWeight, Graph, Hyperedge, Hypergraph, IndexType,
223    MultiDiGraph, MultiGraph, Node,
224};
225
226// Error handling - stable for 1.0
227pub use error::{ErrorContext, GraphError, Result};
228
229// Graph generators - stable for 1.0
230pub use generators::{
231    barabasi_albert_graph, complete_graph, cycle_graph, erdos_renyi_graph, grid_2d_graph,
232    grid_3d_graph, hexagonal_lattice_graph, path_graph, planted_partition_model, star_graph,
233    stochastic_block_model, triangular_lattice_graph, two_community_sbm, watts_strogatz_graph,
234};
235
236// Graph measures - stable for 1.0
237pub use measures::{
238    centrality, clustering_coefficient, graph_density, hits_algorithm, katz_centrality,
239    katz_centrality_digraph, pagerank_centrality, pagerank_centrality_digraph, CentralityType,
240    HitsScores,
241};
242
243// Parallel measures - stable for 1.0 when parallel feature is enabled
244#[cfg(feature = "parallel")]
245pub use measures::parallel_pagerank_centrality;
246
247// Spectral analysis - stable for 1.0
248pub use spectral::{laplacian, normalized_cut, spectral_radius};
249
250// Weighted operations - stable for 1.0
251pub use weighted::{
252    MultiWeight, NormalizationMethod, WeightStatistics, WeightTransform, WeightedOps,
253};
254
255// Attribute system - stable for 1.0
256pub use attributes::{
257    AttributeSummary, AttributeValue, AttributeView, AttributedDiGraph, AttributedGraph, Attributes,
258};
259
260// Memory optimization - stable for 1.0
261pub use memory::{
262    suggest_optimizations, BitPackedGraph, CSRGraph, CompressedAdjacencyList, FragmentationReport,
263    HybridGraph, MemoryProfiler, MemorySample, MemoryStats, OptimizationSuggestions,
264    OptimizedGraphBuilder,
265};
266
267// Performance monitoring - stable for 1.0
268pub use performance::{
269    LargeGraphIterator, LargeGraphOps, MemoryMetrics, ParallelConfig, PerformanceMonitor,
270    PerformanceReport, StreamingGraphProcessor,
271};
272
273// I/O operations - stable for 1.0
274pub use io::*;
275
276// Experimental features - subject to change
277pub use embeddings::{
278    DeepWalk, DeepWalkConfig, Embedding, EmbeddingModel, Node2Vec, Node2VecConfig, RandomWalk,
279    RandomWalkGenerator,
280};
281
282pub use layout::{circular_layout, hierarchical_layout, spectral_layout, spring_layout, Position};
283
284pub use temporal::{
285    temporal_betweenness_centrality, temporal_reachability, TemporalGraph, TemporalPath,
286    TimeInstant, TimeInterval,
287};
288
289// Advanced mode optimizations - experimental but stable API
290pub use advanced::{
291    create_advanced_processor, execute_with_advanced, AdvancedConfig, AdvancedProcessor,
292    AdvancedStats, AlgorithmMetrics, GPUAccelerationContext, NeuralRLAgent, NeuromorphicProcessor,
293};
294
295// Graph memory profiling - experimental
296pub use graph_memory_profiler::{
297    AdvancedMemoryProfiler,
298    EfficiencyAnalysis,
299    MemoryProfile,
300    MemoryProfilerConfig,
301    MemoryStats as GraphMemoryStats, // Renamed to avoid conflict
302    OptimizationOpportunity,
303    OptimizationType,
304};
305
306// Numerical accuracy validation - experimental
307pub use numerical_accuracy_validation::{
308    create_comprehensive_validation_suite, run_quick_validation, AdvancedNumericalValidator,
309    ValidationAlgorithm, ValidationConfig, ValidationReport, ValidationResult,
310    ValidationTolerances,
311};