Unit 1 AI Part-3 Searchtechniques
Unit 1 AI Part-3 Searchtechniques
(0,0) 🡪 (5,0) 🡪
(5,3)🡪(0,3)🡪(3,0)🡪(3,3)🡪(5,1)🡪(0,1)🡪(1,0)🡪(1,3) 🡪
(4,0)
Comparisons
• BFS is effective when search tree has low branching factor
• DFS is best when goal exist in the lower left portion of the tree.
GOAL is chosen.
Heuristic Search Techniques
Heuristics
✔ A heuristic is a method that improves the efficiency of the
search process.
✔ Some heuristics help in the search process without
sacrificing any claims and occasionally cause an excellent
path to be overlooked.
✔ Heuristics may not find the best solution every time but
guarantee that they find a good solution in a reasonable
time.
✔ These are particularly useful in solving tough and complex
problems, solutions of which would require infinite time.
Heuristic search
‘A heuristic function maps a problem state descriptions to a measures of
desirability(represented as numbers).
Heuristic search methods use knowledge about the problem domain,
choose promising operators and heuristic functions to evaluate the next
state towards the goal state.
For finding a solution, steps involved:
✔ Add domain—specific information to select what is the best path to
continue searching along.
✔ Define a heuristic function h(n) that estimates the ‘goodness’ of a
node. Specifically, h(n) = estimated cost(or distance) of minimal cost
path from n to a goal state.
Example :
❖ Finding a route from one city to another city.
Heuristic search techniques
• A framework for describing search methods is
provided and several general purpose
search techniques are discussed.
• All are varieties of Heuristic Search:
– Generate and test
– Hill Climbing
– Best First Search
– A* Algorithm
Generate-and-Test
Algorithm
1. Generate a possible solution.
2. Test to see if this is actually a solution.
3. Quit if a solution has been found.
Otherwise, return to step 1.
17
Generate-and-Test
18
Generate-and-Test
• Exhaustive generate-and-test.
• Heuristic generate-and-test: not consider paths that
seem unlikely to lead to a solution.
• Plan generate-test:
C−reate a list of candidates.
A−pply generate-and-test to that list.
19
Generate-and-Test
Example: coloured blocks
“Arrange four 6-sided cubes in a row, with each side of
each cube painted one of four colours, such that on all
four sides of the row one block face of each colour is
showing.”
Heuristic: if there are more red faces than other colours
then, when placing a block with several red faces, use few
of them as possible as outside faces.
20
Generate-and-Test
It is a depth first search procedure since complete
solutions must be generated before they can be tested.
In its most systematic form, it is simply an exhaustive
search of the problem space.
Operate by generating solutions randomly. Also
called as British Museum algorithm
22
Simple Hill Climbing
Algorithm
Input: START & GOAL states
Variables: OPEN, NODE, SUCCs, FOUND
Output: Yes / No
Method:
• Store initially the start node in a OPEN list(maintained as stack),
FOUND=False
• While ( OPEN≠empty and FOUND=false)
{
remove the top element from OPEN list and call it
NODE
if NODE is goal then FOUND = true
else
find SUCCs of NODE. If any:
sort SUCCs by estimated cost from NODE to goal state and
add them to the front of OPEN list.
}
If FOUND= true then return Yes otherwise NO 23
Simple Hill Climbing
24
General trace of heuristic function
Hill Climbing : Issues
26
Hill Climbing: Disadvantages
Local maximum
A state that is better than all of its neighbours, but not
better than some other states far away.
27
Hill Climbing: Disadvantages
Plateau
A flat area of the search space in which all neighbouring
states have the same value.
28
Hill Climbing: Disadvantages
Ridge
The orientation of the high region, compared to the
set of available moves, makes it impossible to climb
up.
However, two moves executed serially may increase
the height.
29
Hill Climbing: Disadvantages
Ways to overcome
• Backtrack to some earlier node and try going in a
different direction.
• Make a big jump to try to get in a new section.
• Moving in several directions at once.
30
Hill Climbing: Disadvantages
31
Hill Climbing: Disadvantages
Start Goal
A D
D C
C B
B A
Blocks World
32
Hill Climbing: Disadvantages
Start Goal
A D
0 4
D C
C B
B A
Blocks World
Local heuristic:
+1 for each block that is resting on the thing it is supposed to
be resting on.
−1 for each block that is resting on a wrong thing.
33
Hill Climbing: Disadvantages
0 A 2
D D
C C
B B A
34
Hill Climbing: Disadvantages
D 2
C
B A
A 0
D 0
C C D C 0
B B A B A D
35
Hill Climbing: Disadvantages
Start Goal
A D
−6 6
D C
C B
B A
Blocks World
Global heuristic:
For each block that has the correct support structure: +1 to
every block in the support structure.
For each block that has a wrong support structure: −1 to
every block in the support structure. 24
Hill Climbing: Disadvantages
D −
3
C
B A
A −6
D −2
C C D C −1
B B A B A D
37
Hill Climbing: Conclusion
38
A* Algorithm
Initialize the open list with the starting node, and set its
g(n) and h(n) values accordingly.
h(Start_state)=1+0+1+0+1+0+2+0=5
Optimal Solution by A* Algorithm
A* algorithm finds Optimal solution if heuristic function is carefully
designed and is underestimated.
MONOTONIC FUNCTION
A heuristic function h is monotone if
2.h(Goal)=0
Each monotonic heuristic function is admissible.