Improving Heuristics for A* Pathfinding
redblobgames.com
redblobgames.com
Outstanding.
* https://ojs.aaai.org/index.php/AAAI/article/view/11027 * https://arxiv.org/abs/2212.03978
It's about "planning" (ie. searching an action space) which does not generally have a heuristic, so it needs to do "exploration" (which is exactly the opposite of what you want for optimal path finding) to counteract getting stuck in local optima due to greedy search...
I'd be interesting to dive into bounds and good properties for sets of landmarks.
I imagine that if, - Every node is at least X cost/distance away from a landmark - Landmarks are no closer than Y cost/distance from each other
You can start promising a lot about the size of your open set on any execution.
A* on h* (perfect heuristic) takes O(l) where l is the length of the solution (could expand exactly l nodes, but solving/guessing ties incorrectly might bump this to a multiple around the avg edges per vertex). I imagine that having good bounds mean you'll take no longer than a certain amount of expansions/depth before you lock-into the railway that h* provides (and you need some extra work to get off it too).
> the number of nodes A* has to explore decreases from 12693 to 12693
It seems to me that you would need a step to select useful landmarks but the code doesn't seem to do this and I don't see it discussed.
But many games recalculate distance to target (one ping only) over and over again each step, so moving a single block half a map away causes an entire army to repath immediately.
1. If the cost of a tile decreases, the precalculated heuristic will be too high, so A* might find a non-shortest but ok path. In game, you can think of the dorf as following the path they already know about, because they don't yet know that there's a shorter way.
2. If the cost of a tile increases, the precalculated heuristic will be too low, so A* will find the optimal path but it will take a little bit longer (still not as long as if we weren't using this heuristic). In game, you can think of the dorf as following the path they already know about, but running into a wall, so then they find a path around it.
Besides that blocker, your idea sounds like a nice win.
If you don't already know exactly what the heuristic function is and that L is something called a landmark marker, and anyway what is a landmark marker anyway, you need to read quite a long way through the blog post to make sense of it.
And when you do finally get to that point, you realise it is all very simple, so why not just say that at the start?
This blog post is like a story. It doesn’t start with the ending.
I read your comment first, expecting to go to the article and see a bunch of undefined math terms, but that isn’t what happened at all.
Of course you need to know what a heuristic function is, so maybe you’re right in that sense. You absolutely do not need to know anything about landmarks to enjoy the post. I didn’t, and it was no trouble at all to follow.
Perhaps you found the “discovery” method of presentation not to your liking. Discovery means there’s a demo where you move the L around before its purpose is defined. Building an intuitive understanding before producing a rigorous definition is (now) considered a good teaching method.
It's such a quick prompt but can quickly signal how useful the model is in that language or framework, how much you have to constraint output with specs and tests.