Static Edge Orientation (HeiOrient)

March 15, 2026 ยท View on GitHub

Original Repository: https://github.com/HeiOrient/HeiOrient


Overview

HeiOrient orients the edges of an undirected graph to minimize the maximum out-degree of any vertex. The optimal maximum out-degree equals the arboricity of the graph, defined as:

arboricity(G) = max over all subgraphs H of ceil(|E(H)| / (|V(H)| - 1))

Low out-degree orientations enable:

  • Space-efficient adjacency queries (each vertex stores only its out-neighbors)
  • Fast triangle enumeration (enumerate triangles in O(m * arboricity) time)
  • Compact graph representations for streaming and distributed settings

Three algorithms are available:

AlgorithmGuaranteeSpeedDescription
"two_approx"2-approximationFastGreedy orientation
"dfs"HeuristicMediumDFS-based local search improvement
"combined"Best qualitySlowerCombines greedy + DFS refinement

Orientation.orient_edges()

Signature

Orientation.orient_edges(
    g: Graph,
    algorithm: str = "combined",
    seed: int = 0,
    eager_size: int = 100,
) -> EdgeOrientationResult

Parameters

ParameterTypeDefaultDescription
gGraphrequiredInput undirected graph.
algorithmstr"combined"Algorithm: "two_approx", "dfs", or "combined".
seedint0Random seed for reproducibility.
eager_sizeint100Maximum path length for the eager path search heuristic (used by "combined").

Returns

EdgeOrientationResult

FieldTypeDescription
max_out_degreeintMaximum out-degree achieved across all vertices.
out_degreesnp.ndarray (int32)Out-degree of each vertex.
edge_headsnp.ndarray (int32)Head (target) of each oriented edge (same length as g.adjncy).

Exceptions

ExceptionCondition
InvalidModeErroralgorithm is not one of the valid choices.

Example

from chszlablib import Graph, Orientation

g = Graph.from_metis("graph.graph")

# Best quality orientation
result = Orientation.orient_edges(g, algorithm="combined")
print(f"Max out-degree: {result.max_out_degree}")
print(f"Out-degrees: {result.out_degrees}")

# Fast 2-approximation
fast = Orientation.orient_edges(g, algorithm="two_approx")
print(f"Fast max out-degree: {fast.max_out_degree}")

Performance Disclaimer

This Python interface wraps the HeiOrient C++ library via pybind11. While convenient for prototyping and integration into Python workflows, there is inherent overhead from the Python/C++ boundary and data conversion. For maximum performance on large-scale instances, use the original C++ implementation directly from the HeiOrient repository.


References

@inproceedings{DBLP:conf/esa/Reinstadtler0U24,
  author    = {Henrik Reinst{\"{a}}dtler and Christian Schulz and Bora U{\c{c}}ar},
  title     = {Engineering Edge Orientation Algorithms},
  booktitle = {32nd Annual European Symposium on Algorithms, {ESA} 2024},
  series    = {LIPIcs},
  volume    = {308},
  pages     = {97:1--97:18},
  publisher = {Schloss Dagstuhl - Leibniz-Zentrum f{\"{u}}r Informatik},
  year      = {2024},
  doi       = {10.4230/LIPIcs.ESA.2024.97}
}