Urgent.News

What's breaking now, across thousands of outlets.

Tech

Improving Heuristics for A* Pathfinding

In his guide to A* pathfinding algorithms, the author introduces a technique to enhance the efficiency of these algorithms by incorporating "landmark nodes." By strategically placing landmark nodes, A* search can be accelerated by providing a heuristic that is more informed about the structure of the map.

The core idea behind landmark nodes is to calculate a "perfect" heuristic, which ideally knows the map structure and never points in the wrong direction. However, this perfect heuristic varies depending on the goal and start positions. To overcome this challenge, the author proposes using one or more landmark nodes to calculate a reusable heuristic that can be applied to multiple A* searches with different goals.

The article explains that by determining the path from the start to a specific landmark, we can also obtain the shortest path to any destination along this landmark path. This concept is demonstrated using a grid visualization, although landmark nodes can be applied to any graph structure.

The key to this technique lies in the triangle inequality, which states that the sum of two sides of a triangle is always greater than or equal to the third side. By adapting this inequality for directed graphs and precalculating the costs to a specific landmark, we can estimate the cost to reach other locations. This method avoids the impracticality of precalculating all costs and the excessive storage required for a perfect heuristic for every possible goal.

The author emphasizes that while the best placement of landmark nodes may vary depending on the specific project, a practical approach is to identify locations that are beneficial for multiple randomly chosen paths. By iteratively placing landmarks away from previously chosen ones, the algorithm can systematically improve pathfinding efficiency across various (start, goal) pairs.

Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at redblobgames.com →

More in Tech

More from Tuesday 28 July →