Professional Documents
Culture Documents
Informed Searches
Best-first search
Greedy best-first search
A* search
Heuristics
Nancy E. Reed
nreed@hawaii.edu
Genetic algorithms
Chapter 4
2
1
7
4
Complete? Yes.
Optimal? Yes, if path cost is nondecreasing function of depth
Time Complexity: O(bd)
Space Complexity: O(bd), note that every node in the fringe is kept in the queue.
1
5
Complete? Yes.
Optimal? Yes, if path cost is nondecreasing function of depth
Time Complexity: O(bd)
Space Complexity: O(bd), note that every node in the fringe keep in the queue.
Note that Breadth First search can be seen as a special case of Uniform Cost Search, where the path cost is just the depth.
Artificial Intelligence
Depth-Limited Search
L is 2 in this example
10
Complete? Yes
Optimal? Yes
Time Complexity: O(bd), where d is the depth of the solution.
Space Complexity: O(bd), where d is the depth of the solution.
= 123,456
11
12
Artificial Intelligence
13
14
http://www2.hawaii.edu/~nreed/
lisp/sssearch/
West
15
16
Utility Functions
Global variables
;;
;;
17
18
FWGC
GC
W
Artificial Intelligence
19
F WG C
WG C
G C
F W
WG
20
F WG C
WG C
C
G C
F W
F W
WG
F WG C
Illegal State
22
F WG C
WG C
G C
F W
F WG C
C
F
F W
F WG
F W
WG
C
G
G C
F W
G C
G C
F WG
F W
G
W
F WG
C
F W
G
F W
G C
G
W
F WG C
C
F WG C
Illegal State
Repeated State
G C
GC
G
F W
F WG
G C
WG
C
F W
F WG
GC
F W
C
G
F WG
F
W
F
F W
G
C
F WG C
Initial State
WG
W
F W
Repeated State
21
F WG C
Illegal State
F W
G
W
F WG C
Goal State
23
uninformed search
blind search
24
Artificial Intelligence
25
Best-first search
Implementation:
Order the nodes in open list (fringe) in
decreasing order of desirability
Special cases:
27
8
5
4
1
1
4
2
5
FWG
C
3
6
8
G
FW C
29
Example: Romania
30
be in Bucharest
Start
Find solution:
sequence of cities, such
that total driving distance is minimized.
Goal
Artificial Intelligence
31
Artificial Intelligence
38
The A* Algorithm
39
Romania Map
40
Starting in Arad
Start
Goal
A* search example
A* search example
Artificial Intelligence
A* search example
A* search example
46
A* search example
47
48
Example: 8-puzzle
start state
goal state
Artificial Intelligence
49
50
; otherwise,
51
52
(+
(defun heuristic-eval-1 (state goal)
"Sum the distance for each tile from its goal position."
(do
53
54
(do
((sum 0) (i 0 (1+ i)))
(do
((j 0 (1+ j)))
((equal j *n*) )
(setq sum
(+ sum
(tile-reverse (+ (* i *n*) j) (+ (* i *n*) j 1)
state goal)))))
(do
((sum 0) (i 0 (1+ i)))
((equal i *n* ) sum)
; return 0
((and
(do
((j 0 (1+ j)))
((equal j (- *n* 1)) )
(setq sum
(+ sum
(tile-reverse (+ (* i *n*) j) (+ (* i *n*) j 1)
state goal)))) )))
1)
(t 0)) )
; return 1
; else return 0
Artificial Intelligence
55
8 Puzzle Problem
Distance Function
;; DISTANCE - calculate the distance a tile is from
;; its goal position.
(defun distance (tile state goal)
"Calculate the Manhattan distance a tile is from its
goal position."
(+
(abs (- (row tile state)
(row tile goal)))
(abs (- (column tile state)
(column tile goal)))) )
Admissible Heuristics
A heuristic h(n) is admissible if for every node n,
h(n) h*(n), where h*(n) is the true cost to reach the
goal state from n.
An admissible heuristic never overestimates the
cost to reach the goal, i.e., it is optimistic
Example: hSLD(n) (never overestimates the actual
road distance)
Theorem: If h(n) is admissible, A* using TREESEARCH is optimal
Consistent Heuristics
A heuristic is consistent if for every node n, every successor
n' of n generated by any action a,
h(n) c(n,a,n') + h(n')
If h is consistent, we have
f(n') = g(n') + h(n')
= g(n) + c(n,a,n') + h(n')
g(n) + h(n)
= f(n)
i.e., f(n) is non-decreasing along any path.
Theorem: If h(n) is consistent, A* using GRAPH-SEARCH
is optimal
Optimality of A*
A* expands nodes in order of increasing f value
Gradually adds "f-contours" of nodes
Contour i has all nodes with f=fi, where fi < fi+1
Optimality of A* (proof)
Suppose some suboptimal goal G2 has been generated and is
in the fringe. Let n be an unexpanded node in the fringe such
that n is on a shortest path to an optimal goal G.
f(G2) = g(G2)
g(G2) > g(G)
f(G) = g(G)
f(G2) > f(G)
since h(G2) = 0
since G2 is suboptimal
since h(G) = 0
from above
56
Artificial Intelligence
Optimality of A* (proof)
Suppose some suboptimal goal G2 has been generated and is in
the fringe. Let n be an unexpanded node in the fringe such that
n is on a shortest path to an optimal goal G.
Properties of A*
Complete? Yes (unless there are
infinitely many nodes with f f(G) )
Time? Exponential
Space? Keeps all nodes in memory
Optimal? Yes
f(G2)
> f(G)
from above
h(n)
h^*(n)
since h is admissible
g(n) + h(n) g(n) + h*(n)
f(n)
f(G)\
Hence f(G2) > f(n), and A* will never select G2 for expansion
Admissible heuristics
Admissible heuristics
Dominance
If h2(n) h1(n) for all n (both admissible)
then h2 dominates h1
h2 is better for search
Typical search costs (average number of
nodes expanded):
d=12 IDS = 3,644,035 nodes
A*(h1) = 227 nodes
A*(h2) = 73 nodes
d=24 IDS = too many nodes
A*(h1) = 39,135 nodes
A*(h2) = 1,641 nodes
h1(S) = ? 8
h2(S) = ? 3+1+2+2+2+3+3+2 = 18
Relaxed problems
A problem with fewer restrictions on the
actions is called a relaxed problem
The cost of an optimal solution to a relaxed
problem is an admissible heuristic for the
original problem
If the rules of the 8-puzzle are relaxed so that
a tile can move anywhere, then h1(n) gives the
shortest solution
If the rules are relaxed so that a tile can move
to any adjacent square, then h2(n) gives the
shortest solution
Artificial Intelligence
Example: n-queens
Put n queens on an n n board with no
two queens on the same row, column, or
diagonal
Hill-Climbing Search
Hill-Climbing Search
Artificial Intelligence
Genetic Algorithms
Genetic Algorithms
A successor state is generated by combining
two parent states
Start with k randomly generated states
(population)
A state is represented as a string over a finite
alphabet (often a string of 0s and 1s)
Evaluation function (fitness function). Higher
values for better states.
Produce the next generation of states by
selection, crossover, and mutation
Genetic Algorithms
Artificial Intelligence
Summary
Problem formulation usually requires abstracting
away real-world details to define a state space that
can feasibly be explored
Informed Searches
Best-first search
Greedy best-first search
A* search
Heuristics
Genetic algorithms
Chapter 4
79