A star search algorithm
lastmod 2024-07-15created 2015-11-066 edits
In computer science, the A* algorithm (A* algorithm, pronounced "A-star algorithm") is one of the graph/tree search algorithms that finds the shortest path from a given start vertex to a goal vertex (in other words, one that passes a test able to determine that a path is the shortest path to the given goal vertex).
It is a pathfinding algorithm built by extending Dijkstra's algorithm. It is read as "A-star algorithm".
Principle
The most basic formula is as follows.
It works as follows.
- Insert the node into an ascending priority queue by f(x).
- Pop the priority queue.
- Find the nodes reachable from that node.
- Compute f(x) for those nodes.
- Insert those nodes into the priority queue.
- Repeat until the goal node is reached.
The pseudocode is as follows.
PQ.push(start_node, g(start_node) + h(start_node)) //우선순위 큐에 시작 노드를 삽입한다.
while PQ is not empty //우선순위 큐가 비어있지 않은 동안
node = PQ.pop //우선순위 큐를 pop한다.
if node == goal_node //만일 해당 노드가 목표 노드이면 반복문을 빠져나온다.
break
for next_node in (next_node_begin...next_node_end) //해당 노드에서 이동할 수 있는 다음 노드들을 보는 동안
PQ.push(next_node, g(node) + cost + h(next_node)) //우선순위 큐에 다음 노드를 삽입한다.
print goal_node_dist //시작 노드에서 목표 노드까지의 거리를 출력한다.
See also
Favorite site
- Wikipedia (en) Description of the A* algorithm
- A* algorithm for beginners (basic concepts and source) 1
- Definition and concepts of the A*(A star) algorithm
- [Recommended] Shortest path search – A* algorithm – GIS Developer
References
-
Astar-algorithm_basic.pdf ↩