Backtracking in A star

喜你入骨 提交于 2019-11-26 09:05:10

问题


Blue-Walls

Green highlighted cells = open list

Red Highlighted cells = closed list

\"enter

Hello, can anyone tell me how can i implement backtracking in a a star search algorithm? I\'ve implemented the a star search according to wiki, but it does not backtrack, what i mean by backtrack is that the open list(green cells) contains 2,0 and 3,3 as shown in the picture, upon reaching 2,0 the current node would \"jump\" to 3,3 since the cost is now more than 3,3 and continue the search from there, how can it be done so that it would backtrack from 2,0->2,1->2,2... all the way back to 3,3 and start the search from there?


回答1:


your image is like 2d grid map

But your text suggest graph approach which is a bit confusing.

  • For 2D grid map the costs must be different between cells on path

You got too much of cost=100 in there and therefore you can not backtrack the path. You have to increase or decrease cost on each step and fill only cells that are near last filled cells. That can be done by recursion on big maps or by scanning whole map or bounding box for last filled number on small maps.

  • Look here for mine C++ A* implementation

The backtracking

Can be done by scanning neighbors of start/end cells after A* filling moving always to the smallest/biggest cost

In this example start filling from (2,0) until (3,3) is hit and then backtrack from (3,2) cost=8 to the smallest cost (always cost-1 for incremental filling). If you need the path in reverse order then start filling from (3,3) instead ...

speedup

Sometimes double filling speed up the process so: Start filling from both ends and stop when they join. To recognize which cell is filled from which point you can use positive and negative values, or some big enough ranges for costs.




回答2:


You can follow backpointers from the two nodes until you reach the common ancestor (0,2), then print the nodes you visited when following from (2,0), followed by the the nodes you visited when following from (3,3), printed in reverse.

To find the common ancestor of two nodes in an A* search tree, just maintain the two "current nodes", and follow the backpointer of whichever has the higher g-cost, until the two current nodes are in the same place.

It bears mentioning that this is a weird thing to do, though. A* is not a stack-based traversal, so it doesn't backtrack.



来源:https://stackoverflow.com/questions/28316046/backtracking-in-a-star

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!