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

Attention Solves Your TSP, Approximately

Wouter Kool, Herke van Hoof, Max WellingarXiv 2018

Abstract

The development of efficient (heuristic) algorithms for practical combinatorial optimization problems is costly, so we want to automatically learn them instead. We show the feasibility of this approach on the important Travelling Salesman Problem (TSP). We learn a heuristic algorithm that uses a Neural Network policy to construct a tour. As an alternative to the Pointer Network, our model is based entirely on (graph) attention layers and is invariant to the input order of the nodes. We train the model efficiently using REINFORCE with a simple and robust baseline based on a deterministic (greedy) rollout of the best policy so far. We significantly improve over results from previous works that consider learned heuristics for the TSP, reducing the optimality gap for a single tour construction from 1.51% to 0.32% for instances with 20 nodes, from 4.59% to 1.71% for 50 nodes and from 6.89% to 4.43% for 100 nodes. Additionally, we improve over a recent Reinforcement Learning framework for two variants of the Vehicle Routing Problem (VRP).

Introduction

Combinatorial optimization (CO) problems, such as the Traveling Salesman Problem (TSP) or Vehicle Routing Problem (VRP), are foundational challenges in logistics and manufacturing. Due to their NP-hard nature, finding exact solutions for large-scale instances is computationally prohibitive. Traditionally, these problems are addressed using hand-crafted heuristics—expert-designed rules of thumb. However, manual heuristic design is labor-intensive and may not generalize across problem variants.

This research explores the use of Deep Reinforcement Learning to automatically discover powerful heuristics. While previous architectures like Pointer Networks showed potential, they often lacked training stability and failed to fully leverage the inherent graph structure of CO problems. We propose the Attention Model (AM), an end-to-end architecture that utilizes graph attention and a novel training baseline to achieve state-of-the-art performance in learned heuristics.

Methods

The Attention Model (AM) consists of a graph-based encoder and an autoregressive decoder.

The Encoder: Graph Attention

Unlike recurrent architectures (e.g., LSTMs) that assume a sequential input order, the AM encoder uses a Transformer-style graph attention mechanism. This ensures the model is permutation invariant, meaning the output is independent of the order in which cities are listed. The encoder produces embeddings for each node and a global graph embedding.

The Attention Model encoder architecture featuring Multi-Head Attention (MHA) and Feed-Forward (FF) layers.

The Decoder: Autoregressive Construction

The model builds a solution step-by-step. At each time step $t$, it attends to the graph embeddings and the current "context"—comprising the global graph embedding, the first node visited, and the last node visited. This context is crucial for TSP, as the vehicle must eventually return to the starting point. An attention mechanism then selects the next node to visit, with a mask applied to prevent revisiting nodes.

Training via Rollout Baseline

To stabilize Reinforcement Learning (REINFORCE), we introduce a rollout baseline. During training, the current policy is compared against a "frozen" version of the best-performing model found so far. The baseline is updated only when the current model demonstrates a statistically significant improvement (via a t-test). This deterministic baseline provides a stable target, facilitating faster and more robust convergence compared to traditional critic networks.

Results

The Attention Model was evaluated on synthetic TSP and VRP datasets sampled uniformly in a 2D unit square. The AM significantly reduced the optimality gap compared to previous learning-based methods across various problem sizes.

Optimality gap vs. problem size for various TSP solvers, highlighting the performance of the Attention Model.

Key performance improvements include:

  • TSP20: Gap reduced from 1.51% to 0.32%.
  • TSP50: Gap reduced from 4.59% to 1.71%.
  • TSP100: Gap reduced from 6.89% to 4.43%.

Beyond TSP, the model generalized effectively to the Capacitated VRP (CVRP) and Split Delivery VRP (SDVRP). While training is computationally intensive, inference is remarkably efficient; the model can solve 10,000 TSP100 instances in approximately 5 seconds on a single GPU.

Conclusion

The Attention Model demonstrates that graph attention and stable reinforcement learning baselines can effectively learn high-quality heuristics for combinatorial optimization. By respecting the permutation invariance of graphs and incorporating necessary context, the AM narrows the gap between learned heuristics and exact solvers. Future work includes improving generalization across problem sizes and adapting the model to real-world constraints like complex road networks and time windows.

Summary updated

BibTeX
@misc{kool2018attention,
  author = {Wouter Kool and Herke van Hoof and Max Welling},
  title = {{Attention Solves Your TSP, Approximately}},
  year = {2018},
  eprint = {1803.08475},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1803.08475},
}
Figure