NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning 2-opt Heuristics for the Traveling Salesman Problem via Deep Reinforcement Learning

Paulo R. de O. da Costa, Jason Rhuggenaath, Yingqian Zhang, Alp Akcay

Abstract

This paper introduces a Deep Reinforcement Learning (DRL) approach to solve the Traveling Salesman Problem (TSP) by learning "improvement heuristics" rather than building tours from scratch. By training a policy to intelligently select the best 2-opt edge swaps, the model achieves near-optimal results more efficiently and with better generalization than previous deep learning methods.

Introduction

The Traveling Salesman Problem (TSP)—finding the shortest path that visits a set of cities and returns to the start—is a cornerstone of combinatorial optimization. While exact solvers exist, they are computationally expensive for large problems. Consequently, researchers use heuristics to find high-quality solutions quickly.

Recently, Deep Learning has been used to "learn" these heuristics. Most prior work focused on construction heuristics, where a model builds a tour node-by-node. However, these often require "crutches" like beam search or heavy sampling to reach high performance. This paper shifts the focus to improvement heuristics. Instead of building a tour, the model starts with an existing (even random) solution and iteratively refines it using "2-opt" moves—a classic technique that swaps two edges to reduce the total path length.

Illustration of a 2-opt move where two edges are swapped to potentially reduce total tour length.

The challenge lies in deciding which swap to make at each step to reach the global optimum quickly without getting stuck in local minima.

Methodology

The authors frame the 2-opt selection process as a Markov Decision Process (MDP) and solve it using a Policy Gradient algorithm. The core of their approach is a sophisticated neural architecture designed to capture the nuances of the TSP state.

Dual Encoder Architecture

The model uses two parallel encoders to represent the state. One encodes the current tour, and the other encodes the best tour found so far in the search. This allows the model to learn moves that aren't just greedy for the current step but contribute to long-term improvement.

The dual encoder architecture combining GCNs and RNNs to process current and best-found solutions.
  • Hybrid Representation: To capture both the spatial locations of nodes and their order in the tour, the encoders combine Graph Convolutional Networks (GCNs) for spatial topology and Long Short-Term Memory (LSTM) networks for sequence information. The authors found that using a bidirectional LSTM was vital to account for the symmetry of TSP tours.
  • Pointing Attention Mechanism: The decoder uses an attention mechanism to "point" to two specific nodes in the tour that should be swapped. This architecture is flexible and can theoretically be extended to more complex $k$-opt moves.
  • Reinforcement Learning: They use the REINFORCE algorithm with a value-function baseline (similar to Advantage Actor-Critic) to reduce gradient variance. They also include an entropy bonus to encourage exploration and prevent the model from converging too early on sub-optimal strategies.

Experimental Results

The models were trained and evaluated on synthetic 2D Euclidean TSP instances (TSP20, TSP50, and TSP100) and the standard TSPlib library.

  • Near-Optimality: On TSP100, the model achieved an optimality gap of just 0.87% within 2,000 steps, outperforming state-of-the-art construction-based DRL methods like GAT-Transformers.
  • Zero-Shot Generalization: Because the model learns the "logic" of what makes a good 2-opt swap rather than just memorizing paths, a policy trained on 50 nodes performed remarkably well when applied to 100 nodes (1.37% gap).
  • Competitive Performance: The model outperformed Google’s OR-Tools (a highly optimized industrial solver) on several real-world TSPlib instances, despite never having seen those specific node distributions during training.
  • Efficiency: While slower than a single greedy pass, the model is significantly faster than previous DRL improvement methods while achieving higher accuracy and better sample efficiency than construction-based models.

Conclusion and Future Work

This work demonstrates that learning improvement heuristics is a powerful alternative to construction-based DRL for combinatorial optimization. By leveraging the geometric and sequential properties of the TSP through a dual-encoder GCN-RNN architecture, the model learns generalizable strategies for tour refinement.

Limitations remain, including the computational overhead of the dual-encoder architecture and the current restriction to 2-opt moves. Future directions include exploring more complex $k$-opt operations (swapping 3 or more edges) and applying this framework to other combinatorial problems like the Vehicle Routing Problem (VRP).

Summary updated

BibTeX
@inproceedings{costa2020learning,
  author = {Paulo R. de O. da Costa and Jason Rhuggenaath and Yingqian Zhang and Alp Akcay},
  title = {{Learning 2-opt Heuristics for the Traveling Salesman Problem via Deep Reinforcement Learning}},
  booktitle = {ACML},
  year = {2020},
  url = {https://openreview.net/forum?id=hxRzGMbl3pW},
}
Figure