Attention, Learn to Solve Routing Problems!

Wouter Kool, Herke van Hoof, Max Welling

Combinatorial optimization (CO) is the backbone of logistics, manufacturing, and even circuit design. The classic example is the Traveling Salesman Problem (TSP): given a list of cities, what is the shortest possible route that visits each city exactly once and returns to the start?

Because these problems are NP-hard, finding the absolute best solution for large instances is computationally exhausting. Traditionally, researchers rely on hand-crafted heuristics—rules of thumb designed by experts to find "good enough" solutions quickly. However, designing these rules is time-consuming and often problem-specific. This paper asks: Can we use machine learning to automatically "learn" these heuristics from data?

The authors introduce a powerful end-to-end deep learning framework that learns to solve combinatorial routing problems. By using a Transformer-inspired attention model and a novel reinforcement learning training strategy, they achieve near-optimal results on problems with up to 100 nodes, significantly outperforming previous neural approaches.

The Attention Model Architecture

The authors propose an Attention Model (AM) consisting of an encoder-decoder architecture. Previous models (like Pointer Networks) relied heavily on recurrent neural networks (LSTMs). By switching to Attention, the model can "look" at the entire graph at once, making it better at capturing global structures and easier to parallelize.

1. The Encoder

Similar to the Transformer architecture, the encoder uses multi-head attention (MHA) to create embeddings for all nodes in the graph. Crucially, it omits "positional encodings." Because the order in which nodes are listed in a graph shouldn't matter, the model must be permutation invariant. By treating the input as a set rather than a sequence, it forms a much more natural representation for routing problems.

The Encoder architecture using Multi-Head Attention to generate node and graph embeddings.

2. The Decoder

The decoder builds the solution (the tour) sequentially, one node at a time. At each step, it looks at the graph's overall state, the first node visited, and the last node visited to decide where to go next. It computes attention over the remaining unvisited nodes and outputs a probability distribution for the next destination.

The Decoder constructs the tour sequentially, using context embeddings to output probabilities for the next node.

Training Strategy: REINFORCE with a Greedy Rollout

Training a model to solve NP-hard problems using supervised learning is difficult because obtaining "optimal" ground-truth solutions for large datasets is computationally prohibitive. Instead, the authors use Reinforcement Learning (REINFORCE).

The paper's "secret sauce" is its Greedy Rollout Baseline. To stabilize training, they compare the current model's performance against a "baseline" version of itself—a frozen, deterministic version that always picks the most likely next node. They only update this baseline if the current model significantly outperforms it in a paired t-test. This self-improvement loop acts like a benchmark the model is constantly trying to beat, proving much more effective and efficient than using a traditional "critic" or value function.

Experiments and Key Results

The researchers evaluated their model on several NP-hard routing variants, generating random instances in a unit square. These included the Traveling Salesman Problem (TSP), Vehicle Routing Problem (VRP), Orienteering Problem (OP), and Prize Collecting TSP (PCTSP).

  • Near-Optimality: For TSP with 100 nodes, the model achieved an optimality gap of only 2.26% when using sampling. This is a massive improvement over previous neural methods, which often lagged by 7-10% or more.
  • Speed: While specialized solvers like LKH3 are highly accurate, they are slow. The Attention Model can solve 10,000 TSP-100 instances in about an hour on a single GPU, whereas LKH3 would take many hours on a CPU to reach similar quality.
  • Versatility and Generalization: Remarkably, the model used the exact same hyperparameters across all different problem types. It successfully outperformed specialized heuristics in the Orienteering Problem and Prize Collecting TSP, proving it is a flexible CO framework rather than just a narrow "TSP solver."

Limitations and Future Work

While solving 100-node instances is impressive for a neural network, real-world logistics often involve thousands of nodes. The $O(n^2)$ complexity of attention layers makes scaling difficult without "sparsifying" the graph (e.g., restricting attention to nearby neighbors).

Furthermore, the model currently handles hard constraints (like vehicle capacity) through simple "masking" (blocking invalid moves). More complex constraints might require sophisticated architectural changes. Finally, the authors suggest that combining this learned heuristic with traditional search methods—like Beam Search or 2-OPT local search—could help close the remaining gap to true optimality.

Summary updated

BibTeX
@inproceedings{kool2019attention,
  author = {Wouter Kool and Herke van Hoof and Max Welling},
  title = {{Attention, Learn to Solve Routing Problems!}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
  url = {https://openreview.net/forum?id=VIRqmhuos1},
}
Figure