AgentSkillsCN

capacity-algorithms

EHZ 容量算法(HK2017、Tube、Billiard)。了解各类算法的适用场景、运行时特性以及应用领域。

SKILL.md
--- frontmatter
name: capacity-algorithms
description: EHZ capacity algorithms (HK2017, Tube, Billiard). When to use each, runtime characteristics, applicability domains.

Capacity Algorithms

This skill covers the three EHZ capacity algorithms available in rust_viterbo: HK2017, Tube, and Billiard. Use this to decide which algorithm to apply and understand performance characteristics.

Note: Algorithm crates (hk2017, tube, billiard) are currently stubs awaiting reimplementation. Sections marked "(LEGACY VERSION)" contain performance data from legacy experiments that may not match reimplemented code.

Quick Reference

AlgorithmDomainComplexityPractical LimitStatus
HK2017 (naive)Any polytopeO(F!)F <= 8Unimplemented
HK2017 (graph-pruned)Any polytopeunknownF <= 10Unimplemented
TubeNo Lagrangian 2-faceunknownunknownUnimplemented
BilliardLagrangian productO(E^6)unknownUnimplemented

Where F = number of facets, E = number of edges.

HK2017 Performance (LEGACY VERSION)

Runtime Formula

code
time_ms = 5.51e-04 * permutations^1.059

Simplified: ~1 microsecond per permutation (linear scaling), R^2 = 0.9997.

Permutation Count

For F facets: perms = sum_{k=2}^{F} F!/(F-k)!

Example: F=5 gives 20 + 60 + 120 + 120 = 320 permutations.

Budget Inversion

BudgetMax Facets (Naive)Max Facets (GraphPruned)
1 second89
5 seconds910
30 seconds1010+

FFI enforces a 10-facet hard limit to prevent runaway computation.

GraphPruned vs Naive

GraphPruned enumerates only cycles in the facet adjacency graph instead of all ordered subsets.

FacetsNaive TimeGraphPruned TimeSpeedup
50.27 ms0.13 ms2.0x
8111 ms15 ms7.4x
91383 ms551 ms2.5x

Best speedup on axis-aligned polytopes (tesseract) where adjacency graph is sparse.

Tube Algorithm Performance (LEGACY VERSION)

Runtime Formula

code
t_ms = beta * tubes, where beta ~ 1.6 us/tube

R^2 ~ 0.92 (less predictable than HK2017).

When Applicable

Tube algorithm requires the polytope to be non-Lagrangian (no Lagrangian 2-faces).

PolytopeTube TimeHK2017 Status
Cross-polytope (16f)1.2sInfeasible
24-cell (24f)249msInfeasible

Reference Capacity Values (LEGACY VERSION)

PolytopeFacetsCapacityAlgorithm
4-simplex50.4167HK2017
Tesseract84.0HK2017
Cross-polytope161.0Tube
24-cell242.0Tube

Mahler Bound (MISSING SOURCE)

The Mahler inequality states: c(K) * c(K^polar) >= 4.

Saturating Pairs

  1. Tesseract x Cross-polytope (polar duals):

    • c(tesseract) = 4.0, c(cross-polytope) = 1.0
    • Product = 4.0 (exact saturation)
  2. 24-cell (self-dual):

    • c(24-cell) = 2.0, c^2 = 4.0 (exact saturation)

These polytopes are extremal for Mahler in 4D.

Profiling Hotspots (LEGACY VERSION)

Cross-Polytope (16 facets, 15840 tubes/iter)

Function%Category
tube_capacity23.8%Algorithm
intersect_polygons16.2%Geometry
Memory ops (malloc/free/memcpy)~23%Memory

Profile: Memory-bound (many small tubes).

24-Cell (24 facets, 1152 tubes/iter)

Function%Category
tube_capacity32.7%Algorithm
do_inverse413.3%Linear algebra
intersect_polygons12.5%Geometry

Profile: Compute-bound (fewer, larger computations).

Closure Constraint Feasibility (LEGACY VERSION)

For a k-facet permutation, closure requires: sum_i beta_i * n_i = 0, beta_i >= 0

Failure Modes

  1. Small k < 5 on general-position polytopes: Over-determined
  2. Normals don't balance: Zero not in conic hull

Why Axis-Aligned Polytopes are Easier

Tesseract normals come in opposite pairs (+e_j, -e_j). For any facet sequence, there's likely a "balancing" normal available.

Escalation Rules

  1. Need HK2017 on F > 8: Consider parallel computation or accept Tube-only
  2. Capacity values change: Rerun algorithm_inventory and compare
  3. New polytope fails validation: Check Lagrangian 2-face detection