question

Ryusuke T avatar image
1 Like"
Ryusuke T asked Jordan Johnson answered

Details of A Star Navigator

Please tell me more about A Star Navigator.

If two routes are found from start to goal, how will they be prioritized? For example, which direction is given priority from up, down, left, and right?

FlexSim 21.0.8
astar navigatoralgorithm
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jordan Johnson avatar image
0 Likes"
Jordan Johnson answered

Your question is good, although I'd like to clarify something. The A* algorithm doesn't find multiple shortest paths. Instead, it searches along the grid, building up a path as it goes. It if hits a dead end, the algorithm backtracks until it can make a different choice, and then continues building up its path. When it finds the goal, it uses the path that is currently built up.

But there are cases where two or more paths qualify as shortest. A* will only find one, but I think you could still ask the same question, with a slight difference: which of the shortest paths will it find?

I think the answer is that it's indeterminate. The reason for this is a bit technical, but here it is. As part of implementing the A* algorithm, we put new candidate nodes into a heap, sorted by the node's distance to the goal. A heap is a sorting data structure, but it isn't stable, which means that items with the same score can be in any order. So if two nodes are just as good of a path, there's not a reliable way to predict which one FlexSim's AStar will choose.

You can check out the definition of the heap for yourself, since the AStar module source code is now publicly available:

https://github.com/flexsim/AStar/blob/master/AStarDLL/AStarNavigator.h#L44

In the middle of AStarNavigator::calculatePath(), you can see nodes being checked, to see if they can go on the open set:
https://github.com/flexsim/AStar/blob/master/AStarDLL/AStarNavigator.cpp#L982

Eventually, that method calls AStarNavigator::expandOpenSet(), which puts new entries on that heap:
https://github.com/flexsim/AStar/blob/master/AStarDLL/AStarNavigator.cpp#L1253

As the search progresses, it continually checks the heap for the next best node to search along:
https://github.com/flexsim/AStar/blob/master/AStarDLL/AStarNavigator.cpp#L918

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeanette F avatar image
0 Likes"
Jeanette F answered

Hello @Ryusuke T,

Please reference our manual which gives details about how A* works. The routes are prioritized by the fastest/shortest distance.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.