A Kotlin-based research project for solving the Asymmetric Travelling Salesman Problem (ATSP) using regret-driven construction heuristics combined with local search optimization. This project evaluates how predicted regret matricesβproduced by machine learning modelsβcan guide greedy tour construction and subsequent 3-opt improvement, and analyses the impact of prediction noise on solution quality.
π Publication: This repository implements the heuristic components (Stage 3) of the following paper:
Heterogeneous graph neural networks for scalable asymmetric traveling salesman problem optimization
Walid Guettala, Γkos Levente HollΓ³-SzabΓ³, LΓ‘szlΓ³ GulyΓ‘s, JΓ‘nos Botzheim
Neurocomputing, Volume 671, 28 March 2026, Article 132718
DOI:
10.1016/j.neucom.2026.132718β Open Access (CC BY 4.0)π GNN training code (Stages 1 & 2): github.com/walidgeuttala/atsp_gnn
- Publication
- Overview
- Key Concepts
- Project Structure
- Algorithms
- Evaluation Pipelines
- Data Format
- Visualization
- Prerequisites
- Building & Running
- Output
- Citation
- License
This repository is part of a larger research effort published in Neurocomputing. The paper presents a three-stage pipeline for solving the ATSP at scale:
| Stage | Component | Description | Repository |
|---|---|---|---|
| 1 | Heterogeneous Line Graph HL(G) | Converts directed edges into nodes connected via four distinct adjacency types, preserving asymmetric relations and reducing density by 25% relative to undirected L(G). | atsp_gnn |
| 2 | Het-GAT | Relation-aware GNN that processes HL(G) to learn edge-level regret via relation fusion (summation, concatenation, or attention). Achieves 91.88% regret correlation on ATSP50. | atsp_gnn |
| 3 | Regret-Guided Heuristics | Batch-Selecting Regret-Guided Edge Builder + Regret-Guided Pre-Evaluating 3-Opt for tour construction and refinement. | This repository |
- Het-GAT-Concat achieves 8.34% optimality gap on ATSP250 and 7.89% on ATSP500, compared to GLOP's 27.96% and 38.96%.
- Runtimes of 0.75s (ATSP250) and 7.20s (ATSP500) β 86% faster than LKH-3.
- 98% reduction in training time and 75% reduction in training data compared to prior approaches.
- Scales effectively to 1000 nodes via subgraph inference.
This project implements and benchmarks Stage 3 of the pipeline β the regret-driven heuristic solvers for ATSP instances:
- Construction phase β The Batch-Selecting Regret-Guided Edge Builder constructs an initial tour in O(nΒ² log n) by iteratively selecting the lowest-regret edges from a predicted regret matrix, while maintaining feasibility constraints (no sub-tours, proper degree).
- Improvement phase β Regret-Guided Pre-Evaluating 3-Opt iteratively improves the tour in O(nΒ³) by evaluating segment reconnections, prioritizing edges with high predicted regret for removal.
The project provides multiple entry points for evaluating:
- Heuristic performance across different problem sizes (50, 100, 150, 250, 500 nodes)
- Impact of varying numbers of 3-opt iterations
- Sensitivity to Gaussian noise injected into predicted regret matrices
| Concept | Description |
|---|---|
| Regret Matrix | A square matrix where entry (i, j) represents the "regret" of not including edge (i β j) in the optimal solution. Lower regret β higher priority for selection. |
| Predicted vs. Expected Regret | The expected regret matrix is the ground truth; the predicted regret matrix is produced by a machine learning model and may contain noise. |
| Gap Ratio | The relative difference between the heuristic solution cost and the known optimum: (cost / optimal) - 1.0. A gap of 0.0 means optimal. |
| Noise Level | Standard deviation of additive Gaussian noise applied to the expected regret matrix, used to simulate prediction errors. |
regret_driven_heuristics/
βββ build.gradle # Gradle build configuration (Kotlin 2.2.0, JVM 17)
βββ settings.gradle # Project name definition
βββ gradle.properties # Kotlin code style settings
β
βββ src/main/kotlin/hu/akos/hollo/szabo/
β βββ EvaluateDataset.kt # Dataset analysis (regret matrix sparsity statistics)
β βββ EvaluateHeuristicsOnDifferent
β β ProblemSizesAndHyperParameters.kt # Evaluate across problem sizes & 3-opt iterations
β βββ EvaluateHeuristicsOnDifferent
β β ProblemSizesAndNoise.kt # Noise sensitivity analysis (all instances)
β βββ EvaluateHeuristicsOnDifferent
β β ProblemSizesAndNoise2.kt # Noise sensitivity analysis (single-solution instances)
β βββ CalculateNoiseOnRegretPredictions.kt # (Placeholder for noise calculation)
β β
β βββ heuristics/
β β βββ OneShotEdgeBuilder.kt # Greedy tour construction from regret matrix
β β βββ ThreeOptCycle.kt # Regret-guided 3-opt improvement cycle
β β βββ ThreeOptOperator.kt # 3-opt move application & cost delta computation
β β βββ EvaluateTsp.kt # Tour cost evaluation
β β
β βββ model/
β βββ RegretData.kt # Data class for an ATSP instance with regret matrices
β βββ LoadRegretData.kt # File parser for regret datasets
β βββ CostRecord.kt # Data class for tracking solution costs
β βββ GraphEdge.kt # Generic weighted directed edge
β βββ DoubleStatistics.kt # Descriptive statistics data class
β βββ ArrayExtensions.kt # Matrix utilities & statistics computation
β βββ NoiseRecord.kt # Record parser for experiment output files
β
βββ notebooks/
β βββ NoiseAnalyses.ipynb # Kotlin Notebook for visualizing noise experiments
β βββ output/ # Exported SVG plots
β βββ noise_plot_light.svg
β βββ noise_plot_light_heatmap.svg
β βββ noise_plot_light_merged.svg
β βββ ...
β
βββ output/ # Raw experiment output files
βββ output-2025-09-21.txt
βββ output-2025-09-21-2.txt
File: OneShotEdgeBuilder.kt
A greedy construction heuristic that builds a Hamiltonian tour in a single pass:
- For each source node, sorts candidate edges by ascending regret value.
- Iteratively selects the globally lowest-regret feasible edge, ensuring:
- No node has more than one outgoing or one incoming selected edge.
- No premature sub-tour is formed (tracked via sequence/chain bookkeeping).
- After selecting n β 1 edges, closes the tour with the remaining edge.
- Converts the sequential (successor) representation to a permutation.
This approach is efficient and deterministicβgiven a regret matrix, it always produces the same tour.
Files: ThreeOptCycle.kt, ThreeOptOperator.kt
A local search improvement operator that performs 3-opt moves guided by the predicted regret matrix:
- Edge prioritization: Ranks tour edges by descending predicted regret. Edges with high regret are more likely to be suboptimal and are prioritized for removal.
- Candidate filtering: For problem size 500, limits candidates to the top 206 highest-regret edges for tractability.
- Move evaluation: For each triple of candidate positions:
- Estimates cost change using the regret matrix as a fast filter.
- Computes exact cost delta from the distance matrix.
- Applies the move in-place if it improves the tour.
- Validation: Includes a runtime assertion verifying that incremental cost tracking matches the full re-evaluation.
The 3-opt move reconnects three tour segments by removing three edges and adding three new ones, producing a different segment ordering.
| Entry Point | Description |
|---|---|
EvaluateHeuristicsOnDifferentProblemSizesAndHyperParameters.kt |
Tests the heuristic pipeline on ATSP instances of size 100, 150, 250, and 500 with varying 3-opt iteration counts (0β9). Reports gap ratio and execution time statistics. |
EvaluateHeuristicsOnDifferentProblemSizesAndNoise.kt |
Injects Gaussian noise (Ο = 0.00β0.50) into expected regret matrices and evaluates the effect on solution quality across 0β10 3-opt iterations on size-50 instances. |
EvaluateHeuristicsOnDifferentProblemSizesAndNoise2.kt |
Same as above, but filtered to single-solution instances (where the expected regret matrix has exactly 2 zeros per row, and the edge builder recovers the optimal tour from clean data). Uses 10 noise samples per instance. |
EvaluateDataset.kt |
Analyses regret matrix properties: sparsity (zero-count) statistics and combinatorial branching factor of the expected regret. |
Each ATSP instance file follows a plain-text format:
<header line>
<distance matrix rows: space-separated doubles>
regret:
<expected regret matrix rows: space-separated doubles>
regret_pred:
<predicted regret matrix rows: space-separated doubles>
opt_cost <optimal tour cost>
Instance files are organized in directories by problem size (e.g., test_atsp100/, test_atsp150/).
The notebooks/NoiseAnalyses.ipynb Kotlin Notebook uses the Kandy plotting library to visualize experimental results:
- Line plots: Gap ratio vs. noise level, grouped by 3-opt iteration count
- Ribbon plots: Shaded area charts showing gap accumulation
- Heatmaps: Gap ratio as a function of both noise level and 3-opt iterations
Pre-rendered SVG plots are available in notebooks/output/.
- JDK 17 or later
- Gradle (wrapper included β no separate installation needed)
- ATSP dataset files stored locally (paths are hardcoded and must be adjusted to your environment)
./gradlew buildEach evaluation pipeline has its own main() function. Run them via Gradle or your IDE:
# Example: Run the noise sensitivity analysis
./gradlew run -PmainClass=hu.akos.hollo.szabo.EvaluateHeuristicsOnDifferentProblemSizesAndNoiseKtOr run directly from IntelliJ IDEA by clicking the green βΆ gutter icon next to any fun main().
Note: Dataset paths are currently hardcoded (e.g.,
H:\by-domain\official\phd\research\datasets\...). Update these paths in the source files to point to your local dataset location before running.
Evaluation results are written to the output/ directory as plain-text files with the naming convention output-<date>.txt. Each run produces pairs of lines:
- Gap ratio statistics β
DoubleStatistics(max=..., min=..., avg=..., q1=..., q2=..., median=..., standardDeviation=...) - Execution time statistics (milliseconds) β same format
These files can be loaded and visualized using the provided Kotlin Notebook.
| Technology | Version | Purpose |
|---|---|---|
| Kotlin | 2.2.0 | Primary language |
| Kotlin Coroutines | 1.6.4 | Concurrency support |
| Gradle | Wrapper | Build system |
| JVM | 17 | Target runtime |
| Kandy | β | Plotting (notebooks) |
If you use this code in your research, please cite:
@article{guettala2026heterogeneous,
title = {Heterogeneous graph neural networks for scalable asymmetric traveling salesman problem optimization},
author = {Guettala, Walid and HollΓ³-SzabΓ³, Γkos Levente and GulyΓ‘s, LΓ‘szlΓ³ and Botzheim, JΓ‘nos},
journal = {Neurocomputing},
volume = {671},
pages = {132718},
year = {2026},
publisher = {Elsevier},
doi = {10.1016/j.neucom.2026.132718},
url = {https://www.sciencedirect.com/science/article/pii/S0925231226001153},
note = {Open Access (CC BY 4.0)}
}All authors are affiliated with the Department of Artificial Intelligence, ELTE EΓΆtvΓΆs LorΓ‘nd University, Budapest, Hungary.
| Author | Role | ORCID |
|---|---|---|
| Walid Guettala (corresponding) | Conceptualization, Methodology, Software, Investigation, Data curation, Formal analysis, Writing | 0000-0001-5941-6818 |
| Γkos Levente HollΓ³-SzabΓ³ | Methodology, Software, Investigation, Writing | 0009-0008-6428-634X |
| LΓ‘szlΓ³ GulyΓ‘s | Supervision, Validation, Writing β review & editing | 0000-0002-6367-6695 |
| JΓ‘nos Botzheim | Supervision, Validation, Writing β review & editing | 0000-0002-7838-6148 |
This project accompanies an Open Access publication licensed under CC BY 4.0.