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