# Incremental improvement from A* to Dijkstra's

This topic is 2518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm looking for a way to smoothly present path improvement, starting from A* to a regular Dijkstra. I'm operating under an assumption that A* with its heuristics will find a path fast, while Dijkstra's will find the best path ever, though it might take significantly longer. Basically, I need my pathfinder to find (some) path immediately, with an option to improve it over the next second or two.

Obviously gradual reducing the heuristic towards-the-target bias should do the trick, but at the unacceptable cost of recalculating every-damn-thing at each pass.

I tried making A* not stop at a first found end node edge, and not putting the end node on the closed nodes list, but that resulted in the algorithm frantically hopping around the end node, trying to get at it from different angles. Also, nodes once visited in a seemingly good, but ultimately sub-optimal path (costly in terrain, but good in heuristics) were never visited again (closed list prevented that, naturally) even if backing away a bit from the proper direction resulted in finding a perfect shortcut path (very cheap terrain-wise, but not promising as far as heuristics go).

So, here's my puzzle: is there a known combination of these algorithms, capable of somehow gradually reducing the use of heuristics? Perhaps by some clever "reviving" of closed nodes if they prove to be reachable faster (though when I tried it, it kept reviving all nodes around the goal, for some reason)..?

##### Share on other sites
Hidden
Dijkstra's and A* will both give you the optimal path. A*, if it has a viable heuristic, has the potential to use the information that the heuristic gives to make the search faster.

I think what you're looking for is something along the lines of http://137.215.9.22/bitstream/handle/2263/10822/Botha_Shortest(2008).pdf?sequence=1

Hidden
What you're looking for is something along the lines of: http://137.215.9.22/bitstream/handle/2263/10822/Botha_Shortest(2008).pdf

I'm operating under an assumption that A* with its heuristics will find a path fast, while Dijkstra's will find the best path ever, though it might take significantly longer.
A* will find the shortest path, assuming your heuristic is "admissible" (it never overestimates the minimal cost of reaching the goal).

Another algorithm you might be interested in is 'iterative deepening A*'.

##### Share on other sites

A* will find the shortest path, assuming your heuristic is "admissible" (it never overestimates the minimal cost of reaching the goal).

Actually, I don't think it will: in a complex map where a direct portal (leading right next to the target point) lies just behind the starting point, no A* variant that I know of will ever knowingly move away from the target, unless it's stuck. So when there's a (mediocre) beeline from start to end, A* will never think of moving in the completely opposite direction, in hopes of finding a perfect shortcut from there. And this IS the kind of map that I'm working on - shortcuts and teleports and wormholes all over. Hence, no heuristic (that I know of) can be good enough.

Iterative deepening, though, looks like a series of A* runs, just with a narrowing acceptable cost - however, how exactly do I prevent the accepting of a too-costly solution? By never closing nodes whose total cost has already exceeded the allowed cost, perhaps, and just dropping them?

Also, how does that prevent the problem I described, where a heuristically "more interesting" node has already been seen (and thus, closed), and later somehow a shortcut leading directly to that node is found, exceeding the heuristic expectations? In my experience, the shortcut is ignored, since that node is in the closed list. Or, should nodes be taken out of the closed list, if cheaper paths to them are found? But, wouldn't that massively increase calculation time, with each interesting shortcut forcing the recalculation of a significant part of the map?

##### Share on other sites
A* will search the "whole solution space" like Dijkstra. It will just always try the "most obvious" path first which may allow it to terminate early.

##### Share on other sites

It will just always try the "most obvious" path first which may allow it to terminate early.

"May" allow? If I don't allow and just proceed, my ending node ends up on the closed list, and the search never again completes. If I leave it on the open list, though, it's constantly "licked at" from neighboring nodes, which are trying to find a better solution (but if the heuristic was good, these are worse than the first found beeline path). Do you mean that I should allow it anyway, thus wasting a lot of time for the nodes to "lick" at the end node, so that finally the move "backing away" from the end direction, and into the "portal", is considered? But even then, the portal will only lead to an already checked (and, thus, closed) node...

##### Share on other sites
i am not very familiar with A* but I think the key here is in determining the correct heuristic to make sure portals are accounted for when executing the search. I dont know what your current heuristic is, but if you are using Manhattan Distance to goal, you could try using Manhattan Distance to the nearest of goal or any portal. In that way you are sure you are never overestimating your heuristic.

I hope this will help!

##### Share on other sites
Hum. Minimum of goals or portals, you say... Now that's a thought.

That actually answers a different question - "how to get a perfect path even when portals are involved". However, maybe this renders my dilemma moot.

Interesting, will give it a spin. Thank you.

##### Share on other sites
The portals themselves could have a child node to the exit point as well so that nodes expansion would include a node a lot closer. Sorry I am a bit rusty on A*, but I need to implement it here very shortly, so I may come back with my concept solidified.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633757
• Total Posts
3013711
×