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

Recent works using deep learning to solve the Traveling Salesman Problem (TSP) have focused on learning construction heuristics. Such approaches find TSP solutions of good quality but require expensive search procedures to reach optimality. This paper introduces a Deep Reinforcement Learning (DRL) approach to solve the TSP by learning an improvement heuristic rather than a construction one. By training a policy to iteratively apply 2-opt edge swaps using a dual GCN-LSTM encoder and pointing attention, the authors achieve near-optimal results that outperform previous deep learning methods and classical 2-opt heuristics in both speed and solution quality.

What Problem Does This Paper Address?

The Traveling Salesman Problem (TSP) is a cornerstone of combinatorial optimization: find the shortest route that visits a set of cities exactly once and returns to the start. Because it is NP-hard, researchers rely on heuristics.

Recent deep learning research has focused heavily on construction heuristics—algorithms that build a tour from scratch. While effective, these often require expensive search procedures (like beam search) to reach high-quality solutions. This paper shifts the focus to improvement heuristics, which start with an existing (even random) solution and iteratively refine it. Specifically, they automate the "2-opt" move—a classic local search technique that swaps two edges to remove crossings—by learning which swaps are most promising through reinforcement learning.

A 2-opt move swaps two edges to remove crossings and reduce tour length.

Methods

The authors frame the improvement process as a Markov Decision Process (MDP) and solve it using a Policy Gradient algorithm. The state representation consists of the current tour and the best tour found so far in the search.

The Architecture

As shown in the architecture diagram below, the model utilizes a sophisticated dual-stream approach to process the TSP state:

  • Dual Encoder: The model uses two identical encoder units. Each unit combines a Graph Convolutional Network (GCN) to capture the spatial relationships between nodes and a Bidirectional LSTM to capture the sequence information of the current tour.
  • Policy Decoder: Uses a pointing attention mechanism to select a pair of nodes $(i, j)$ that define the 2-opt swap. Unlike previous work, this architecture isn't tied to a fixed number of possible moves, making it more flexible.
  • Value Decoder: A critic network that estimates the expected future reward to reduce variance during training.
The dual-encoder architecture uses GCNs and RNNs to process the current and best-found solutions.

Training

They use REINFORCE with an advantage baseline and an entropy bonus to encourage exploration. Notably, they employ a curriculum-style approach, increasing the "episode length" (the number of allowed swaps) as training progresses.

Key Insights and Ideas

  • Learning the "Why" of 2-opt: Traditional 2-opt heuristics use fixed rules (like "First Improvement" or "Best Improvement"). This model learns a stochastic policy that can accept temporarily worse moves to escape local optima, acting similarly to metaheuristics like Simulated Annealing but with learned intuition.
  • The Power of Symmetry: By using bidirectional LSTMs, the model explicitly accounts for the fact that a TSP tour is valid in both directions, which significantly improves the quality of the learned representations.
  • History Matters: Including the "best-so-far" tour in the state representation allows the agent to understand its progress relative to the best known solution, leading to more stable improvements.
  • Zero-Shot Generalization: A policy trained on 50-node problems can be applied to 100-node problems and still outperform many construction-based methods, suggesting the model learns fundamental geometric properties of the TSP.

Key Results

  • Optimality Gaps: On TSP100, the model achieves an optimality gap of 0.87% within 2,000 steps. This is significantly better than the 1.42% gap achieved by the GAT-Transformer (Wu et al., 2019) using 5,000 samples.
  • Efficiency: The proposed method is more sample-efficient than previous improvement-based DL models, requiring 25–50% fewer samples during training to achieve superior results.
  • Comparison to Classical Heuristics: The learned policy consistently finds better solutions than standard "First Improvement" and "Best Improvement" 2-opt heuristics with restarts.
  • Real-World Performance: On TSPLib instances, the model outperformed Google's OR-Tools in 5 out of 10 tested cases, despite never seeing those specific node distributions during training.

Limitations and Future Work

While inference is fast, training the policy gradient model requires a large number of samples and significant computational time. Additionally, while the architecture is designed to be extensible to $k$-opt (swapping more than 2 edges), this paper only implements and evaluates 2-opt. The authors suggest that future work could explore TSPs with stochastic travel costs, where learned heuristics might provide even greater advantages over hand-coded ones.

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