golomb

Architecture Documentation

Module Overview

The Golomb ruler optimization project is structured into four main layers:

1. Core Layer (core/, utils/)

Purpose: Fundamental data structures and validation.

Components:

Dependencies: None (self-contained)

2. Heuristics Layer (heuristics/)

Purpose: Fast approximate solutions using metaheuristics.

Components:

Dependencies: core/, utils/random

Extension Points:

3. MCTS Layer (mcts/)

Purpose: Balanced exploration using Monte Carlo Tree Search.

Components:

Dependencies: core/, utils/random

Extension Points:

4. Exact Layer (exact/)

Purpose: Optimal solutions via constraint programming or integer linear programming.

Current Status: Stub implementation returning greedy seed.

Interface:

Future Implementations:

Dependencies: core/ (will require OR-Tools or similar)

5. CLI Layer (cli/)

Purpose: Command-line interface for running solvers.

Components:

Dependencies: All layers (core, heuristics, mcts, exact)

Data Flow

User Input (CLI)
    ↓
Mode Selection
    ↓
┌───────────┬──────────┬─────────────┐
│  Heuristic│   MCTS   │    Exact    │
└───────────┴──────────┴─────────────┘
    ↓            ↓            ↓
    └────────────┴────────────┘
              ↓
        Core Validation
              ↓
          Output Result

Build System

Testing Strategy

Unit Tests (tests/test_golomb_core.cpp)

Benchmarks (benchmarks/bench_build_partial_rule.cpp)

Performance Considerations

  1. Bitset representation: O(1) distance checks vs O(n) set lookup
  2. Sorted marks: binary search for insertion (O(log n))
  3. Mutation strategy: avoid full validation per candidate
  4. MCTS expansion: lazy child creation on first visit
  5. Memory: tree pruning for long searches (not implemented)

Code Style

Extension Guidelines

Adding a New Heuristic

  1. Add function signature to include/heuristics/<name>.hpp
  2. Implement in src/heuristics/<name>.cpp
  3. Use RuleState for efficient incremental construction
  4. Add tests in tests/test_<name>.cpp
  5. Link new source in CMakeLists.txt (golomb_heur target)

Integrating Neural Networks for MCTS

  1. Add dependency: PyTorch C++ (libtorch) or ONNX Runtime
  2. Replace compute_policy_priors_uniform() with network forward pass
  3. Replace evaluate_leaf() with value network output
  4. Add model loading in mcts_build() initialization
  5. Consider GPU acceleration for batch inference

Adding Exact Solver

  1. Add OR-Tools to CMakeLists via CPM or find_package
  2. Implement CP-SAT model in src/exact/exact_cpsat.cpp
  3. Update solve_exact_stub() to call real solver
  4. Add timeout handling and incremental bounds
  5. Test on small instances (n=4-6) with known optima

Maintenance Notes