logo

A-Star Algorithm: Pathfinding Algorithm for Finding Shortest Path

   

Added on  2023-01-03

14 Pages2004 Words82 Views
A-Star Algorithm:
The A* algorithm is one of most used pathfinding algorithm which mainly finds the shortest
path between multiple points also known as nodes. In this algorithm a combination of two
heuristic functions are applied to search for next iteration. One heuristic function is h(n)
which mainly finds the estimate of the how the vertex n is away from the target node T. The
h(n) is also admissible that is it never overestimates the distance from current node to goal.
Another heuristic function in A* is g(n) which is the distance measured from current node to
the strating node. Now, in this particular case the nodes are all the grids in the square size
which is developed in MATLAB. The source is the robot starting position and the destination
is the End poisition in the grid which is chosen by user. Furthermore, the user can also choose
as many blockades as desired in step by step manner in unit grid points. The A star algorithm
finds the best (minimum distance) route from starting position to End position of the robot.
The route is shown by simulation in MATLAB.
Algorithm methodology:
The brief of the algorithm is the following. All the positions of obstacles, start and end are
extracted as given by the user. The starting position is also added in obstacle array as the
robot will not move in starting position. In map start, end, obstacles and empty grid points are
labelled as 1,0,-1 and 2. Then the initial heuristics h(0) and g(0) are calculated and then the
total cost f(0) = h(0) + g(0) is obtained. h(0) is calculated by a distance function defined in
distance.m. Then the queue in first step is calculated by the insert.m function where starting
positions, ending position as parent nodes and their respective costs h(n), g(n) and f(n) are
taken as inputs and stored in the queue function. Now, the Astar main alogrithm is applied
inside a while loop where the exploration and queues after each explloration is updated by

expand_node.m and queue_fn.m. The loop continues till there exist a path between start and
the ending node and current node is not equals to the target node. Finally, the costs in each
iteration, queues in each step and the shortest path followed bhy the robot is displayed by the
result.m function. The shortest path is also shown by the line plot in the grid.
The expnasion of the A* algorithm is less expensive in comparison to dijkstra algorithm and
given by the follwing cost function relation.
f(n) = g(n) + h(n)
Here, f(n) = total distance through cuurent node
g(n) = so far cost to reach the node n
h(n) = estimated cost from current node to goal node.
Calculation of h(n) can be computed either by the Manhattan distance or by Euclidean
distance heuristics. Manhattan distance is calculated by summing the total number of squares
moved horizontally and vertically to reach the destination node from the starting node.
h=|xstart xend|+|ystart yend|
This is less accurate than the Eucildean distance heuristic but for computation Manhattan
distance is faster than Eucildean distance as in Euclidean distance a large area is needed to be
explored for finding the path. In this algorithm the Euclidean distance heuristics is employed
to find the cost due to its accuracy feature. The euclidean distance is given by,
h = ( xstart xend ) 2 + ( ystart yend ) 2
Flowchart of A* algorithm:

sample run:

Output obtained by running A_star.m.
Heuristic function f(n) = g(n) + h(n)
This is defined under add_1st_node function.
1 2 3 4 5 6
Select the Target location: Left click
1
2
3
4
5
6
Start
Target
QUEUE_COUNT =
16
QUEUE =

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Greedy Best First Search Algorithm for Finding Distance between Cities in Spain
|5
|827
|341

Search Algorithms and State Identification
|7
|1332
|60

Expert Programming Assignment Help
|20
|2590
|22