Unit-2 Heuristic Search Techniques
Unit-2 Heuristic Search Techniques
UNIT-II:
Heuristic Search Techniques
Algorithm
1. Generate a possible solution. For example,
generating a particular point in the problem
space or generating a path for a start state.
2. Test to see if this is a actual solution by
comparing the chosen point or the endpoint
of the chosen path to the set of acceptable
goal states
3. If a solution is found, quit. Otherwise go to
Step 1
Hill Climbing
• Step 1: Evaluate the initial state, if it is goal state then return success and stop,
else make current state as initial state.
• Step 2: Loop until a solution is found or the current state does not change.
– Let SUCC be a state such that any successor of the current state will be better
than it.
– For each operator that applies to the current state:
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to the SUCC.
• If it is better than SUCC, then set new state as SUCC.
• If the SUCC is better than the current state, then set current state to
SUCC.
• Step 5: Exit.
Stochastic hill climbing:
• Stochastic hill climbing does not examine for all its
neighbour before moving. Rather, this search algorithm
selects one neighbour node at random and decides
whether to choose it as a current state or examine
another state.
Best First Search (Informed Search)
Algorithm:
Best-First-Search(Graph g, Node start)
• Create an empty PriorityQueue pq;
• pq.insert(start) // Insert "start" in pq
• While PriorityQueue is not empty do
– u = PriorityQueue.DeleteMin
– if u is the goal state, then Exit
– Else
– For each neighbour v of u
• If v "Unvisited“ then Mark v "Visited"
• pq.insert(v)
– Mark v "Examined"
• End procedure
A General Example
Best-first search
• use an evaluation function f(n) for each node
– f(n) provides an estimate for the total cost
– Expand the node n with smallest f(n).
Start node: Arad
Goal node: Bucharest
Total distance covered:
140+99+211=450
• Complete
– No, GBFS can get stuck in loops (e.g. bouncing back and
forth between cities)
• Time
– O(bm) but a good heuristic can have dramatic improvement
• Space
– O(bm) – keeps all the nodes in memory
• Optimal
– No!
A* Search
• A* (A star) is the most widely known form of Best-First
search
– It evaluates nodes by combining g(n) and h(n)
– f(n) = g(n) + h(n)
– Where
• g(n) = the actual cost to get from the initial node to
node n.
• h(n) = Heuristic cost (also known as "estimation
cost") from node n to destination node n.
1. Create an open list of found but not explored nodes, initially empty.
2. Create a closed list to hold already explored nodes, initially empty.
3. Add a starting node to the open list with an initial value of g
4. While the open list is not empty do
a. find the node with the least value of f() on the open list, call it „q‟
b. Remove „q‟ from the open list
c. generate q's successors and set their parents to q
d. for each successor
i. if successor is the goal state, then stop search
ii. else, compute g(), h(), and f() for successor
iii. if a node with the same level as successor is in the OPEN list
which has a lower f than successor, skip this successor
iv. else if a node with the same level as successor is in the CLOSED
list which has a lower f than successor, skip this successor
v. else, add the node to the open list
e. Insert q on to the closed list
140 75
118
140
75
118
140
99 80
151
140
75
118
80
140 99 151
146
97 80
140 118
75
80
140 99 151
99 146 97
211 80
140 99 80
151
80
99 146 97
211
Skipped
101 138 97
• Complete
– Yes
• Time
– Exponential
– The better the heuristic, the better the time
• Best case h is perfect, O(d)
• Worst case h = 0, O(bd) same as BFS
• Space
– Keeps all nodes in memory and save in case of repetition
– This is O(bd) or worse
– A* usually runs out of space before it runs out of time
• Optimal
– Yes
Problem Reduction
• If we are looking for a sequence of actions to achieve some
goal, then one way to do it is to use state-space search,
where each node in you search space is a state of the world,
and you are searching for a sequence of actions that get you
from an initial state to a final state.
• Another way is to consider the different ways that the goal
state can be decomposed into simpler sub-goals.
• If we can discover how to get from a given node to a goal
state along any one of the branches leaving it.
• To represent problem reduction techniques we need to use
an AND-OR graph/tree.
• Problem reduction technique using AND-OR graph is useful
for representing a solution of a problems that can be solved
by decomposing them into a set of smaller problems all of
which must be solved.
• This decomposition or reduction generates arcs that we call
AND arcs.
• One AND arc may point to any numbers of successor nodes.
• All of which must then be solved in order for the arc to point
solution.
• In order to find solution in an AND-OR graph we need an
algorithm similar to best-first search but with the ability to
handle the AND arcs appropriately.
• We define FUTILITY, if the estimated cost of solution
becomes greater than the value of FUTILITY then we
abandon the search, FUTILITY should be chosen to
correspond to a threshold.
A
9 A
38
B C D
B C D 27
3 4 17 9
5
• initial guess m=1 because the sum of two single digits can
generate at most a carry '1'.
• When n=1 o=0 or 1 because the largest single digit number
added to m=1 can generate the sum of either 0 or 1
depend on the carry received from the carry sum. By this
we conclude that o=0 because m is already 1 hence we
cannot assign same digit another letter(rule no.)
• We have m=1 and o=0 to get o=0 we have s=8 or 9, again
depending on the carry received from the earlier sum.
Means-Ends Analysis
• Most of the search strategies either reason forward of backward
however, often a mixture of the two directions is appropriate.
• Such mixed strategy would make it possible to solve the major
parts of problem first and solve the smaller problems that arise
when combining them together.
• Such a technique is called "Means - Ends Analysis".
• The means-ends analysis process centers around finding the
difference between current state and goal state. The problem space
of means - ends analysis has an initial state and one or more goal
state, a set of operate with a set of preconditions their application
and difference functions that computes the difference between two
state a(i) and s(j). A problem is solved using means – ends analysis
by
Algorithm for Means-Ends Analysis:
• Let's take a Current state as CURRENT and Goal State as GOAL, then
following are the steps for the MEA algorithm.
• Step 1: Compare CURRENT to GOAL, if there are no differences
between both then return Success and Exit.
• Step 2: Else, select the most significant difference and reduce it by doing
the following steps until the success or failure occurs.
– Select a new operator O which is applicable for the current difference,
and if there is no such operator, then signal failure.
– Attempt to apply operator O to CURRENT. Make a description of two
states.
i) O-Start, a state in which O?s preconditions are satisfied.
ii) O-Result, the state that would result if O were applied In O-start.
– If
(First-Part <------ MEA (CURRENT, O-START)
And
(LAST-Part <----- MEA (O-Result, GOAL), are successful, then signal
Success and return the result of combining FIRST-PART, O, and
LAST-PART.
Example of Mean-Ends Analysis:
Solution:
To solve the above problem, we will first find the differences
between initial states and goal states, and for each
difference, we will generate a new state and will apply the
operators. The operators we have for this problem are:
Move
Delete
Expand
1. Evaluating the initial state: 2. Applying Delete operator