3. WHAT IS A HEURISTIC SEARCH?
• A Heuristic is a technique to solve a problem faster than classic
methods, or to find an approximate solution when classic methods
cannot.
• A Heuristic (or a heuristic function) takes a look at search algorithms. At
each branching step, it evaluates the available information and makes a
decision on which branch to follow.
• It does so by ranking alternatives. The Heuristic is any device that is
often effective but will not guarantee work in every case.
• This is a kind of a shortcut as we often trade one of optimality,
completeness, accuracy, or precision for speed. 2/7/2023 3
5. WHY DO WE NEED HEURISTICS?
• To produce a solution , in a reasonable amount of time. It
doesn’t have to be the best- an approximate solution will do
since this is fast enough.
• Reduce the polynomial number for most problems that are
exponential. And in situations where we can’t find known
algorithms.
• Heuristic Techniques may be weak methods because they
are vulnerable to combinatorial explosion. 2/7/2023 5
6. • Other names for these are Blind Search, Uninformed Search, and
Blind Control Strategy.
• These aren’t always possible since they demand much time or
memory.
• They search the entire state space for a solution and use an arbitrary
ordering of operations.
• Examples of these are Breadth First Search (BFS) and Depth First
Search (DFS).
DIRECT HEURISTIC SEARCH TECHNIQUES IN AI
2/7/2023 6
7. WEAK HEURISTIC SEARCH TECHNIQUES IN AI
• Other names for these are Informed Search, Heuristic Search, and
Heuristic Control Strategy.
• These are effective if applied correctly to the right types of tasks and
usually demand domain-specific information.
• Examples are Best First Search (BFS) and A*.
• Best-First Search
• A* Search
• Bidirectional Search
• Tabu Search
• Beam Search
• Simulated Annealing
• Hill Climbing
• Constraint Satisfaction Problems
2/7/2023 7
9. HILL CLIMBING – ANOTHER EXAMPLE
• Problem: You have just arrived in Washington, D.C. You’re in your car, trying to get
downtown to the Washington Monument.
2/7/2023 9
10. FEATURES OF HILL CLIMBING IN AI
• Generate and Test variant: Hill Climbing is the variant of
Generate and Test method. The Generate and Test method
produce feedback which helps to decide which direction to
move in the search space.
• Greedy approach: Hill-climbing algorithm search moves in
the direction which optimizes the cost.
• No backtracking: It does not backtrack the search space, as it
does not remember the previous states.
2/7/2023 10
11. PROBLEMS WITH HILL CLIMBING IN AI
Three issues Addressed
• Local Maximum- All neighboring states have values worse than the current. The
greedy approach means we won’t be moving to a worse state. This terminates the
process even though there may have been a better solution. As a workaround, we
use backtracking.
• Plateau- All neighbors to it have the same value. This makes it impossible to choose
a direction. To avoid this, we randomly make a big jump.
• Ridge- At a ridge, movement in all possible directions is downward. This makes it
look like a peak and terminates the process. To avoid this, we may use two or more
rules before testing.
2/7/2023 11
13. GENERATE AND TEST SEARCH
• Is a heuristic search technique based on Depth First Search with Backtracking
which guarantees to find a solution if done systematically and there exists a
solution.
• In this technique, all the solutions are generated and tested for the best solution.
• It ensures that the best solution is checked against all possible generated solutions.
• It is also known as British Museum Search Algorithm as it’s like looking for an
exhibit at random or finding an object in the British Museum by wandering
randomly.
2/7/2023 13
14. GENERATE AND TEST SEARCH
Step:1 Generate a possible solution. For
example, generating a particular point in
the problem space or generating a path for
a start state.
Step:2Test 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
Step:3 If a solution is found, quit.
Otherwise go to Step 1
2/7/2023 14
16. SIMPLE HILL CLIMBING
• Examines one neighboring node at a time and selects the first one that optimizes the
current cost to be the next node.
• Algorithm:
1. Evaluate initial state- if goal state, stop and return success. Else, make initial state
current.
2. Loop until the solution reached or until no new operators left to apply to current
state:
a. Select new operator to apply to the current producing new state.
b. Evaluate new state:
• If a goal state, stop and return success.
• If better than the current state, make it current state, proceed.
• Even if not better than the current state, continue until the solution
reached.
3. Exit.
2/7/2023 16
17. FEATURES:
• Less time consuming
• Less optimal solution and the solution is not
guaranteed
2/7/2023 17
18. STEEPEST-ASCENT HILL CLIMBING:
• The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This
algorithm examines all the neighboring nodes of the current state and selects one
neighbor node which is closest to the goal state. This algorithm consumes more time
as it searches for multiple neighbors
2/7/2023 18
19. ALGORITHM FOR STEEPEST-ASCENT 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 3: Exit.
2/7/2023 19
20. ANNEALING
• Annealing is a thermal process for obtaining low energy
states of a solid in a heat bath.
• The process contains two steps:
• Increase the temperature of the heat bath to a maximum value at
which the solid melts.
• Decrease carefully the temperature of the heat bath until the
particles arrange themselves in the ground state of the solid.
Ground state is a minimum energy state of the solid.
• The ground state of the solid is obtained only if the
maximum temperature is high enough and the cooling is
done slowly.
2/7/2023 20
21. SIMULATED ANNEALING
• Simulated annealing maintains a current assignment of values to variables.
• At each step, it picks a variable at random, then picks a value at random. If
assigning that value to the variable is an improvement or does not increase the
number of conflicts, the algorithm accepts the assignment and there is a new
current assignment.
• Otherwise, it accepts the assignment with some probability, depending on the
temperature and how much worse it is than the current assignment. If the change is
not accepted, the current assignment is unchanged.
2/7/2023 21
22. • To control how many worsening steps are accepted, there is a positive real-valued
temperature T.
• Suppose A is the current assignment of a value to each variable. Suppose that h(A) is
the evaluation of assignment A to be minimized.
• For solving constraints, h is typically the number of conflicts. Simulated annealing
selects a neighbor at random, which gives a new assignment A'. If h(A') ≤ h(A), it
accepts the assignment and A' becomes the new assignment. Otherwise, the
assignment is only accepted randomly with probability
• e(h(A)-h(A'))/T.
• Thus, if h(A') is close to h(A), the assignment is more likely to be accepted. If the
temperature is high, the exponent will be close to zero, and so the probability will be
close to 1. As the temperature approaches zero, the exponent approaches -∞, and the
probability approaches zero.
2/7/2023 22
24. OR GRAPHS
• BFS uses the concept of a Priority queue and heuristic search.
• To search the graph space, the BFS method uses two lists for tracking
the traversal.
• An ‘Open’ list that keeps track of the current ‘immediate’ nodes
available for traversal and a ‘CLOSED’ list that keeps track of the
nodes already traversed.
2/7/2023 24
25. BEST FIRST SEARCH ALGORITHM
• Create 2 empty lists: OPEN and CLOSED
• Start from the initial node (say N) and put it in the ‘ordered’ OPEN list
• Repeat the next steps until the GOAL node is reached
• If the OPEN list is empty, then EXIT the loop returning ‘False’
• Select the first/top node (say N) in the OPEN list and move it to the CLOSED list. Also,
capture the information of the parent node
• If N is a GOAL node, then move the node to the Closed list and exit the loop returning ‘True’.
The solution can be found by backtracking the path
• If N is not the GOAL node, expand node N to generate the ‘immediate’ next nodes linked to
node N and add all those to the OPEN list
• Reorder the nodes in the OPEN list in ascending order according to an evaluation function f(n)
2/7/2023 25
27. ADVANTAGES AND DISADVANTAGES OF
BEST FIRST SEARCH
• Advantages:
1. Can switch between BFS and DFS, thus gaining the advantages of
both.
2. More efficient when compared to DFS.
• Disadvantages:
1. Chances of getting stuck in a loop are higher.
2/7/2023 27
28. A* SEARCH ALGORITHM
A* search is the most commonly known form of best-first search. It uses heuristic function h(n),
and cost to reach the node n from the start state g(n). It has combined features of UCS and
greedy best-first search, by which it solve the problem efficiently.
A* search algorithm finds the shortest path through the search space using the heuristic
function. This search algorithm expands less search tree and provides optimal result faster. A*
algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
In A* search algorithm, we use search heuristic as well as the cost to reach the node. Hence we
can combine both costs as following, and this sum is called as a fitness number.
Example
2/7/2023 28
29. ALGORITHM
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and
stops.
Step 3: Select the node from the OPEN list which has the smallest value of evaluation
function (g+h), if node n is goal node then return success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into the closed list.
For each successor n', check whether n' is already in the OPEN or CLOSED list, if not
then compute evaluation function for n' and place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the
back pointer which reflects the lowest g(n') value.
Step 6: Return to Step 2.
2/7/2023 29
30. Advantages:
• A* search algorithm is the best algorithm than other search algorithms.
• A* search algorithm is optimal and complete.
• This algorithm can solve very complex problems.
Disadvantages:
• It does not always produce the shortest path as it mostly based on heuristics and
approximation.
• A* search algorithm has some complexity issues.
• The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.
2/7/2023 30