As Tar Search

download As Tar Search

of 20

Transcript of As Tar Search

  • 8/6/2019 As Tar Search

    1/20

    Submitted By Md. Wasim Akram

    ID- UG 02-22-09-016

  • 8/6/2019 As Tar Search

    2/20

    A* Search Algorithm

    What is A*?

    A* is one of the many search algorithms thattakes an input, evaluates a number of

    possible paths and returns a solution

    The goal of this presentation is to providebackground information, details and an

    example to demonstrate A* search

  • 8/6/2019 As Tar Search

    3/20

    What is A* Search Good For?

    If there is solution A* will find it, which makesthis search algorithm complete

    Similar to greedy best-first search but ismore accurate because A* takes intoaccount the nodes that have already beentraversed

    (Best-first search is a search algorithmwhich explores a graph by expanding themost promising node chosen according to aspecified rule)

  • 8/6/2019 As Tar Search

    4/20

    Path Scoring: How to Calculate the

    Path Cost

    A* figures the least-cost path to the node whichmakes it a best first search algorithm.

    Uses the formula F(x)=g(x)+h(x) G(x) is the total distance from the initial position to

    the current position. H(x) is the heuristic function that is used to

    approximate distance from the current location tothe 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 thegoal state is reach and with much more accuracy.

    F(x) = g(x)+h(x) this is the current approximationof the shortest path to the goal.

  • 8/6/2019 As Tar Search

    5/20

    The Open List (Priority Queue) and

    the Closed List

    When starting at the initial node this searchkeeps track of the nodes to be traversed. This is known as the open set and it keeps track of

    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 areupdated.

    This search continues until it reaches the nodewith the lowest f(x) value, which is called the goal

    node. H(x) at the goal is zero which is an admissibleheuristic because the path to the goal is clearlynot an overestimate.

  • 8/6/2019 As Tar Search

    6/20

    The Open and Closed List (contd)

    If the heuristic function hneveroverestimates the minimum cost ofreaching the goal, also known as being

    admissible, then A* is also known to beadmissible.

  • 8/6/2019 As Tar Search

    7/20

    Example Using A* Search

    Here we are using Disneyland Paris toprovide an example to traverse nodes froman initial state to a goal state.

    The main entrance is the initial node

    The Magic Kingdom is the goal state

    There are two paths that can be taken and aremarked by nodes

    Each node will have the f(x), g(x), and h(x).

    Then it will show at each node and indicatewhich is the next node that it will traversebased on least path cost.

  • 8/6/2019 As Tar Search

    8/20

    Disneyland Paris

    Say you are at the entrance ofDisneyland Paris and you are trying toget to the Magic Kingdom.

    There are two distinct paths that overlapin the center.

    Using A* I will demonstrate how the

    algorithm traverses nodes and reachesthe final destination.

  • 8/6/2019 As Tar Search

    9/20

    As you can see the initial node and the goal state are labeled accordingly.

  • 8/6/2019 As Tar Search

    10/20

    The first path is highlighted in with green nodes.

  • 8/6/2019 As Tar Search

    11/20

    The second path is illustrated with purple nodes and overlaps with the firstpath

  • 8/6/2019 As Tar Search

    12/20

    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 arenot 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.

  • 8/6/2019 As Tar Search

    13/20

    The first node traversed is the one with the lowest f(x) value

  • 8/6/2019 As Tar Search

    14/20

    The only option is the purple node where F(x)=80

  • 8/6/2019 As Tar Search

    15/20

    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)

  • 8/6/2019 As Tar Search

    16/20

    Finally we see that A* found the node with the smallest f(x) value. When thegoal node is popped off the priority queue then the search stops.

  • 8/6/2019 As Tar Search

    17/20

    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 emptyx := the node in openset having the lowest f_score[] value

    if x = goalreturn reconstruct_path(came_from, came_from[goal])

  • 8/6/2019 As Tar Search

    18/20

    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

  • 8/6/2019 As Tar Search

    19/20

    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 ispolynomial 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 fasterthan the logarithm of the perfect heuristic h * that returns

    the true distance from x to the goal

  • 8/6/2019 As Tar Search

    20/20

    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 ModernApproach (Second Edition) pp 97-101

    Wikipedia.com