0% found this document useful (0 votes)
52 views62 pages

Best First Search A Star

The document discusses heuristic search techniques. It describes that heuristics help guide search algorithms to be more efficient by providing problem-specific knowledge to direct the search. The A* algorithm is described as using both cost and heuristic functions to estimate the cost to reach the goal state, making it optimal. A* maintains OPEN and CLOSED lists to track nodes, expanding the lowest cost node first. It is complete and optimal for finite search spaces but can be computationally expensive.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views62 pages

Best First Search A Star

The document discusses heuristic search techniques. It describes that heuristics help guide search algorithms to be more efficient by providing problem-specific knowledge to direct the search. The A* algorithm is described as using both cost and heuristic functions to estimate the cost to reach the goal state, making it optimal. A* maintains OPEN and CLOSED lists to track nodes, expanding the lowest cost node first. It is complete and optimal for finite search spaces but can be computationally expensive.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Heuristic Search

Techniques
Harshita Sharma
What is Heuristic Search?
• Heuristic is a technique which makes our search algorithm more efficient.
• Some heuristics help to guide a search process without sacrificing any claim to
completeness and some sacrificing it.
• Heuristic is a problem specific knowledge that decreases expected search efforts.
• It is a technique which sometimes works but not always.
• Heuristic search algorithm uses information about the problem to help directing the
path through the search space.
• These searches uses some functions that estimate the cost from the current state to
the goal presuming that such function is efficient.
• A heuristic function is a function that maps from problem state descriptions to
measure of desirability usually represented as number.
• The purpose of heuristic function is to guide the search process in the most
profitable directions by suggesting which path to follow first when more than is
available.
• Generally heuristic incorporates domain knowledge to improve efficiency over blind
search.
• In AI heuristic has a general meaning and also a more specialized technical meaning.
• Generally a term heuristic is used for any advice that is effective but is not
guaranteed to work in every case.
• Heuristic is a method that provides a better guess about the correct choice to make
at any junction that would be achieved by random guessing.
• This technique is useful in solving tough problems which could not be solved in any
other way, those whose solutions take an infinite time to compute.
Heuristic Strategies
Simple Techniques
• Hill Climbing
• Simple
• Steepest Ascent
• Problems
• Simulated Annealing

(All already discussed in class)


Improved Techniques
• Best First Search
• OR graphs
• A* algorithm
• Problem Reduction
• AND-OR graphs
• AO* algorithm
• Constraint Satisfaction
• Means-ends Analysis
BEST FIRST SEARCH
Introduction
• Combines the advantages of breadth first search and depth first search.
• DFS is good as it allows a solution to be found without all competing branches
having to be expanded at all levels.
• BFS is good because it does not get trapped on dead-end paths.
• In BFS and DFS, when we are at a node, we can consider any of the adjacent as
next node. So both BFS and DFS blindly explore paths without considering any
cost function. The idea of Best First Search is to use an evaluation function to
decide which adjacent is most promising and then explore.
• The best first search allows us to switch between paths thus gaining the
benefit of both approaches.
• At each step the most promising node is chosen.
• If one of the nodes chosen generates nodes that are less promising it is
possible to choose another at the same level and in effect the search changes
from depth to breadth.
• If on analysis these are no better than this previously unexpanded node and
branch is not forgotten and the search method reverts to the
• Best first search is an instance of graph search algorithm in which a node is selected for
expansion based o evaluation function f (n).
• Traditionally, the node which is the lowest evaluation is selected for the explanation because
the evaluation measures distance to the goal.
• Best first search can be implemented within general search frame work via a priority queue, a
data structure that will maintain the fringe in ascending order of f values.
• This search algorithm serves as combination of depth first and breadth first search
algorithm.
• Best first search algorithm is often referred greedy algorithm this is because they quickly
attack the most desirable path as soon as its heuristic weight becomes the most desirable
OR Graphs
• Best first search works on the type of problems that can be represented in
the form of OR graphs.
• An OR graph is a graph whose various branches represents an alternative
problem solving path.
• We can choose either one path OR another path OR another path to reach
our goal.
Implementation
Done by using two lists of nodes:
• OPEN
OPEN is a priority queue of nodes that have been evaluated by the heuristic function
but which have not yet been expanded into successors. The most promising nodes are
at the front.
• CLOSED
CLOSED are nodes that have already been generated and these nodes must be stored
because a graph is being used in preference to a tree.
Example
Example
Example
Example
Example
Algorithm
1. Start with OPEN holding the initial state
2. Until a goal is found or there are no nodes left on open do.
• Pick the best node on OPEN
• Generate its successors
• For each successor Do
• If it has not been generated before ,evaluate it ,add it to OPEN and record its parent
• If it has been generated before change the parent if this new path is better and in that case update
the cost of getting to any successor nodes.
3. If a goal is found or no more nodes left in OPEN, quit, else return to 2.
Disadvantages
1. It is not optimal.
2. It is incomplete because it can start down an infinite path and never return to
try other possibilities.
3. The worst-case time complexity for greedy search is O (bm ), where m is the
maximum depth of the search space.
4. Because greedy search retains all nodes in memory, its space complexity is
the same as its time complexity
Question
• Taking the example of Route-finding problems in Romania, the goal is to
reach Bucharest starting from the city Arad.
Solution
The A* Algorithm
• The Best First algorithm is a simplified form of the A* algorithm.
• The A* search algorithm (pronounced "Ay-star") is a tree search algorithm that
finds a path from a given initial node to a given goal node (or one passing a given
goal test).
• It employs a "heuristic estimate" which ranks each node by an estimate of the best
route that goes through that node.
• It visits the nodes in order of this heuristic estimate.
• Similar to greedy best-first search but is more accurate because A* takes into
account the nodes that have already been traversed.
• A* search finds the shortest path through a search space to goal state using
heuristic function.
• This technique finds minimal cost solutions and is directed to a goal state
called A* search.
• In A*, the * is written for optimality purpose. The A* algorithm also finds
the lowest cost path between the start and goal state, where changing from
one state to another requires some cost.
• A* requires heuristic function to evaluate the cost of path that passes
through the particular state.
• This algorithm is complete if the branching factor is finite and every action
has fixed cost.
• A* requires heuristic function to evaluate the cost of path that passes
through the particular state. It can be defined by following formula.
Heuristic used
For implementation
• For the implementation of A* algorithm we will use two lists namely OPEN
and CLOSED.
• OPEN: A list which contains the nodes that has been generated but has not
been yet examined.
• CLOSED: A list which contains the nodes that have been examined.
Description
• A* begins at a selected node. Applied to this node is the "cost" of entering this
node (usually zero for the initial node). A* then estimates the distance to the goal
node from the current node. This estimate and the cost added together are the
heuristic which is assigned to the path leading to this node. The node is then added
to a priority queue, often called "open".
• The algorithm then removes the next node from the priority queue (because of the
way a priority queue works, the node removed will have the lowest heuristic). If the
queue is empty, there is no path from the initial node to the goal node and the
algorithm stops. If the node is the goal node, A* constructs and outputs the
successful path and stops.
• If the node is not the goal node, new nodes are created for all admissible adjoining
nodes; the exact way of doing this depends on the problem at hand. For each
successive node, A* calculates the "cost" of entering the node and saves it with the
node. This cost is calculated from the cumulative sum of costs stored with its
ancestors, plus the cost of the operation which reached this new node.
• The algorithm also maintains a 'closed' list of nodes whose adjoining nodes have
been checked. If a newly generated node is already in this list with an equal or lower
cost, no further processing is done on that node or with the path associated with it.
If a node in the closed list matches the new one, but has been stored with a higher
cost, it is removed from the closed list, and processing continues on the new node
• Next, an estimate of the new node's distance to the goal is added to the cost
to form the heuristic for that node. This is then added to the 'open' priority
queue, unless an identical node is found there.
• Once the above three steps have been repeated for each new adjoining node,
the original node taken from the priority queue is added to the 'closed' list.
The next node is then popped from the priority queue and the process is
repeated
Algorithm
Advantages
• It is complete and optimal.
• It is the best one from other techniques.
• It is used to solve very complex problems.
• It is optimally efficient, i.e. there is no other optimal algorithm guaranteed to
expand fewer nodes than A*.
Disadvantages
• This algorithm is complete if the branching factor is finite and every action
has fixed cost.
• The speed execution of A* search is highly dependant on the accuracy of
the heuristic algorithm that is used to compute h (n).
• It has complexity problems.
The g function in A*
• g is a measure of how good a path is.
• Useful for solutions where we want to find the cheapest path.
• For problems where the path cost is not of any concern, search can be guided solely
by h, i.e. set g=0 always
• If a path with shortest no. of steps is required, set cost of each branch =1.
• If cheapest path is required and some operators cost more than others, individual
branches will have varying costs.
• Thus A* is useful to find both any path solutions as well as minimal path cost
solutions.
The h (heuristic) function in A*
• h represents the distance of a node to the goal.
• It is an estimate only, often represented by h` where the ` represents that this is not an exact
cost, but an estimation.
• It represents how good the node itself is.
• h can be either a perfect estimate, an underestimate or an overestimate.
• If h is always set to 0, the search is controlled by g.
• If both h and g are set to 0, it will be a random search.
• If h=0 and g=1, it reduces to breadth first search. All nodes on a lower level will have lower
g (and hence f) values and thus will get expanded before nodes on the next level.
The h (heuristic) function in A*
The case when h` underestimates h
• Wastes some effort.
The case when h` overestimates h
Admissibility
• The algorithm A* is admissible.
• This means that provided a solution exists, the first solution found by A* is an optimal
solution.
• A* is admissible under the following conditions: Heuristic function: for every node n
, h(n) ≤ h*(n) .
• A* is also complete.
• A* is optimally efficient for a given heuristic.
• A* is much more efficient that uninformed search.
Graceful decay of admissibility
• If h' rarely overestimates h by more than d then the A* algorithm will rarely
find a solution whose cost is d greater than the optimal solution.
• Most practical
Question – Apply A* to the Route problem
END

You might also like