Skip to main content

Crate geometric_traits

Crate geometric_traits 

Source
Expand description

§Geometric traits

Crates.io docs.rs CI Security Audit License: MIT Codecov

Rust crate providing algebraic and graph algorithms, and basic structs, designed with a trait-first, correctness-focused approach. It supports no_std environments and offers optional alloc support for algorithms requiring dynamic memory allocation. See CONTRIBUTING.md for the design philosophy and how to contribute.

§Available Algorithms

The table below lists the main algorithm entrypoints currently exported from geometric_traits::traits::algorithms. All listed algorithms require the alloc feature. RandomizedDAG additionally requires either std or hashbrown. Full citations live in the API docs, and the fuzz harnesses are under fuzz/fuzz_targets.

AlgorithmTraitComplexityReference
Bipartite Maximum MatchingHopcroftKarpO(E√V)Hopcroft & Karp (1973)
General Maximum MatchingBlossomO(V²E)Edmonds (1965)
General Min-Cost Perfect MatchingBlossomVO(V²E) believedKolmogorov (2009)
General Maximum MatchingGabow1976O(V³)Gabow (1976)
General Maximum MatchingMicaliVaziraniO(E√V)Micali & Vazirani (1980)
Linear Assignment (Dense LAPJV)LAPJVO(n³)Jonker & Volgenant (1987)
Linear Assignment (Sparse + Padding)SparseLAPJVO(n³)Jonker & Volgenant (1987)
Linear Assignment (Sparse Core)LAPMODO(n³)Volgenant (1996)
Rectangular Assignment (Diagonal Cost Extension)JaqamanO((L+R)³)Jaqaman et al. (2008)
Rectangular Assignment (Crouse LAPJV)CrouseO(min(n,m)²·max(n,m))Crouse (2016)
Topological SortingKahnO(V+E)Kahn (1962)
Elementary Circuit EnumerationJohnsonO((V+E)(C+1))Johnson (1975)
All-Pairs Shortest Paths (Weighted)FloydWarshallO(V³)Floyd (1962), Warshall (1962)
All-Pairs Shortest Paths (Non-Negative Weighted)PairwiseDijkstraO(V·(V+E)·log V)Dijkstra (1959)
All-Pairs Shortest Paths (Unweighted)PairwiseBFSO(V·(V+E))Moore (1959)
Diameter (Exact, Undirected Unweighted)Diameterworst-case O(V·(V+E))Crescenzi et al. (2013)
Strongly Connected ComponentsTarjanO(V+E)Tarjan (1972)
Maximum s-t Flow / Minimum CutDinicO(V²E)Dinitz (1970)
Maximum s-t Flow / Minimum CutEdmondsKarpO(VE²)Edmonds & Karp (1972)
Feedback Arc Set (Greedy Heuristic)EadesLinSmythO(V+E+cV), c = tangled-core sizeEades, Lin & Smyth (1993)
Biconnected Components / Articulation Points / BridgesBiconnectedComponentsO(V+E)Hopcroft & Tarjan (1973)
Cycle Detection (DFS)CycleDetectionO(V+E)DFS back-edge detection
Connected Components (Undirected)ConnectedComponentsO(V+E)Linear-time graph traversal
Minimum Spanning Forest (Kruskal)KruskalO(E log E)Kruskal (1956)
Minimum Spanning Forest (Prim)PrimO(E log V)Prim (1957)
Minimum Spanning Forest (Boruvka)BoruvkaO(E log V)Borůvka (1926), transl. Nešetřil et al. (2001)
Bipartite Detection / 2-ColoringBipartiteDetectionO(V+E)BFS 2-coloring
Tree / Forest DetectionTreeDetectionO(V+E)Component and edge-count predicates
Planarity Testing / EmbeddingPlanarityDetectionO(V+E)Boyer & Myrvold (2004)
Outerplanarity TestingOuterplanarityDetectionO(V+E)Boyer (2012)
K_{2,3} Homeomorph DetectionK23HomeomorphDetectionO(V+E)Boyer (2012)
K_{3,3} Homeomorph DetectionK33HomeomorphDetectionO(V+E)Boyer (2012)
Canonical Labeling (Labeled Simple Graphs)CanonicalLabelingworst-case exponential backtrackingJunttila & Kaski (2007)
Subgraph IsomorphismVf2worst-case exponential backtrackingCordella et al. (2004)
Community DetectionLouvainO(V+E) per levelBlondel et al. (2008)
Community DetectionLeidenO(L·E), L = iterationsTraag et al. (2019)
Root Node ExtractionRootNodesO(V+E)Graph primitive
Sink Node ExtractionSinkNodesO(V+E)Graph primitive
Singleton Node ExtractionSingletonNodesO(V+E)Graph primitive
Simple Path DetectionSimplePathO(V+E)Graph property check
Information Content PropagationInformationContentO(V+E)Resnik (1995)
Resnik Semantic SimilarityResnikO(R·(V+E)) per queryResnik (1995)
Lin Semantic SimilarityLinO(R·(V+E)) per queryLin (1998)
Wu-Palmer Semantic SimilarityWuPalmerO(V+E) per queryWu & Palmer (1994)
Line GraphLineGraphO(∑deg²)Whitney (1932)
Labeled Line GraphLabeledLineGraphO(∑deg²)Labeled variant for MCES / RASCAL
Modular ProductModularProductO(|P|²)Barrow & Burstall (1976)
Maximum Clique EnumerationMaximumCliqueO(3^(n/3)) worst caseTomita & Seki (2003); Prosser (2012)
Delta-Y Exchange DetectionDeltaYExchangeO(V+E)Delta-Y / Y-Delta detector for MCES filtering
Balanced Network FlowKocayO(K·(V+E))Kocay & Stone (1995)
Minimum-Cost Maximum Balanced FlowMinimumCostBalancedFlowhybrid exact (tree DP, bipartite min-cost flow, Blossom-V fallback)Kocay & Stone (1995); Kolmogorov (2009)
Stationary Distribution (Dense GTH)GthO(n³)Grassmann et al. (1985)
Eigenvalue DecompositionJacobiO(n³)Jacobi (1846)
Classical MDSClassicalMdsO(n³)Torgerson (1952)
Force-Directed LayoutForceAtlas2O(I·(V²+E)) exact, O(I·(V log V+E)) Barnes-HutJacomy et al. (2014)
Fast-Multipole Multilevel Layout (TMAP)FmmeO(L·I·(V log V + E)), L = coarsening levelsProbst & Reymond (2020)
Random DAG GenerationRandomizedDAGO(V² log V)Utility generator (needs std or hashbrown)

CanonicalLabeling returns a canonical order, a certificate and search statistics. Setting CanonicalLabelingOptions::collect_automorphism_generators to true also returns generators of the full label-preserving automorphism group, where generator[v] is the image of original dense vertex v. The generator vector is empty when collection is disabled or the graph is asymmetric, excludes the identity and need not be minimal.

PermutationGroup computes with such generators without enumerating the group. It builds a stabilizer chain by deterministic Schreier–Sims (Sims, 1970) and answers order, contains and orbit, and smallest_image returns the lexicographically smallest image of a set together with a group element reaching it, by a backtrack over the chain after Linton (2004) that is exponential only in the worst case.

§Node Ordering Primitives

The crate also exports reusable graph-level node ordering and node scoring building blocks from geometric_traits::traits::algorithms.

PrimitiveKindComplexityReference
DegeneracySortersmallest-last node orderingO(V+E)Matula & Beck (1983)
LayeredLabelPropagationSortermultiresolution node orderingO(|Γ| · U · (V+E) + |Γ|² · V log V)Boldi et al. (2011)
CoreNumberScorerk-core / shell scoreO(V+E)Batagelj & Zaveršnik (2003)
DegreeScorernode scoreO(V+E)Graph primitive
SecondOrderDegreeScorernode scoreO(V+E)Degree-of-neighbors score
TriangleCountScorernode scoreO(|V̂| · d_cover²)Exact triangle count
SquareCountScorernode scoreO(|V̂| · d_cover² · d_graph)Exact 4-cycle count
LocalClusteringCoefficientScorernode scoreO(|V̂| · d_cover² + V+E)Matches NetworkX clustering()
SquareClusteringCoefficientScorernode scoreO(V · d_graph³)Matches NetworkX square_clustering()
PageRankScorercentrality scoreO(iterations · (V+E))Brin & Page (1998); NetworkX-aligned
PowerIterationEigenvectorCentralityScorercentrality scoreO(iterations · (V+E))Shifted power iteration; NetworkX-aligned
KatzCentralityScorercentrality scoreO(iterations · (V+E))Katz (1953); NetworkX-aligned
BetweennessCentralityScorercentrality scoreO(V · (V+E))Brandes (2001)
ClosenessCentralityScorercentrality scoreO(V · (V+E))Freeman (1979)
DescendingLexicographicScoreSortertwo-key node orderingO(V log V) plus scorer costLexicographic two-key sorter

§Undirected Graph Generators

Standalone functions for generating undirected graphs, all returning SymmetricCSR2D<CSR2D<usize, usize, usize>>. All require the alloc feature. Random generators additionally take a seed: u64 parameter.

§Deterministic Generators

GeneratorFunctionParameters
Complete Graph K_ncomplete_graph(n)n = vertices
Cycle C_ncycle_graph(n)n = vertices
Path P_npath_graph(n)n = vertices
Star S_nstar_graph(n)n = leaves
Grid G_{r×c}grid_graph(rows, cols)rows, cols
Hexagonal / Honeycomb Latticehexagonal_lattice_graph(rows, cols)rows, cols = hexagon rows, cols
Triangular Latticetriangular_lattice_graph(rows, cols)rows, cols = vertex-grid rows, cols
Torus T_{r×c}torus_graph(rows, cols)rows, cols
Hypercube Q_dhypercube_graph(d)d = dimension
Barbell B(k, p)barbell_graph(clique_size, path_len)clique_size, path_len
Crown Cr_ncrown_graph(n)n = vertices per side
Wheel W_nwheel_graph(n)n = rim vertices
Complete Bipartite K_{m,n}complete_bipartite_graph(m, n)m, n = partition sizes
Petersenpetersen_graph()-
Turán T(n, r)turan_graph(n, r)n = vertices, r = partitions
Windmill Wd(k, n)windmill_graph(num_cliques, clique_size)num_cliques, clique_size
Friendship F_nfriendship_graph(n)n = triangles = windmill_graph(n, 3)

§Random Generators

Random generators require std or hashbrown in addition to alloc when they use a HashSet internally.

GeneratorFunctionParametersReference
Erdős-Rényi G(n, m)erdos_renyi_gnm(seed, n, m)n = vertices, m = edgesErdős & Rényi (1959)
Erdős-Rényi G(n, p)erdos_renyi_gnp(seed, n, p)n = vertices, p = edge probabilityGilbert (1959); geometric skip: Batagelj & Brandes (2005)
Barabási-Albertbarabasi_albert(seed, n, m)n = vertices, m = edges/step; initial clique size = m + 1Barabási & Albert (1999)
Watts-Strogatzwatts_strogatz(seed, n, k, beta)n = vertices, k = neighbours, β = rewiring prob.Watts & Strogatz (1998)
Random Regularrandom_regular_graph(seed, n, k) -> Result<_, _>n = vertices, k = degreeConfiguration model; Wormald (1999)
Stochastic Block Modelstochastic_block_model(seed, sizes, p_intra, p_inter)community sizes, within-community p, between-community pHolland, Laskey & Leinhardt (1983)
Configuration Modelconfiguration_model(seed, degrees)degree sequenceMolloy & Reed (1995)
Chung-Luchung_lu(seed, weights)weight vectorChung & Lu (2002)
Random Geometricrandom_geometric_graph(seed, n, radius)n = vertices, r = connection radiusGilbert (1961); Penrose (2003)

§Graph & Set Similarity Metrics

Standalone free functions and a GraphSimilarities trait for comparing graphs or sets by their overlap. The trait provides edge-based, vertex-based, and combined similarity methods via default implementations. Any type that reports matched counts and graph sizes gets all metrics for free. These do not require the alloc feature.

MetricFunctionFormulaRangeReference
Jaccard / Tanimototanimoto_similarity|A∩B| / |A∪B|[0, 1]Jaccard (1901)
Dice / Sorensendice_similarity2|A∩B| / (|A|+|B|)[0, 1]Dice (1945); Sørensen (1948)
Overlap / Szymkiewicz-Simpsonoverlap_similarity|A∩B| / min(|A|,|B|)[0, 1]Szymkiewicz (1934); Simpson (1943)
Cosinecosine_similarity|A∩B| / sqrt(|A||B|)[0, 1]Salton & McGill (1983)
Tverskytversky_similarity|A∩B| / (|A∩B| + α|A\B| + β|B\A|)[0, 1]Tversky (1977)
Kulczynski (2nd)kulczynski_similarity0.5(|A∩B|/|A| + |A∩B|/|B|)[0, 1]Kulczyński (1927)
Braun-Blanquetbraun_blanquet_similarity|A∩B| / max(|A|,|B|)[0, 1]Braun-Blanquet (1932)
Sokal-Sneath (1st)sokal_sneath_similarity|A∩B| / (|A∩B| + 2|AΔB|)[0, 1]Sokal & Sneath (1963)
McConnaugheymcconnaughey_similarity(|A∩B|² - |A\B||B\A|) / (|A||B|)[-1, 1]McConnaughey (1964)
Johnsonjohnson_similarity(E_c+V_c)² / ((V₁+E₁)(V₂+E₂))[0, 1]Raymond et al. (2002)

Modules§

errors
Submodule defining common errors for the graph crate.
impls
Implementations of traits for standard library types.
naive_structs
Submodule providing naively implemented data structures for graphs.
prelude
Prelude module for the graph crate.
test_utils
Testing utilities for constructing type instances from raw bytes and replaying fuzz corpus or crash files, and shared invariant-checking functions used by both fuzz targets and regression tests.
traits
Submodule defining the graph-related traits.