golomb

Golomb Ruler Optimization

CI Documentation Benchmarks Release GitHub release License: MIT Conventional Commits

C++20 project for finding optimal Golomb rulers using multiple approaches: heuristics, MCTS, and exact methods.

Overview

A Golomb ruler is a set of marks at integer positions such that all pairwise distances are distinct. This project implements three optimization layers:

  1. Core - Bitset-based distance tracking and validation (O(1) distance checks)
  2. Heuristics - Evolutionary algorithm with local search for quick solutions
  3. MCTS - Monte Carlo Tree Search with PUCT selection for balanced exploration
  4. Exact - OR-Tools CP-SAT solver for optimal solutions

Features

Building

Prerequisites

Quick Start

./scripts/build.sh
./scripts/run_tests.sh

# Or manually
mkdir build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
ctest --test-dir build

Pre-built Binaries

Download pre-compiled binaries from the latest successful CI run:

Extract the executable and run directly.

Usage

./build/golomb_cli --order 8 --ub 120 --mode mcts --iters 5000

# Options:
#   --order <n>       Number of marks (default: 8)
#   --ub <value>      Upper bound for positions (default: 120)
#   --mode <mode>     heur|mcts|exact (default: heur)
#   --iters <n>       Iterations for heur/mcts (default: 1000)
#   --c-puct <value>  PUCT exploration constant (default: 1.4)
#   --timeout <ms>    Exact solver timeout (default: 10000)

Architecture

core/              - Distance bitset, validation, state management
utils/             - RNG utilities
heuristics/        - Evolutionary algorithm, local search
mcts/              - PUCT-based MCTS with hooks for policy/value networks
exact/             - OR-Tools CP-SAT solver for exact optimization
cli/               - Command-line interface

See docs/ARCHITECTURE.md for detailed design documentation.

Documentation

Full API documentation is automatically generated with Doxygen and deployed to GitHub Pages:

Documentation is automatically updated on every push to the master branch.

Testing

# Run all tests
./scripts/run_tests.sh

# Run benchmarks
./build/golomb_benchmarks

Code Formatting

./scripts/format.sh

Performance Benchmarks

This project uses Google Benchmark for performance testing. Benchmarks run automatically on every push to master, comparing performance with previous commits to detect regressions.

View benchmark results:

Run benchmarks locally:

./build/golomb_benchmarks

Benchmark categories:

Performance regressions >10% will trigger warnings in pull requests.

Claude Code Integration (MCP)

This project is configured with Model Context Protocol (MCP) servers for enhanced development with Claude Code in VS Code.

Configured MCP servers:

Setup instructions: See docs/MCP_GUIDE.md

Prerequisites: Node.js 18+

Contributing

We welcome contributions! This project uses Conventional Commits for automated versioning and changelog generation.

Quick start:

  1. Fork and clone the repository
  2. Create a feature branch: git checkout -b feat/your-feature
  3. Make your changes following our coding standards
  4. Use conventional commit messages (see below)
  5. Run tests and ensure they pass
  6. Submit a pull request

Commit message format:

# Feature (minor version bump)
git commit -m "feat(core): add parallel distance calculation"

# Bug fix (patch version bump)
git commit -m "fix(mcts): correct PUCT formula"

# Breaking change (major version bump)
git commit -m "feat!: redesign API

BREAKING CHANGE: RuleState constructor signature changed"

For detailed guidelines: See CONTRIBUTING.md

Future Work

License

MIT License - See LICENSE

References