scirs2-graph 0.4.1

Graph processing module for SciRS2 (scirs2-graph)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::needless_range_loop)]
//! # SciRS2 Graph - Graph Algorithms and Network Analysis
//!
//! **scirs2-graph** provides comprehensive graph algorithms and data structures for network analysis,
//! offering shortest paths, centrality measures, community detection, spectral methods, and graph
//! embeddings with parallel processing and memory-efficient implementations.
//!
//! ## 🎯 Key Features
//!
//! - **Graph Representations**: Directed, undirected, weighted, multi-graphs
//! - **Classic Algorithms**: BFS, DFS, Dijkstra, A*, Bellman-Ford, Floyd-Warshall
//! - **Centrality Measures**: Betweenness, closeness, eigenvector, PageRank
//! - **Community Detection**: Louvain, label propagation, spectral clustering
//! - **Spectral Methods**: Graph Laplacian, spectral clustering, graph embeddings
//! - **Network Metrics**: Clustering coefficient, diameter, average path length
//! - **Performance**: Parallel algorithms, memory profiling
//!
//! ## 📦 Module Overview
//!
//! | SciRS2 Module | NetworkX/igraph Equivalent | Description |
//! |---------------|----------------------------|-------------|
//! | `algorithms` | `networkx.algorithms` | Core graph algorithms (BFS, DFS, shortest paths) |
//! | `measures` | `networkx.centrality` | Centrality and network metrics |
//! | `spectral` | `scipy.sparse.linalg` | Spectral graph theory and embeddings |
//! | `generators` | `networkx.generators` | Graph generation (random, regular, etc.) |
//! | `io` | `networkx.readwrite` | Graph I/O (GML, GraphML, edge lists) |
//!
//! ## 🚀 Quick Start
//!
//! ```toml
//! [dependencies]
//! scirs2-graph = "0.4.1"
//! ```
//!
//! ```rust,no_run
//! use scirs2_graph::{Graph, breadth_first_search, betweenness_centrality};
//!
//! // Create graph and run BFS
//! let mut g: Graph<i32, f64> = Graph::new();
//! let n0 = g.add_node(0);
//! let n1 = g.add_node(1);
//! g.add_edge(0, 1, 1.0);
//! ```
//!
//! ## 🔒 Version: 0.4.1
//!
//! ## API Stability and Versioning
//!
//! scirs2-graph follows strict semantic versioning with clear stability guarantees:
//!
//! ### Stability Classifications
//! - ✅ **Stable**: Core APIs guaranteed until next major version (2.0.0)
//! - ⚠️ **Experimental**: May change in minor versions, marked with `#[cfg(feature = "experimental")]`
//! - 📋 **Deprecated**: Will be removed in next major version, use alternatives
//!
//! ### Version Guarantees
//! - **MAJOR** (1.x.x → 2.x.x): Breaking changes to stable APIs allowed
//! - **MINOR** (1.0.x → 1.1.x): New features, deprecations only (no breaks to stable APIs)
//! - **PATCH** (1.0.0 → 1.0.1): Bug fixes only, no API changes
//!
//! ### Stable Core APIs (v0.4.0+)
//! - Graph data structures (`Graph`, `DiGraph`, `MultiGraph`)
//! - Basic algorithms (traversal, shortest paths, connectivity)
//! - Graph generators and I/O operations
//! - Community detection with `_result` suffix functions
//! - Error handling and core types

#![warn(missing_docs)]

pub mod advanced;
pub mod algorithms;
pub mod attributes;
pub mod base;
pub mod compressed;
pub mod embeddings;
pub mod error;
pub mod generators;
pub mod graph_memory_profiler;
pub mod io;
pub mod layout;
pub mod link_prediction;
pub mod measures;
pub mod memory;
pub mod numerical_accuracy_validation;
pub mod parallel_algorithms;
pub mod performance;
pub mod spectral;
pub mod streaming;
pub mod temporal;
pub mod temporal_graph;
pub mod temporal_interval;
pub mod weighted;

// Graph alignment (IsoRank)
pub mod alignment;
// Graph condensation (coreset, distillation, evaluation)
pub mod condensation;
// Distributed graph algorithms
pub mod distributed;
// GPU-accelerated graph operations
pub mod gpu;
// Graph transformers (GraphGPS, Graphormer)
pub mod graph_transformer;
// Graph partitioning (METIS, FENNEL)
pub mod partitioning;
// Signed and directed graph embeddings
pub mod signed_directed;
// Self-supervised learning on graphs
pub mod ssl;

// Graph Neural Network layers and transformers
pub mod gnn;

// SIMD-accelerated graph operations
#[cfg(feature = "simd")]
pub mod simd_ops;

// Re-export stable APIs for 1.0
pub use algorithms::{
    articulation_points,
    astar_search,
    astar_search_digraph,
    // Centrality measures - stable for 1.0
    betweenness_centrality,
    bidirectional_search,
    bidirectional_search_digraph,

    // Core traversal algorithms - stable for 1.0
    breadth_first_search,
    breadth_first_search_digraph,
    bridges,
    // Flow algorithms - stable for 1.0
    capacity_scaling_max_flow,
    center_nodes,
    closeness_centrality,
    complement,
    // Connectivity analysis - stable for 1.0
    connected_components,
    cosine_similarity,

    depth_first_search,
    depth_first_search_digraph,
    // Graph properties - stable for 1.0
    diameter,
    // Shortest path algorithms - stable for 1.0
    dijkstra_path,
    dinic_max_flow,
    dinic_max_flow_full,
    edge_subgraph,
    edmonds_karp_max_flow,
    eigenvector_centrality,
    eulerian_type,
    floyd_warshall,
    floyd_warshall_digraph,
    fluid_communities_result,
    ford_fulkerson_max_flow,
    // Girvan-Newman community detection
    girvan_newman_communities_result,
    girvan_newman_result,
    greedy_coloring,
    greedy_modularity_optimization_result,
    hierarchical_communities_result,
    hopcroft_karp,
    infomap_communities,
    is_bipartite,

    isap_max_flow,
    // Similarity measures - stable for 1.0
    jaccard_similarity,
    k_core_decomposition,

    k_shortest_paths,

    label_propagation_result,
    line_digraph,
    line_graph,
    // Community detection algorithms - stable for 1.0
    louvain_communities_result,
    maximal_matching,
    // Matching algorithms - stable for 1.0
    maximum_bipartite_matching,
    maximum_cardinality_matching,
    min_cost_max_flow,
    min_cost_max_flow_graph,
    minimum_cut,

    // Spanning tree algorithms - stable for 1.0
    minimum_spanning_tree,

    minimum_st_cut,
    minimum_weight_bipartite_matching,
    modularity,

    modularity_optimization_result,
    multi_commodity_flow,
    multi_source_multi_sink_max_flow,
    pagerank,
    parallel_max_flow,
    personalized_pagerank,

    push_relabel_max_flow,
    push_relabel_max_flow_full,
    radius,
    random_walk,
    stable_marriage,

    strongly_connected_components,
    subdigraph,
    // Graph transformations - stable for 1.0
    subgraph,
    tensor_product,
    // Other algorithms - stable for 1.0
    topological_sort,
    transition_matrix,

    weight_filtered_subgraph,

    // Result types - stable for 1.0
    AStarResult,
    BipartiteMatching,
    BipartiteResult,
    CommunityResult,
    CommunityStructure,
    CostEdge,
    DendrogramLevel,
    EulerianType,
    GirvanNewmanConfig,
    GirvanNewmanResult,
    GraphColoring,
    HopcroftKarpResult,
    InfomapResult,
    MaxFlowResult,
    MaximumMatching,
    MinCostFlowResult,
    MotifType,
    MultiCommodityFlowResult,
};

// Parallel algorithms - stable for 1.0 when parallel feature is enabled
#[cfg(feature = "parallel")]
pub use algorithms::{
    parallel_label_propagation_result, parallel_louvain_communities_result, parallel_modularity,
};

// Parallel spectral operations - stable for 1.0 when parallel feature is enabled
#[cfg(feature = "parallel")]
pub use spectral::{parallel_laplacian, parallel_spectral_clustering};

// Experimental algorithms - unstable, may change in future versions
pub use algorithms::{
    // Isomorphism and advanced matching - experimental
    are_graphs_isomorphic,
    are_graphs_isomorphic_enhanced,
    // Complex graph products - experimental
    cartesian_product,

    // NP-hard problems - experimental (may be moved or optimized)
    chromatic_number,
    find_isomorphism,
    find_isomorphism_vf2,
    find_motifs,
    find_subgraph_matches,
    graph_edit_distance,

    has_hamiltonian_circuit,
    has_hamiltonian_path,
};

// Advanced coloring algorithms
pub use algorithms::coloring::{
    chromatic_bounds, dsatur_coloring, edge_coloring, greedy_coloring_with_order, list_coloring,
    verify_coloring, welsh_powell, ChromaticBounds, ColoringOrder, EdgeColoring, ListColoring,
};

// Advanced motif and subgraph analysis
pub use algorithms::motifs::{
    count_3node_motifs, count_4node_motifs, count_motif_frequencies, frequent_subgraph_mining,
    graphlet_degree_distribution, sample_motif_frequencies, vf2_subgraph_isomorphism,
    wl_subtree_kernel, FrequentPattern, GraphletDDResult, GraphletDegreeVector, VF2Result,
    WLKernelResult,
};

// Link prediction algorithms
pub use link_prediction::{
    adamic_adar_all, adamic_adar_index, common_neighbors_all, common_neighbors_score, compute_auc,
    evaluate_link_prediction, jaccard_coefficient, jaccard_coefficient_all, katz_similarity,
    katz_similarity_all, preferential_attachment, preferential_attachment_all,
    resource_allocation_all, resource_allocation_index, simrank, simrank_score,
    LinkPredictionConfig, LinkPredictionEval, LinkScore,
};

// Core graph types - stable for 1.0
pub use base::{
    BipartiteGraph, DiGraph, Edge, EdgeWeight, Graph, Hyperedge, Hypergraph, IndexType,
    MultiDiGraph, MultiGraph, Node,
};

// Error handling - stable for 1.0
pub use error::{ErrorContext, GraphError, Result};

// Graph generators - stable for 1.0
pub use generators::{
    barabasi_albert_graph, complete_graph, cycle_graph, erdos_renyi_graph, grid_2d_graph,
    grid_3d_graph, hexagonal_lattice_graph, path_graph, planted_partition_model,
    power_law_cluster_graph, random_geometric_graph, star_graph, stochastic_block_model,
    triangular_lattice_graph, two_community_sbm, watts_strogatz_graph,
};

// Graph measures - stable for 1.0
pub use measures::{
    centrality, clustering_coefficient, graph_density, hits_algorithm, katz_centrality,
    katz_centrality_digraph, pagerank_centrality, pagerank_centrality_digraph, CentralityType,
    HitsScores,
};

// Parallel measures - stable for 1.0 when parallel feature is enabled
#[cfg(feature = "parallel")]
pub use measures::parallel_pagerank_centrality;

// Spectral analysis - stable for 1.0
pub use spectral::{laplacian, normalized_cut, spectral_radius};

// Weighted operations - stable for 1.0
pub use weighted::{
    MultiWeight, NormalizationMethod, WeightStatistics, WeightTransform, WeightedOps,
};

// Attribute system - stable for 1.0
pub use attributes::{
    AttributeSummary, AttributeValue, AttributeView, AttributedDiGraph, AttributedGraph, Attributes,
};

// Memory optimization - stable for 1.0
pub use memory::{
    suggest_optimizations, BitPackedGraph, CSRGraph, CompressedAdjacencyList, FragmentationReport,
    HybridGraph, MemoryProfiler, MemorySample, MemoryStats, OptimizationSuggestions,
    OptimizedGraphBuilder,
};

// Performance monitoring - stable for 1.0
pub use performance::{
    LargeGraphIterator, LargeGraphOps, MemoryMetrics, ParallelConfig, PerformanceMonitor,
    PerformanceReport, StreamingGraphProcessor,
};

// I/O operations - stable for 1.0
pub use io::*;

// Graph embedding algorithms
pub use embeddings::{
    DeepWalk, DeepWalkConfig, DeepWalkMode, Embedding, EmbeddingModel, LINEConfig, LINEOrder,
    Node2Vec, Node2VecConfig, RandomWalk, RandomWalkGenerator, SpectralEmbedding,
    SpectralEmbeddingConfig, SpectralLaplacianType, LINE,
};

pub use layout::{circular_layout, hierarchical_layout, spectral_layout, spring_layout, Position};

// Stream-model temporal graph (f64 timestamps, centrality, motifs, community)
pub use temporal::{
    count_temporal_triangles, evolutionary_clustering, temporal_betweenness, temporal_closeness,
    temporal_motif_count, temporal_pagerank, DynamicCommunity, TemporalEdge as StreamTemporalEdge,
    TemporalGraph as StreamTemporalGraph, TemporalMotifCounts,
};

// Interval-model temporal graph (generic typed nodes, TimeInstant/TimeInterval)
pub use temporal_interval::{
    temporal_betweenness_centrality, temporal_reachability, TemporalGraph, TemporalPath,
    TimeInstant, TimeInterval,
};

// Advanced mode optimizations - experimental but stable API
pub use advanced::{
    create_advanced_processor, execute_with_advanced, AdvancedConfig, AdvancedProcessor,
    AdvancedStats, AlgorithmMetrics, GPUAccelerationContext, NeuralRLAgent, NeuromorphicProcessor,
};

// Graph memory profiling - experimental
pub use graph_memory_profiler::{
    AdvancedMemoryProfiler,
    EfficiencyAnalysis,
    MemoryProfile,
    MemoryProfilerConfig,
    MemoryStats as GraphMemoryStats, // Renamed to avoid conflict
    OptimizationOpportunity,
    OptimizationType,
};

// Numerical accuracy validation - experimental
pub use numerical_accuracy_validation::{
    create_comprehensive_validation_suite, run_quick_validation, AdvancedNumericalValidator,
    ValidationAlgorithm, ValidationConfig, ValidationReport, ValidationResult,
    ValidationTolerances,
};

// Compressed sparse row graph representation
pub use compressed::{AdjacencyList, CsrGraph, CsrGraphBuilder, NeighborIter};

// Parallel graph algorithms on CSR graphs
pub use parallel_algorithms::{
    bfs, connected_components as csr_connected_components, pagerank as csr_pagerank,
    triangle_count, BfsResult, ComponentsResult, PageRankConfig, PageRankResult,
    TriangleCountResult,
};

#[cfg(feature = "parallel")]
pub use parallel_algorithms::{
    parallel_bfs, parallel_connected_components, parallel_pagerank, parallel_triangle_count,
};

// Streaming graph processing
pub use streaming::{
    DegreeDistribution, DoulionTriangleCounter, EvictionStrategy, MascotTriangleCounter,
    MemoryBoundedConfig, MemoryBoundedProcessor, SlidingWindowGraph, StreamEdge, StreamEvent,
    StreamOp, StreamingGraph, TriangleCounterStats,
};