Universal TSP path improver using the PCH (Position-Candidate-Hypothesis) paradigm
Takes ANY TSP path (from ANY algorithm), statistically analyzes it, and synthesizes a shorter path.
smart-pch-tsp-rs — universal TSP path improver using the PCH (Position-Candidate-Hypothesis) paradigm.
PCH takes ANY TSP path (from ANY algorithm), statistically analyzes it, and synthesizes a shorter path.
Better Quality: Improves paths by 1-2% on average (up to 3% on some datasets).
Point traitPCH improves paths through statistical analysis:
Add to your Cargo.toml:
[dependencies] smart-pch-tsp = "0.1"
use smart_pch_tsp::{City, pch_improve};
let points = vec![
City { x: 0.0, y: 0.0 },
City { x: 1.0, y: 0.0 },
City { x: 0.0, y: 1.0 },
];
let initial_path = vec![0, 1, 2, 0];
let initial_distance = 4.0;
let (improved_distance, improved_path) = pch_improve(
&points,
&initial_path,
initial_distance,
50, // permutations_per_hypothesis
1000, // batch_size
30, // time_limit (seconds)
300, // top_candidates
12, // num_agents
);
println!("Improved: {:.2} -> {:.2}", initial_distance, improved_distance);
| Parameter | Type | Default | Description |
|---|---|---|---|
permutations_per_hypothesis | usize | 50 | Random swaps per hypothesis |
batch_size | u64 | 1000 | Batch size for thread sync |
time_limit | u64 | 30 | Time limit in seconds |
top_candidates | usize | 300 | Top candidates per position |
num_agents | usize | 12 | Number of parallel agents |
| Algorithm | Distance | Time |
|---|---|---|
| Dynamic Gravity | 13,291.14 | 0.011s |
| PCH Improved | 13,162.07 | 31.653s |
| Improvement | 129.07 (1.0%) | — |
This library is part of the NP Problem Ecosystem — a comprehensive suite of exact and heuristic solvers for the Traveling Salesman Problem:
| Project | Description | Language |
|---|---|---|
| Exact TSP Solver | Dual-mode TSP solver in Go: exact Branch & Bound with proven optimality, plus heuristic threshold search with reference gap. | Go |
| Smart TSP Oracle | Exact solver with adaptive thresholding | Python |
| Smart TSP Solver | Heuristic solver with Angular-Radial & Dynamic Gravity | Python |
| Smart TSP Benchmark | Professional testing infrastructure | Python |
| smart-dynamic-gravity-tsp | Fast physics-inspired TSP solver | Rust |
| smart-pch-tsp | Universal PCH path improver | Rust |
All projects are grounded in the Position-Candidate-Hypothesis (PCH) paradigm for NP-complete problems.
# Clone repository git clone https://github.com/smartlegionlab/smart-pch-tsp-rs cd smart-pch-tsp # Build cargo build # Run tests cargo test # Run documentation tests (checks code examples in docs) cargo test --doc # Run examples cargo run --example basic --release cargo run --example improve_dg --release # Run benchmarks cargo bench # Build documentation cargo doc --open
By using this software, you agree to the full disclaimer terms.
Software provided "AS IS" without warranty. You assume all risks.
Full legal disclaimer: See DISCLAIMER.md
License: BSD 3-Clause License