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 compressed;
76pub mod embeddings;
77pub mod error;
78pub mod generators;
79pub mod graph_memory_profiler;
80pub mod io;
81pub mod layout;
82pub mod link_prediction;
83pub mod measures;
84pub mod memory;
85pub mod numerical_accuracy_validation;
86pub mod parallel_algorithms;
87pub mod performance;
88pub mod spectral;
89pub mod streaming;
90pub mod temporal;
91pub mod temporal_graph;
92pub mod temporal_interval;
93pub mod weighted;
94
95// SIMD-accelerated graph operations
96#[cfg(feature = "simd")]
97pub mod simd_ops;
98
99// Re-export stable APIs for 1.0
100pub use algorithms::{
101    articulation_points,
102    astar_search,
103    astar_search_digraph,
104    // Centrality measures - stable for 1.0
105    betweenness_centrality,
106    bidirectional_search,
107    bidirectional_search_digraph,
108
109    // Core traversal algorithms - stable for 1.0
110    breadth_first_search,
111    breadth_first_search_digraph,
112    bridges,
113    // Flow algorithms - stable for 1.0
114    capacity_scaling_max_flow,
115    center_nodes,
116    closeness_centrality,
117    complement,
118    // Connectivity analysis - stable for 1.0
119    connected_components,
120    cosine_similarity,
121
122    depth_first_search,
123    depth_first_search_digraph,
124    // Graph properties - stable for 1.0
125    diameter,
126    // Shortest path algorithms - stable for 1.0
127    dijkstra_path,
128    dinic_max_flow,
129    dinic_max_flow_full,
130    edge_subgraph,
131    edmonds_karp_max_flow,
132    eigenvector_centrality,
133    eulerian_type,
134    floyd_warshall,
135    floyd_warshall_digraph,
136    fluid_communities_result,
137    ford_fulkerson_max_flow,
138    // Girvan-Newman community detection
139    girvan_newman_communities_result,
140    girvan_newman_result,
141    greedy_coloring,
142    greedy_modularity_optimization_result,
143    hierarchical_communities_result,
144    hopcroft_karp,
145    infomap_communities,
146    is_bipartite,
147
148    isap_max_flow,
149    // Similarity measures - stable for 1.0
150    jaccard_similarity,
151    k_core_decomposition,
152
153    k_shortest_paths,
154
155    label_propagation_result,
156    line_digraph,
157    line_graph,
158    // Community detection algorithms - stable for 1.0
159    louvain_communities_result,
160    maximal_matching,
161    // Matching algorithms - stable for 1.0
162    maximum_bipartite_matching,
163    maximum_cardinality_matching,
164    min_cost_max_flow,
165    min_cost_max_flow_graph,
166    minimum_cut,
167
168    // Spanning tree algorithms - stable for 1.0
169    minimum_spanning_tree,
170
171    minimum_st_cut,
172    minimum_weight_bipartite_matching,
173    modularity,
174
175    modularity_optimization_result,
176    multi_commodity_flow,
177    multi_source_multi_sink_max_flow,
178    pagerank,
179    parallel_max_flow,
180    personalized_pagerank,
181
182    push_relabel_max_flow,
183    push_relabel_max_flow_full,
184    radius,
185    random_walk,
186    stable_marriage,
187
188    strongly_connected_components,
189    subdigraph,
190    // Graph transformations - stable for 1.0
191    subgraph,
192    tensor_product,
193    // Other algorithms - stable for 1.0
194    topological_sort,
195    transition_matrix,
196
197    weight_filtered_subgraph,
198
199    // Result types - stable for 1.0
200    AStarResult,
201    BipartiteMatching,
202    BipartiteResult,
203    CommunityResult,
204    CommunityStructure,
205    CostEdge,
206    DendrogramLevel,
207    EulerianType,
208    GirvanNewmanConfig,
209    GirvanNewmanResult,
210    GraphColoring,
211    HopcroftKarpResult,
212    InfomapResult,
213    MaxFlowResult,
214    MaximumMatching,
215    MinCostFlowResult,
216    MotifType,
217    MultiCommodityFlowResult,
218};
219
220// Parallel algorithms - stable for 1.0 when parallel feature is enabled
221#[cfg(feature = "parallel")]
222pub use algorithms::{
223    parallel_label_propagation_result, parallel_louvain_communities_result, parallel_modularity,
224};
225
226// Parallel spectral operations - stable for 1.0 when parallel feature is enabled
227#[cfg(feature = "parallel")]
228pub use spectral::{parallel_laplacian, parallel_spectral_clustering};
229
230// Experimental algorithms - unstable, may change in future versions
231pub use algorithms::{
232    // Isomorphism and advanced matching - experimental
233    are_graphs_isomorphic,
234    are_graphs_isomorphic_enhanced,
235    // Complex graph products - experimental
236    cartesian_product,
237
238    // NP-hard problems - experimental (may be moved or optimized)
239    chromatic_number,
240    find_isomorphism,
241    find_isomorphism_vf2,
242    find_motifs,
243    find_subgraph_matches,
244    graph_edit_distance,
245
246    has_hamiltonian_circuit,
247    has_hamiltonian_path,
248};
249
250// Advanced coloring algorithms
251pub use algorithms::coloring::{
252    chromatic_bounds, dsatur_coloring, edge_coloring, greedy_coloring_with_order, list_coloring,
253    verify_coloring, welsh_powell, ChromaticBounds, ColoringOrder, EdgeColoring, ListColoring,
254};
255
256// Advanced motif and subgraph analysis
257pub use algorithms::motifs::{
258    count_3node_motifs, count_4node_motifs, count_motif_frequencies, frequent_subgraph_mining,
259    graphlet_degree_distribution, sample_motif_frequencies, vf2_subgraph_isomorphism,
260    wl_subtree_kernel, FrequentPattern, GraphletDDResult, GraphletDegreeVector, VF2Result,
261    WLKernelResult,
262};
263
264// Link prediction algorithms
265pub use link_prediction::{
266    adamic_adar_all, adamic_adar_index, common_neighbors_all, common_neighbors_score, compute_auc,
267    evaluate_link_prediction, jaccard_coefficient, jaccard_coefficient_all, katz_similarity,
268    katz_similarity_all, preferential_attachment, preferential_attachment_all,
269    resource_allocation_all, resource_allocation_index, simrank, simrank_score,
270    LinkPredictionConfig, LinkPredictionEval, LinkScore,
271};
272
273// Core graph types - stable for 1.0
274pub use base::{
275    BipartiteGraph, DiGraph, Edge, EdgeWeight, Graph, Hyperedge, Hypergraph, IndexType,
276    MultiDiGraph, MultiGraph, Node,
277};
278
279// Error handling - stable for 1.0
280pub use error::{ErrorContext, GraphError, Result};
281
282// Graph generators - stable for 1.0
283pub use generators::{
284    barabasi_albert_graph, complete_graph, cycle_graph, erdos_renyi_graph, grid_2d_graph,
285    grid_3d_graph, hexagonal_lattice_graph, path_graph, planted_partition_model,
286    power_law_cluster_graph, random_geometric_graph, star_graph, stochastic_block_model,
287    triangular_lattice_graph, two_community_sbm, watts_strogatz_graph,
288};
289
290// Graph measures - stable for 1.0
291pub use measures::{
292    centrality, clustering_coefficient, graph_density, hits_algorithm, katz_centrality,
293    katz_centrality_digraph, pagerank_centrality, pagerank_centrality_digraph, CentralityType,
294    HitsScores,
295};
296
297// Parallel measures - stable for 1.0 when parallel feature is enabled
298#[cfg(feature = "parallel")]
299pub use measures::parallel_pagerank_centrality;
300
301// Spectral analysis - stable for 1.0
302pub use spectral::{laplacian, normalized_cut, spectral_radius};
303
304// Weighted operations - stable for 1.0
305pub use weighted::{
306    MultiWeight, NormalizationMethod, WeightStatistics, WeightTransform, WeightedOps,
307};
308
309// Attribute system - stable for 1.0
310pub use attributes::{
311    AttributeSummary, AttributeValue, AttributeView, AttributedDiGraph, AttributedGraph, Attributes,
312};
313
314// Memory optimization - stable for 1.0
315pub use memory::{
316    suggest_optimizations, BitPackedGraph, CSRGraph, CompressedAdjacencyList, FragmentationReport,
317    HybridGraph, MemoryProfiler, MemorySample, MemoryStats, OptimizationSuggestions,
318    OptimizedGraphBuilder,
319};
320
321// Performance monitoring - stable for 1.0
322pub use performance::{
323    LargeGraphIterator, LargeGraphOps, MemoryMetrics, ParallelConfig, PerformanceMonitor,
324    PerformanceReport, StreamingGraphProcessor,
325};
326
327// I/O operations - stable for 1.0
328pub use io::*;
329
330// Graph embedding algorithms
331pub use embeddings::{
332    DeepWalk, DeepWalkConfig, DeepWalkMode, Embedding, EmbeddingModel, LINEConfig, LINEOrder,
333    Node2Vec, Node2VecConfig, RandomWalk, RandomWalkGenerator, SpectralEmbedding,
334    SpectralEmbeddingConfig, SpectralLaplacianType, LINE,
335};
336
337pub use layout::{circular_layout, hierarchical_layout, spectral_layout, spring_layout, Position};
338
339// Stream-model temporal graph (f64 timestamps, centrality, motifs, community)
340pub use temporal::{
341    count_temporal_triangles, evolutionary_clustering, temporal_betweenness, temporal_closeness,
342    temporal_motif_count, temporal_pagerank, DynamicCommunity, TemporalEdge as StreamTemporalEdge,
343    TemporalGraph as StreamTemporalGraph, TemporalMotifCounts,
344};
345
346// Interval-model temporal graph (generic typed nodes, TimeInstant/TimeInterval)
347pub use temporal_interval::{
348    temporal_betweenness_centrality, temporal_reachability, TemporalGraph, TemporalPath,
349    TimeInstant, TimeInterval,
350};
351
352// Advanced mode optimizations - experimental but stable API
353pub use advanced::{
354    create_advanced_processor, execute_with_advanced, AdvancedConfig, AdvancedProcessor,
355    AdvancedStats, AlgorithmMetrics, GPUAccelerationContext, NeuralRLAgent, NeuromorphicProcessor,
356};
357
358// Graph memory profiling - experimental
359pub use graph_memory_profiler::{
360    AdvancedMemoryProfiler,
361    EfficiencyAnalysis,
362    MemoryProfile,
363    MemoryProfilerConfig,
364    MemoryStats as GraphMemoryStats, // Renamed to avoid conflict
365    OptimizationOpportunity,
366    OptimizationType,
367};
368
369// Numerical accuracy validation - experimental
370pub use numerical_accuracy_validation::{
371    create_comprehensive_validation_suite, run_quick_validation, AdvancedNumericalValidator,
372    ValidationAlgorithm, ValidationConfig, ValidationReport, ValidationResult,
373    ValidationTolerances,
374};
375
376// Compressed sparse row graph representation
377pub use compressed::{AdjacencyList, CsrGraph, CsrGraphBuilder, NeighborIter};
378
379// Parallel graph algorithms on CSR graphs
380pub use parallel_algorithms::{
381    bfs, connected_components as csr_connected_components, pagerank as csr_pagerank,
382    triangle_count, BfsResult, ComponentsResult, PageRankConfig, PageRankResult,
383    TriangleCountResult,
384};
385
386#[cfg(feature = "parallel")]
387pub use parallel_algorithms::{
388    parallel_bfs, parallel_connected_components, parallel_pagerank, parallel_triangle_count,
389};
390
391// Streaming graph processing
392pub use streaming::{
393    DegreeDistribution, DoulionTriangleCounter, EvictionStrategy, MascotTriangleCounter,
394    MemoryBoundedConfig, MemoryBoundedProcessor, SlidingWindowGraph, StreamEdge, StreamEvent,
395    StreamOp, StreamingGraph, TriangleCounterStats,
396};