aprender-tsp
Local TSP (Traveling Salesman Problem) optimization with personalized .apr models.
Features
- Multiple Solvers: ACO (Ant Colony), Tabu Search, Genetic Algorithm, Hybrid
- TSPLIB Support: Standard benchmark instance format (berlin52, att48, eil51, etc.)
- Model Persistence: Train once, solve fast with
.aprbinary format - CLI & Library: Use as command-line tool or Rust library
- Deterministic: Seed-based reproducibility for benchmarking
Quick Start
# Install
# Train a model
# Solve new instances
# View model info
# Benchmark against known optimum
Algorithms
| Algorithm | Description | Best For |
|---|---|---|
| ACO | Ant Colony Optimization | General TSP, exploration |
| Tabu | Tabu Search with 2-opt | Local refinement |
| GA | Genetic Algorithm | Large instances |
| Hybrid | GA + Tabu + ACO pipeline | Best quality |
Library Usage
use ;
// Load instance
let instance = from_tsplib?;
// Solve with ACO
let mut solver = new
.with_num_ants
.with_alpha
.with_beta;
let solution = solver.solve?;
println!;
println!;
Pre-trained Models
POC models available on Hugging Face: paiml/aprender-tsp-poc
| Model | Instance | Gap from Optimal |
|---|---|---|
| berlin52-aco.apr | berlin52 | 1.92% |
| att48-aco.apr | att48 | 4.30% |
| eil51-aco.apr | eil51 | 4.07% |
Instance Format
Supports TSPLIB format (.tsp):
NAME: example
TYPE: TSP
DIMENSION: 4
EDGE_WEIGHT_TYPE: EUC_2D
NODE_COORD_SECTION
1 0.0 0.0
2 1.0 0.0
3 1.0 1.0
4 0.0 1.0
EOF
Also supports CSV format with optional header.
Model Format
.apr files are compact binary models (~77 bytes):
- Magic bytes:
APR\0 - Version: 1
- CRC32 checksum for integrity
- Algorithm-specific parameters
Part of Aprender
This crate uses aprender::metaheuristics for core optimization algorithms. See aprender for the full ML library.
License
MIT