Visualizer for A* search algorithm in C using
raylib.
A* is a pathfinding algorithm that finds the shortest path between source and destination using a goal-directed heuristic.
demo.mp4
- If you are using linux make sure to run these to use docker buildkit and allow x11 forwarding
export DOCKER_BUILDKIT=1
xhost +local:root > /dev/null
- If you are using MacOS make sure to run these to use docker buildkit and allow x11 forwarding
export DOCKER_BUILDKIT=1
Setting up Docker for gui in mac: https://gist.github.com/roaldnefs/fe9f36b0e8cf2890af14572c083b516c
-
If you are using windows setup WSL and follow the steps for linux machine.
-
Clone the repository
git clone https://github.com/nishantHolla/a-star-visualizer
cd a-star-visualizer
- Run build script to build in debug mode
./build.sh debug
or in release mode
./build.sh release
- Execute the program
./run debug
or if you built in release mode
./run release
A* is an informed search algorithm that finds the shortest path between a source vertex and a destination
vertex in a weighted graph. It does this by maintaining a tree of paths originating at the start node
and extending those paths one edge at a time until the goal node is reached.
At each iteration of the search, A* holds a cost map of all visited nodes that is calculated by the
formula
where
-
$g(n)$ is the cost of the path from the start node to node n -
$h(n)$ is the heuristic function that approximates how close node n is to the destination node -
$f(n)$ is the total cost of node n that is used to determine if a node is worthwhile to visit.
This implementation of A* uses a priority queue to store the neighbors of the current cell with the
priority of their cost. Since cost must be minimized, the cells with low cost are prioritized over cells
with higher cost.
The heuristic function
For a graph where diagonal traversal is allowed, Euclidean distance is used as a heuristic which is given by
where
The time complexity of A* is given by