Professional Documents
Culture Documents
Heuristic (Informed)
Search
Search Algorithm #2
SEARCH#2
1. INSERT(initial-node,FRINGE)
2. Repeat:
a. If empty(FRINGE) then return failure
b. N REMOVE(FRINGE)
c. s STATE(N)
d. If GOAL?(s) then return path or goal state
e. For every state s in SUCCESSORS(s)
i. Create a node N as a successor of N
ii. INSERT(N,FRINGE)
(Wh
(Where
we try
t to
t choose
h
smartly)
tl )
R&N: Chap. 4, Sect. 4.13
Best-First Search
Best-First Search
How to construct f?
How to construct f?
Greedy best-search
Heuristic function
Heuristic Function
Other Examples
STATE(N)
Goal state
STATE(N)
Goal state
8-Puzzle
8-Puzzle
3
5
3+3
1+5
2+3
3+4
2
2
3
5+2
0+4
3+2
1+3
2+3
4
5
1+5
2+4
10
8-Puzzle
Robot Navigation
yN
6
2
5
2
4
yg
1
0
4
6
5+0
3+4
f(N) = h(N) =
4+1
h1 (N) =
5
11
xg
xN
(L2 or Euclidean distance)
12
(L1 or Manhattan distance)
Best-First Efficiency
Local-minimum problem
14
Admissible Heuristic
Admissible Heuristic
0 h(N) h*(N)
0 h(N) h*(N)
15
8-Puzzle Heuristics
5
16
8-Puzzle Heuristics
STATE(N)
Goal state
STATE(N)
17
Goal state
18
8-Puzzle Heuristics
5
8-Puzzle Heuristics
STATE(N)
Goal state
STATE(N)
19
Goal state
h1 (N) =
20
is admissible
21
22
23
A* Search
Result #1
26
Proof (1/2)
Proof (1/2)
27
28
Proof (1/2)
1) If a solution exists, A* terminates and
returns a solution
Proof (2/2)
2) Whenever A* chooses to expand a goal
node, the path to this node is optimal
- C*= cost of the optimal solution path
8-Puzzle
2+3
3+4
5+2
0+4
3+2
4+1
2+3
1+3
5+0
3+4
1+5
2+4
31
32
Robot Navigation
Robot Navigation
f(N) = h(N), with h(N) = Manhattan distance to the goal
(not A*)
8
6
5
6
7
6
5
4
5
33
34
Robot Navigation
Robot Navigation
6
77
8
00
6
7
8+3
6+3
8 7+4
7 6+5
6 5+6
5 4+7
4 3+8
3 2+9
2 3+10
3 4
7+2
7
6+1
6
7+0
7 6+1
6
8+1
8 7+2
7 6+3
6 5+4
5 4+5
4 3+6
3 2+7
2 3+8
3 4
35
5+6
5 4+7
4 3+8
3
3 2+9
2 1+10
1 0+11
0 1
6
5
4
5
5
6
36
Best-First Search
A* Search
1) f(N) = g(N) + h(N), where:
Result #1
38
h = 100
1
1
2
90
The heuristic h is
clearly admissible
100
0
39
c=1
h = 100
1
1
40
4+90
90
100
0
2+1
f = 1+100
100
1
1
2
90
2+1
1+100
2+90
4+90
102
104
100
104
But ...
But ...
1
1+1
1
1
2
1
1
2+1
2+1
2+1
2+1
2
2+1
2+1
2n+1 states
O(2n) nodes
44
h(N)
h(N)
Consistent Heuristic
Consistency Violation
(alternative definition)
h(N)
=10
2+1
(triangle inequality)
45
1+1
Consistent Heuristic
c(N,N)
=10
10
2+1
4
43
If h tells that N is
100 units from the
goal, then moving
from N along an arc
costing 10 units
should not lead to a
node N that h
estimates to be 10
units away from the
goal
1
1
2
4
1+1
1+1
h(N)
=100
(triangle inequality)
47
8-Puzzle
5
3
6
8
goal
STATE(N)
c(N,N)
h(N)
h(N)
h(N) c(N,N) + h(N)
49
50
Robot Navigation
Result #2
If h is consistent, then whenever A*
expands a node, it has already found
an optimal path to this nodes state
N
c(N,N)
h(N)
h(N)
h(N) c(N,N) + h(N)
Proof (1/2)
1)
f(N)
52
Proof (2/2)
2)
f(N)
K
N
S
53
Proof (2/2)
2)
Implication of Result #2
Result #2
If h is consistent, then whenever A* expands a
Ifnode,
a node
is already
selectedfound
for expansion,
other
it K
has
an optimalthen
pathany
to this
node
N instate
the fringe verifies f(N) f(K)
nodes
The path to N
is the optimal
path to S
K
N
S
N1
N2 can be
discarded
N2
56
S1
57
58
Heuristic Accuracy
For example: h 0
h1(N) h2(N)
h2 is said to be more accurate ((or more informed)
f
)
than h1
5
3
6
STATE(N)
59
Goal state
60
10
Result #3
Proof
C* = h*(initial-node)
Every
y node N such that h(N)
( ) < C*g(
g(N)) is eventually
y
expanded. So, every node N such that h2(N) < C*g(N)
is expanded by A2*. Since h1(N) h2(N), N is also
expanded by A1*
If there are several nodes N such that f1(N) = f2(N) =
C* (such nodes include the optimal goal nodes, if there
exists a solution), A1* and A2* may or may not expand
them in the same order (until one goal node is
expanded)
62
Experimental Results
63
5
5
di is th
the length
l
th of
f the
th
shortest path to move
tile i to its goal position,
ignoring the other tiles,
e.g., d5 = 2
h2 = i=1,...8 di
8-puzzle with:
h1 = number of misplaced tiles
h2 = sum of distances of tiles to their goal positions
IDS
A1*
A2*
2.45
1.79
1.79
2.73
1.34
1.30
12
2.78 (3,644,035)
1.42 (227)
1.24 (73)
16
--
1.45
1.25
20
--
1.47
1.27
24
--
1.48 (39,135)
1.26 (1,641)
64
Can we do better?
For example, we could consider two more complex
relaxed problems:
5
d1234 = length of the
shortest path to move
tiles 1, 2, 3, and 4 to
their goal positions,
positions
ignoring the other tiles
1
4
2
3
d5678
5
7
66
11
Can we do better?
Can we do better?
1
4
d5678
8
5
5678
1
2
3
d5678
5
7
Several order-of-magnitude
speedups
7 3 6
7 8
d
for the 15- and 24-puzzle (see R&N)
4
Can we do better?
1
67
5
7
8-Puzzle
f(N) = g(N) + h(N)
with h(N) = number of misplaced tiles
Cutoff=4
6
71
72
12
8-Puzzle
8-Puzzle
Cutoff=4
Cutoff=4
73
74
8-Puzzle
8-Puzzle
Cutoff=4
4
4
Cutoff=4
75
76
8-Puzzle
8-Puzzle
Cutoff=5
Cutoff=5
6
77
6
78
13
8-Puzzle
8-Puzzle
Cutoff=5
4
4
Cutoff=5
5
7
79
80
8-Puzzle
8-Puzzle
Cutoff=5
5
4
Cutoff=5
5
4
7
6
5
7
81
8-Puzzle
82
Advantages/Drawbacks of IDA*
Advantages:
Still complete and optimal
Requires less memory than A*
Avoid the overhead to sort the fringe
Cutoff=5
5
4
5
7
Drawbacks:
6
83
84
14
Local Search
Steepest Descent
1) S initial state
2) Repeat:
a) S arg minSSUCCESSORS(S){h(S)}
b) if GOAL?(S) return S
c) if h(S) < h(S) then S S else return failure
Similar to:
- hill climbing with h
- gradient descent over continuous space
85
86
Application: 8-Queen
Application: 8-Queen
Repeat n times:
1) Pick an initial state S at random with one queen in each column
2) Repeat k times:
a) If GOAL?(S) then return S
b) Pick an attacked queen Q at random
c) Move Q in its column to minimize the number of attacking
queens new S [m
q
[min-conflicts
f
heuristic]]
3) Return failure
1
2
Repeat
n times:
Why
does it work ???
1) 1)Pick
an initial
state
S at random
with one that
queen in
each column
There
are
many
goal states
are
2) Repeat k times:
well-distributed over the state space
a) If GOAL?(S) then return S
2)b)IfPick
no an
solution
has been found after a few
attacked queen Q at random
better
start it
overofagain.
c) steps,
Move Q its
it in its
column to
to minimize
theall
number
attacking
hnew
S would
Bqueens
Building
ildi is minimum
a search
ttree
ld be
b much
h lless
2
0
2
2
2
2
2
3
3
2
2
3
3
2
2
3
Steepest Descent
2
2
2
2
1) S initial state
2) Repeat:
a) S arg minSSUCCESSORS(S){h(S)}
b) if GOAL?(S) return S
c) if h(S) < h(S) then S S else return failure
S initial state
Repeat k times:
a)
b)
c)
d)
3)
89
h = h(S)-h(S)
with probability ~ exp(h/T), where T is called the
temperature, do: S S
[Metropolis criterion]
Return failure
90
15
Search problems
Blind search
Heuristic search:
best-first and A*
Variants of A*
Local search
92
93
16