Path Planning Using A* Algorithm
Shashank V Raghavan??
Artificial Intelligence?| Autonomous Systems??| Resident Robot Geek??| Quantum Computing??| Product and Program Management??
The A* Algorithm is a widely popular graph traversal path planning algorithm that works similarly to Dijkstra’s algorithm. But it directs its search toward the most promising states, potentially saving time. For approaching a near-optimal solution with the available data-set/node, A* is the most widely used method. It is commonly used in static environments but also dynamic environments. In the gaming industry, the A* algorithm is widely used. Thanks to artificial intelligence (AI), the A* algorithm has been improved and tailored for robot path planning, intelligent urban transportation, graph theory, and automatic control applications. It is less computationally intensive and simpler than many other path planning algorithms, and its efficiency makes it suitable for use on constrained and embedded systems.
The A* algorithm is a heuristic algorithm that finds the best path using heuristic information. The A* algorithm must search the map for nodes and apply appropriate heuristic functions to provide guidance. The two factors that govern an algorithm are the efficient resources used to perform the task and the response time or computation time taken to perform the task. When using the A* algorithm, there is a trade-off between speed and accuracy. We can reduce the algorithm’s time complexity in exchange for more memory or consume less memory for slower executions. We find the shortest path in both cases. The A* algorithm can be used to find the shortest path to an empty parking space in a crowded parking lot.
Explanation
Consider a square grid having many obstacles and we are given a starting cell and a target cell. We want to reach the target cell (if possible) from the starting cell as quickly as possible. Here A* Search Algorithm comes to the rescue. What A* Search Algorithm does is that at each step it picks the node according to a value-‘f’ which is a parameter equal to the sum of two other parameters – ‘g’ and ‘h’. At each step it picks the node/cell having the lowest ‘f’, and process that node/cell.
We define ‘g’ and ‘h’ as
g = the movement cost to move from the starting point to a given square on the grid, following the path generated to get there.?
h = the estimated movement cost to move from that given square on the grid to the final destination. This is often referred to as the heuristic, which is nothing but a kind of smart guess.
Algorithm?
Create Open List and Closed List (Dijkstra Algorithm)?
1. Initialize the open list
2. Initialize the closed list
put the starting node on the open
list (you can leave its f at zero)
3. while the open list is not empty
a) find the node with the least f on
the open list, call it "q"
b) pop q off the open list
c) generate q's 8 successors and set their
parents to q
d) for each successor
i) if successor is the goal, stop search
ii) else, compute both g and h for successor
successor.g = q.g + distance between
successor and q
successor.h = distance from goal to
successor (This can be done using many
ways, we will discuss three heuristics-
Manhattan, Diagonal and Euclidean
Heuristics)
successor.f = successor.g + successor.h
iii) if a node with the same position as
successor is in the OPEN list which has a
lower f than successor, skip this successor
iV) if a node with the same position as
successor is in the CLOSED list which has
a lower f than successor, skip this successor
otherwise, add the node to the open list
end (for loop)
e) push q on the closed list
end (while loop)
Consider the below figure if we want to reach the target cell from the source cell, then the A* Search algorithm would follow path as shown below. Note that the below figure is made by considering Euclidean Distance as a heuristics.
Heuristics?
The h function can be calculated using the following techniques:
Exact Heuristics – Either calculate the exact value of h (which is certainly time consuming).?????????????
OR?
Manhattan Distance – Approximate the value of h using some heuristics (less time consuming).
Exact Heuristics
This method helps to find the exact values of h, however this is very time consuming.
1) Pre-compute the distance between each pair of cells before running the A* Search Algorithm.
2) If there are no blocked cells/obstacles then we can just find the exact value of h without any pre-computation using the distance formula/Euclidean Distance.
Approximation Heuristics
1) Manhattan Distance –??
领英推荐
h = abs (current_cell.x – goal) + abs (current_cell.y – goal.y)
The Manhattan Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target cell).?
2) Diagonal Distance-?
dx = abs(current_cell.x – goal.x)
dy = abs(current_cell.y – goal.y)
h = D * (dx + dy) + (D2 - 2 * D) * min(dx, dy)
where D is length of each node(usually = 1) and D2 is diagonal distance between each node (usually = sqrt(2) ).
The Diagonal Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target cell).
3) Euclidean Distance-
h = sqrt ( (current_cell.x – goal.x)2 + (current_cell.y – goal.y)2 )
The Euclidean Distance Heuristics is shown by the below figure (assume red spot as source cell and green spot as target cell).
Implementation?
We can use any data structure to implement open list and closed list but for best performance, we use a set data structure of C++ STL(implemented as Red-Black Tree) and a Boolean hash table for a closed list. The implementations are similar to Dijkstra’s algorithm. If we use a Fibonacci heap to implement the open list instead of a binary heap/self-balancing tree, then the performance will become better (as Fibonacci heap takes O(1) average time to insert into open list and to decrease key)
Also to reduce the time taken to calculate g, we will use dynamic programming.??
Advantages:
Disadvantages: