Reputation: 685
I tried to search google and stackoverflow for similar questions but I wasn't successful in finding any.
My implementation of A* works, however when collecting the path from the start node to the end node it simply loops through two nodes which are connected to each other (I can get from node A to node B but also from node B to node A).
I've followed wikipedia's A* implementation but also when I created Dijksta's algorithm it uses the same method which worked perfectly - so I'm confused as to why this is not.
My current output is this:
Node: 3093,
Node: 3085,
Node: 3093,
Node: 3085,
Node: 3093,
Node: 3085,
Node: 3093,
... repeated
Does anyone know why it doesn't properly store the .from? Also I'm wanting to store the edges that the program traversed to get the successful route - does anyone know how I'd do that? Can I simply implement a storage that will add the correct edge?
Upvotes: 1
Views: 79
Reputation: 875
Where you have the for loop with the comment: "//if the neighbor is in closed set, move to next neighbor" the break statement will just break out of the for loop and continue to evaluate the neighbor even though it is in the closed set.
Setting a boolean here and continue the while instead will atleast fix that problem.
Upvotes: 2