Unit 2b InformedSearchAndCSP
Unit 2b InformedSearchAndCSP
TECHNIQUES:
Heuristic Search
Heuristic Search Techniques
• Direct techniques (blind search) are not
always possible (they require too much time
or memory).
1 2 3 1 2 3
7 8 4 8 4
6 5 7 6 5
1 2 3 GOAL 1 23
8 4 7 84
7 6 5 6 5
right
1 23 1 23 123
7 84 7 84 7 4
6 5 6 5 6 85
right
1 23 1 23 123
7 84 7 84 7 4
6 5 6 5 6 85
h=2 h=4 h=3
Another 8-puzzle heuristic
• Count how far away (how many tile
movements) each tile is from it’s correct
position.
• Sum up this count over all the tiles.
• This is another estimate on the number of
moves away from a solution.
1 2 3 GOAL 1 23
8 4 7 84
7 6 5 6 5
right
1 23 1 23 123
7 84 7 84 7 4
6 5 6 5 6 85
h=2 h=4 h=4
Techniques
• There are a variety of search techniques that
rely on the estimate provided by a heuristic
function.
• In all cases - the quality (accuracy) of the
heuristic is important in real-life application
of the technique!
Hill Climbing
• Variation of generate-and-test approach:
– generation of next state depends on feedback from the
test procedure.
– Test now includes a heuristic function that provides a
guess as to how good each possible state is.
• There are a number of ways to use the information
returned by the test procedure.
• Searching for a goal state = Climbing to the top of
a hill
Simple Hill Climbing
• Use heuristic to move only to states that are
better than the current state.
15
Simple Hill Climbing
Function Optimization
y = f(x)
y
x
Potential Problems with
Simple Hill Climbing
• Will terminate when at local optimum.
20
Hill Climbing: Disadvantages
Plateau
A flat area of the search space in which all
neighbouring states have the same value.
21
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.
22
Hill Climbing: Disadvantages
Ways Out
24
Hill Climbing: Disadvantages
(Example)
Start Goal
A D
D C
C B
B A
Blocks World
25
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.
26
Hill Climbing: Disadvantages
0 A 2
D D
C C
B B A
27
Hill Climbing: Disadvantages
D 2
C
B A
A 0
0
D
C C D C 0
B B A B A D
28
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
29 structure.
Hill Climbing: Disadvantages
D -3
C
B A
A -6
-2
D
C C D C -1
B B A B A D
30
Hill Climbing: Conclusion
• Can be very inefficient in a large, rough
problem space.
B C D B C D
3 5 1 3 5
E F
4 6
A A
B C D B C D
5 5
G H E F G H E F
6 5 4 6 6 5 6
I J
2 1
35
Best-First Search
• OPEN: nodes that have been generated, but
have not examined.
This is organized as a priority queue.
38
Best-First Search
• Greedy search:
h(n) = estimated cost of the cheapest path
from node n to a goal state.
Neither optimal nor complete
• Uniform-cost search:
g(n) = cost of the cheapest path from the
initial state to node n.
Optimal and complete, but very inefficient
Example: City with straight-line dist.
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
GBFS is not complete
c
b g
a goal state
start state
• h1(S) = ?
• h2(S) = ?
Admissible heuristics
E.g., for the 8-puzzle:
• h1(n) = number of misplaced tiles
• h2(n) = total Manhattan distance
(i.e., no. of squares from desired location of each tile)
• h1(S) = ? 8
• h2(S) = ? 3+1+2+2+2+3+3+2 = 18
The average solution cost for a randomly generated 8-puzzle instance is about
22 steps. The branching factor is about 3.
Dominance
• If h2(n) ≥ h1(n) for all n (both admissible)
• then h2 dominates h1
• h2 is better for search: it is guaranteed to expand
less or equal no. of nodes.
Cryptarithmetic puzzle:
SEND
MORE
MONEY
57
Constraint Satisfaction
• As compared with a straightforard search procedure,
viewing a problem as one of constraint satisfaction
can reduce substantially the amount of search.
SEND
+ MOR E
----------
MONEY
Variables: S, E, N, D, M, O, R, Y Soln.:95
67
Domains: 1085
[0..9] for S, M, E, N, D, O, R, Y
====
Search space: 1,814,400 10652
Aside: could have [1..9] for S and M
Constraints
Option 1:
C1a) 1000 S + 100 E + 10 N + D +
1000 M + 100 O + 10 R + E
= 10000 M + 1000 O + 100 N + 10 E + Y SEND
Or use 5 equality constraints, using auxiliary +MORE
“carry” variables C1, …, C4 Є [0…9] ----------
Option 2: C1b) MONEY
D+E = 10 C1 + Y Which constraint set better
C1 + N + R = 10 C2 + E for solving? C1a or C1b? Why?
C2 + E + O = 10 C3 + N
C3 + S + M = 10 C4 + O C1b, more “factored”. Smaller
C4 =M pieces. Gives more propagation!