Sign in to follow this  
atcdevil

A* path reconstruction

Recommended Posts

atcdevil    145
I implemented A* based on the wikipedia.org article. It states: "This path reconstruction from the stored closed nodes (see below) means it is not necessary to store the path-so-far within each node." But below that line there is no mention of how to reconstruct the path. So how do I reconstruct the path from the 'closed' priority queue without storing the path so far in each node?

Share this post


Link to post
Share on other sites
Kris_A    182
You "traverse in reverse". Whenever you create a node, store its parent node. When you find the node that's at the target position, go into a loop that backtracks the list of nodes (using 'node->parent') until it reaches the first node, adding each node to a list. Then just reverse the list so the path is in the correct order (or if you like you can just go backwards through the list whenever you're making things actually follow the path)

if (node->x == target_x && node->y == target_x) {
while (node != first_node) {
list[list_pos++] = node;
node = node->parent;
}

reverse(list);
}


Hope this helps!

Share this post


Link to post
Share on other sites
atcdevil    145
that does, thank you very much.

although that solution is sufficient. is it possible to reconstruct the path without even storing the parent?

Share this post


Link to post
Share on other sites
Kris_A    182
Not sure, but I would guess not. If you're trying to optimise for size, I think the best you can get away with is storing the parent as a reference to an array element rather than a pointer.

Edit: You could always try different things, like running the pathfinder in reverse, and restrict it to the nodes already created by the first run. Not sure what results that would produce, though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this