Skip to main content

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.5"
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.5 (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.5+)
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
71pub mod advanced;
72pub mod algorithms;
73pub mod attributes;
74pub mod base;
75pub mod embeddings;
76pub mod error;
77pub mod generators;
78pub mod graph_memory_profiler;
79pub mod io;
80pub mod layout;
81pub mod measures;
82pub mod memory;
83pub mod numerical_accuracy_validation;
84pub mod performance;
85pub mod spectral;
86pub mod temporal;
87pub mod weighted;
88
89// Re-export stable APIs for 1.0
90pub use algorithms::{
91    articulation_points,
92    astar_search,
93    astar_search_digraph,
94    // Centrality measures - stable for 1.0
95    betweenness_centrality,
96    bidirectional_search,
97    bidirectional_search_digraph,
98
99    // Core traversal algorithms - stable for 1.0
100    breadth_first_search,
101    breadth_first_search_digraph,
102    bridges,
103    center_nodes,
104    closeness_centrality,
105    complement,
106    // Connectivity analysis - stable for 1.0
107    connected_components,
108    cosine_similarity,
109
110    depth_first_search,
111    depth_first_search_digraph,
112    // Graph properties - stable for 1.0
113    diameter,
114    // Shortest path algorithms - stable for 1.0
115    dijkstra_path,
116    // Flow algorithms - stable for 1.0
117    dinic_max_flow,
118    edge_subgraph,
119    eigenvector_centrality,
120    eulerian_type,
121    floyd_warshall,
122    floyd_warshall_digraph,
123    fluid_communities_result,
124    greedy_coloring,
125    greedy_modularity_optimization_result,
126    hierarchical_communities_result,
127    infomap_communities,
128    is_bipartite,
129
130    // Similarity measures - stable for 1.0
131    jaccard_similarity,
132    k_core_decomposition,
133
134    k_shortest_paths,
135
136    label_propagation_result,
137    line_digraph,
138    line_graph,
139    // Community detection algorithms - stable for 1.0
140    louvain_communities_result,
141    maximal_matching,
142    // Matching algorithms - stable for 1.0
143    maximum_bipartite_matching,
144    maximum_cardinality_matching,
145    minimum_cut,
146
147    // Spanning tree algorithms - stable for 1.0
148    minimum_spanning_tree,
149
150    minimum_weight_bipartite_matching,
151    modularity,
152
153    modularity_optimization_result,
154    pagerank,
155    personalized_pagerank,
156
157    push_relabel_max_flow,
158    radius,
159    random_walk,
160    stable_marriage,
161
162    strongly_connected_components,
163    subdigraph,
164    // Graph transformations - stable for 1.0
165    subgraph,
166    tensor_product,
167    // Other algorithms - stable for 1.0
168    topological_sort,
169    transition_matrix,
170
171    weight_filtered_subgraph,
172
173    // Result types - stable for 1.0
174    AStarResult,
175    BipartiteMatching,
176    BipartiteResult,
177    CommunityResult,
178    CommunityStructure,
179    EulerianType,
180    GraphColoring,
181    InfomapResult,
182    MaximumMatching,
183    MotifType,
184};
185
186// Parallel algorithms - stable for 1.0 when parallel feature is enabled
187#[cfg(feature = "parallel")]
188pub use algorithms::{
189    parallel_label_propagation_result, parallel_louvain_communities_result, parallel_modularity,
190};
191
192// Parallel spectral operations - stable for 1.0 when parallel feature is enabled
193#[cfg(feature = "parallel")]
194pub use spectral::{parallel_laplacian, parallel_spectral_clustering};
195
196// Experimental algorithms - unstable, may change in future versions
197pub use algorithms::{
198    // Isomorphism and advanced matching - experimental
199    are_graphs_isomorphic,
200    are_graphs_isomorphic_enhanced,
201    // Complex graph products - experimental
202    cartesian_product,
203
204    // NP-hard problems - experimental (may be moved or optimized)
205    chromatic_number,
206    find_isomorphism,
207    find_isomorphism_vf2,
208    find_motifs,
209    find_subgraph_matches,
210    graph_edit_distance,
211
212    has_hamiltonian_circuit,
213    has_hamiltonian_path,
214};
215
216// Core graph types - stable for 1.0
217pub use base::{
218    BipartiteGraph, DiGraph, Edge, EdgeWeight, Graph, Hyperedge, Hypergraph, IndexType,
219    MultiDiGraph, MultiGraph, Node,
220};
221
222// Error handling - stable for 1.0
223pub use error::{ErrorContext, GraphError, Result};
224
225// Graph generators - stable for 1.0
226pub use generators::{
227    barabasi_albert_graph, complete_graph, cycle_graph, erdos_renyi_graph, grid_2d_graph,
228    grid_3d_graph, hexagonal_lattice_graph, path_graph, planted_partition_model, star_graph,
229    stochastic_block_model, triangular_lattice_graph, two_community_sbm, watts_strogatz_graph,
230};
231
232// Graph measures - stable for 1.0
233pub use measures::{
234    centrality, clustering_coefficient, graph_density, hits_algorithm, katz_centrality,
235    katz_centrality_digraph, pagerank_centrality, pagerank_centrality_digraph, CentralityType,
236    HitsScores,
237};
238
239// Parallel measures - stable for 1.0 when parallel feature is enabled
240#[cfg(feature = "parallel")]
241pub use measures::parallel_pagerank_centrality;
242
243// Spectral analysis - stable for 1.0
244pub use spectral::{laplacian, normalized_cut, spectral_radius};
245
246// Weighted operations - stable for 1.0
247pub use weighted::{
248    MultiWeight, NormalizationMethod, WeightStatistics, WeightTransform, WeightedOps,
249};
250
251// Attribute system - stable for 1.0
252pub use attributes::{
253    AttributeSummary, AttributeValue, AttributeView, AttributedDiGraph, AttributedGraph, Attributes,
254};
255
256// Memory optimization - stable for 1.0
257pub use memory::{
258    suggest_optimizations, BitPackedGraph, CSRGraph, CompressedAdjacencyList, FragmentationReport,
259    HybridGraph, MemoryProfiler, MemorySample, MemoryStats, OptimizationSuggestions,
260    OptimizedGraphBuilder,
261};
262
263// Performance monitoring - stable for 1.0
264pub use performance::{
265    LargeGraphIterator, LargeGraphOps, MemoryMetrics, ParallelConfig, PerformanceMonitor,
266    PerformanceReport, StreamingGraphProcessor,
267};
268
269// I/O operations - stable for 1.0
270pub use io::*;
271
272// Experimental features - subject to change
273pub use embeddings::{
274    DeepWalk, DeepWalkConfig, Embedding, EmbeddingModel, Node2Vec, Node2VecConfig, RandomWalk,
275    RandomWalkGenerator,
276};
277
278pub use layout::{circular_layout, hierarchical_layout, spectral_layout, spring_layout, Position};
279
280pub use temporal::{
281    temporal_betweenness_centrality, temporal_reachability, TemporalGraph, TemporalPath,
282    TimeInstant, TimeInterval,
283};
284
285// Advanced mode optimizations - experimental but stable API
286pub use advanced::{
287    create_advanced_processor, execute_with_advanced, AdvancedConfig, AdvancedProcessor,
288    AdvancedStats, AlgorithmMetrics, GPUAccelerationContext, NeuralRLAgent, NeuromorphicProcessor,
289};
290
291// Graph memory profiling - experimental
292pub use graph_memory_profiler::{
293    AdvancedMemoryProfiler,
294    EfficiencyAnalysis,
295    MemoryProfile,
296    MemoryProfilerConfig,
297    MemoryStats as GraphMemoryStats, // Renamed to avoid conflict
298    OptimizationOpportunity,
299    OptimizationType,
300};
301
302// Numerical accuracy validation - experimental
303pub use numerical_accuracy_validation::{
304    create_comprehensive_validation_suite, run_quick_validation, AdvancedNumericalValidator,
305    ValidationAlgorithm, ValidationConfig, ValidationReport, ValidationResult,
306    ValidationTolerances,
307};