smart-pch-tsp-rs

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).

No Dependencies — Only uses Rust standard library.

  • Universal Improver — Takes ANY path — returns a shorter one
  • Generic Points — Works with any type implementing the Point trait
  • Statistical Path Synthesis — Uses transition frequency analysis
  • Parallel Processing — Multi-agent system for faster computation
  • Better Quality — Improves paths by 1-2% on average (up to 3% on some datasets)
  • No Dependencies — Only uses Rust standard library

PCH improves paths through statistical analysis:

  1. Accept ANY initial path (from any algorithm)
  2. Build candidate framework (top N candidates per position)
  3. Generate hypotheses with random permutations
  4. Collect transition statistics (weighted by improvement)
  5. Synthesize better path from maximum-weight transitions

ParameterTypeDefaultDescription
permutations_per_hypothesisusize50Random swaps per hypothesis
batch_sizeu641000Batch size for thread sync
time_limitu6430Time limit in seconds
top_candidatesusize300Top candidates per position
num_agentsusize12Number of parallel agents

AlgorithmDistanceTime
Dynamic Gravity13,291.140.011s
PCH Improved13,162.0731.653s
Improvement129.07 (1.0%)

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);

This library is part of the NP Problem Ecosystem — a comprehensive suite of exact and heuristic solvers for the Traveling Salesman Problem:

ProjectDescriptionLanguage
Exact TSP SolverDual-mode TSP solver in Go: exact Branch & Bound with proven optimality, plus heuristic threshold search with reference gap.Go
Smart TSP OracleExact solver with adaptive thresholdingPython
Smart TSP SolverHeuristic solver with Angular-Radial & Dynamic GravityPython
Smart TSP BenchmarkProfessional testing infrastructurePython
smart-dynamic-gravity-tspFast physics-inspired TSP solverRust
smart-pch-tspUniversal PCH path improverRust

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

Links


Created by Alexander Suvorov Sr.

Copyright © 2026, Alexander Suvorov. All rights reserved.

Rust TSP PCH Heuristic Optimization Parallel