TransPath: Learning Heuristics for Grid-Based Pathfinding via Transformers

Daniil E. Kirilenko, Anton Andreychuk, Aleksandr Panov, Konstantin S. Yakovlev

Abstract: Efficient pathfinding is a cornerstone of robotics and game AI. While the A* algorithm is a standard solution, its performance depends heavily on heuristic functions that are often blind to obstacles, leading to excessive computational overhead in complex environments. TransPath addresses this by using a hybrid CNN-Transformer architecture to predict instance-dependent heuristics. By learning a "correction factor" for standard distances and a "path probability map," TransPath reduces node exploration by up to 4x while maintaining path costs within 0.3% of the optimal solution.

Introduction

Standard pathfinding algorithms like A rely on a heuristic function ($h$) to estimate the remaining distance to a goal. Common heuristics, such as Octile or Manhattan distance, are instance-independent and assume a clear line of sight. In environments with complex geometries, such as "bugtraps" or mazes, these heuristics become overly optimistic. This causes A to explore thousands of unnecessary nodes before discovering a path around obstacles.

While neural networks have been used to predict the "perfect" distance ($h^*$), absolute distance values are difficult for models to learn across varying map scales. Furthermore, many purely machine-learning-based planners lack the theoretical safety guarantees, such as bounded sub-optimality, required for critical applications.

The TransPath Architecture

TransPath introduces a two-pronged approach using a novel neural network architecture that combines the strengths of Convolutional Neural Networks (CNNs) and Transformers.

The TransPath architecture: (a) shows the full pipeline from input map to output PPM; (b) details the ResNet block; (c) details the Transformer block.

As shown in the architecture diagram above, the model uses a CNN encoder to capture local features like corners and narrow passages. These features are then processed by Transformer blocks, which utilize self-attention to reason about global context—such as identifying a distant gap that serves as the only exit from a room. Finally, a CNN decoder projects these high-level features back into a grid format.

Heuristic Proxies and Search Integration

Instead of predicting raw distances, TransPath learns two specific proxies:

  1. Correction Factor ($cf$): This is the ratio between the "blind" heuristic and the perfect distance ($h / h^*$). Because this value is normalized between 0 and 1, it is significantly easier for the network to learn and generalizes better across different map sizes.
  2. Path Probability Map (PPM): A heatmap predicting the likelihood of each grid cell lying on the shortest path.

These proxies are integrated into the search process to improve efficiency. The Correction Factor is used in a weighted A variant to prioritize promising directions. The PPM is utilized as a secondary heuristic within the Focal Search* framework. This allows the algorithm to use "fuzzy" neural predictions to accelerate the search while mathematically guaranteeing that the resulting path cost does not exceed the optimal path by more than a user-defined factor ($w$).

Experimental Evaluation

The researchers trained TransPath on the Tiled Motion Planning (TMP) dataset, consisting of 64,000 unique 64x64 grids. The dataset was specifically filtered for "hard" instances where the shortest path is significantly longer than the straight-line distance, ensuring a rigorous test of the model's reasoning capabilities.

Visualization of search efficiency: the green area represents the nodes expanded by the algorithm, while the red line indicates the final path found.

Key Results

TransPath was compared against standard A, Weighted A, and Neural A*. The results highlight several advantages:

  • Efficiency: TransPath reduced the number of expanded nodes (computational effort) by a factor of 4x compared to standard A*.
  • Path Quality: Solutions were nearly optimal, with costs exceeding the shortest possible path by less than 0.3% on average.
  • Success Rate: In complex "bugtrap" scenarios, TransPath solved significantly more instances within a fixed time budget than its competitors.

Conclusion and Future Work

TransPath demonstrates that combining local CNN features with the global reasoning of Transformers can drastically improve pathfinding efficiency without sacrificing optimality. By predicting ratios rather than absolute distances, the model achieves stable training and high accuracy.

Future work aims to scale the architecture to larger grids, as the quadratic cost of self-attention currently limits the model to moderate map sizes. Additionally, the researchers plan to extend TransPath to 3D environments and dynamic scenarios involving moving obstacles.

Summary updated

BibTeX
@inproceedings{kirilenko2023transpath,
  author = {Daniil E. Kirilenko and Anton Andreychuk and Aleksandr Panov and Konstantin S. Yakovlev},
  title = {{TransPath: Learning Heuristics for Grid-Based Pathfinding via Transformers}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i10.26465},
}
Figure