Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A* Search Algorithm
What is A*?
A* is one of the many search algorithms that
more accurate because A* takes into account the nodes that have already been traversed (Best-first search is a search algorithm which explores a graph by expanding the most promising node chosen according to a specified rule)
the current position. H(x) is the heuristic function that is used to approximate distance from the current location to the goal state.
This function is distinct because it is a mere estimation
rather than an exact value. The more accurate the heuristic the better the faster the goal state is reach and with much more accuracy.
F(x) = g(x)+h(x) this is the current approximation
nodes in order of the lowest f(x) to the highest f(x). In order of priority each node is removed from the queue and then the values for f(x) and h(x) neighboring nodes around the removed node are updated. This search continues until it reaches the node with the lowest f(x) value, which is called the goal node. H(x) at the goal is zero which is an admissible heuristic because the path to the goal is clearly not an overestimate.
If the heuristic function h never overestimates the minimum cost of reaching the goal, also known as being admissible, then A* is also known to be admissible.
marked by nodes Each node will have the f(x), g(x), and h(x). Then it will show at each node and indicate which is the next node that it will traverse based on least path cost.
Disneyland Paris
Say you are at the entrance of Disneyland Paris and you are trying to get to the Magic Kingdom. There are two distinct paths that overlap in the center. Using A* I will demonstrate how the algorithm traverses nodes and reaches the final destination.
As you can see the initial node and the goal state are labeled accordingly.
The second path is illustrated with purple nodes and overlaps with the first path
In this stage all of the values are shown for f(x), g(x), & h(x). Note that in this example the heuristic is not monotonic and therefore we are not using a closed set to keep track of the nodes traversed. Since the closed set is not keeping track of the visited nodes the values of the neighboring nodes of the current node remain the same.
The first node traversed is the one with the lowest f(x) value
There are two options in this case: 1.The purple one with the higher F(x) 2.The green one with the lower F(x) As mentioned before A* will choose the one with the lowest F(x)
Finally we see that A* found the node with the smallest f(x) value. When the goal node is popped off the priority queue then the search stops.
Pseudocode
unction A*(start,goal) closedset := the empty set // The set of nodes already evaluated. openset := {start} // The set of tentative nodes to be evaluated, initially containing the start node came_from := the empty map // The map of navigated nodes.
g_score[start] := 0 // Cost from start along best known path. h_score[start] := heuristic_cost_estimate(start, goal) f_score[start] := h_score[start] // Estimated total cost from start to goal through y.
while openset is not empty x := the node in openset having the lowest f_score[] value if x = goal return reconstruct_path(came_from, came_from[goal])
remove x from openset add x to closedset foreach y in neighbor_nodes(x) if y in closedset continue tentative_g_score := g_score[x] + dist_between(x,y) if y not in openset add y to openset tentative_is_better := true else if tentative_g_score < g_score[y] tentative_is_better := true else tentative_is_better := false
if tentative_is_better = true came_from[y] := x g_score[y] := tentative_g_score h_score[y] := heuristic_cost_estimate(y, goal) f_score[y] := g_score[y] + h_score[y] return failure
function reconstruct_path(came_from, current_node) if came_from[current_node] is set p = reconstruct_path(came_from, came_from[current_node]) return (p + current_node) else return current_node
Complexity
The time complexity of A* depends on the heuristic. In the worst case, the number of nodes expanded is exponential in the length of the solution (the shortest path), but it is polynomial when the search space is a tree, there is a single goal state, and the heuristic function h meets the following condition: | h(x) h * (x) | = O(logh * (x))
where h * is the optimal heuristic, the exact cost to get from x to the goal. In other words, the error of h will not grow faster than the logarithm of the perfect heuristic h * that returns the true distance from x to the goal
Conclusion
Recap on A*:
Uses the formula f(x)=h(x)+g(x)
Traverses the node with the lowest f(x) value Very useful in searching for a goal state
References:
Book: Artificial Intelligence: A Modern