0

Most of the time when implementing a pathfinding algorithm such as A*, we seek to minimize the travel cost along the path. We could also seek to find the optimal path with the fewest number of turns. This could be done by, instead of having a grid of location states, having a grid of location-direction states. For any given location in the old grid, we would have 4 states in that spot representing that location moving left, right, up, or down. That is, if you were expanding to a node above you, you would actually be adding the 'up' state of that node to the priority queue, since we've found the quickest route to this node when going UP. If you were going that direction anyway, we wouldnt add anything to the weight. However, if we had to turn from the current node to get to the expanded node, we would add a small epsilon to the weight such that two shortest paths in distance would not be equal in cost if their number of turns differed. As long as epsilon is << cost of moving between nodes, its still the shortest path.

I now pose a similar problem, but with relaxed constraints. I no longer wish to find the shortest path, not even a path with the fewest turns. My only goal is to find a path of ANY length with numTurns <= n. To clarify, the goal of this algorithm would be to answer the question:

"Does there exist a path P from locations A to B such that there are fewer than or equal to n turns?"

I'm asking whether using some sort of greedy algorithm here would be helpful, since I do not require minimum distance nor turns. The problem is, if I'm NOT finding the minimum, the algorithm may search through more squares on the board. That is, normally a shortest path algorithm searches the least number of squares it has to, which is key for performance.

Are there any techniques that come to mind that would provide an efficient way (better or same as A*) to find such a path? Again, A* with fewest turns provides the "optimal" solution for distance and #turns. But for my problem, "optimal" is the fastest way the function can return whether there is a path of <=n turns between A and B. Note that there can be obstacles in the path, but other than that, moving from one square to another is the same cost (unless turning, as mentioned above).

I've been brainstorming, but I can not think of anything other than A* with the turn states . It might not be possible to do better than this, but I thought there may be a clever exploitation of my relaxed conditions. I've even considered using just numTurns as the cost of moving on the board, but that could waste a lot of time searching dead paths. Thanks very much!

Edit: Final clarification - Path does not have to have least number of turns, just <= n. Path does not have to be a shortest path, it can be a huge path if it only has n turns. The goal is for this function to execute quickly, I don't even need to record the path. I just need to know whether there exists one. Thanks :)

user2045279
  • 691
  • 1
  • 6
  • 16
  • (Assumes discrete values) Take a maximum of n steps, where on each step, you turn from each previously reachable node in every turnable direction and mark each new node accessible without turning as reachable. If you reach the final node, you have a path of least turns. (Manhattan distance?) – user1277170 Dec 05 '13 at 20:39
  • 1
    I don't think you can do better than linear for this problem. Transform the graph (4 new nodes for each old one), put costs on edges as 1 if it is a turn, and 0 if it is not, and run A*. However, with A* it might be tricky to create an admissible heuristic, so I would rather recommend to go with simple Iterative deepening DFS (plus DFS is usually considered to be better than BFS if you need *any* answer). [This](http://en.wikipedia.org/wiki/Graph_traversal) has a list of search algorithms if needed. – ile Dec 05 '13 at 22:05
  • The might helps http://stackoverflow.com/questions/19436859/pathfinding-a-with-least-turns – Zaikun Xu Oct 26 '15 at 09:48

0 Answers0