Title: Heuristic search
1Heuristic search
- Reading AIMA 2nd ed., Ch. 4.1-4.3
2(Blind) Tree search so far
function TreeSearch(problem, fringe) n
InitialState(problem) fringe Insert(n) while
(1) If Empty(fringe) return failure n
RemoveFront(fringe) If Goal(problem,n) return
n fringe Insert( Expand(problem,n) ) end end
- Strategies
- BFS fringe FIFO
- DFS fringe LIFO
- Strategies defined by the order of node expansion
3Example of BFS and DFS in a maze
G
G
s0
s0
4Informed searches best-first search
- Idea Add domain-specific information to select
the best path to continue searching along. - How to do it?
- Use evaluation function, f(n), which selects the
most desirable (best-first) node to expand. - Fringe is a queue sorted in decreasing order of
desirability. - Ideal case f(n) true cost to goal state t(n)
- Of course, t(n) is expensive to compute (BFS!)
- Use an estimate (heuristic) instead
5maze example
- f(n) straight-line distance to goal
2
1
G
3
2
1
1
4
3
2
2
2
s0
3
3
3
4
4
4
6Romania example
7Greedy search
- Evaluation function f(n) h(n) --- heuristic
estimate of cost from n to closest goal - Greedy search expands nodes that appear to be
closest to goal
8Example of greedy search
Arad h 366
Arad h 366
Sibiu h 253
Fagaras h 176
Bucharest h 0
Is this the optimal solution?
9Properties of greedy search
- Completeness
- Not complete, can get stuck in loops, e.g., Iasi
-gt Neamt -gt Iasi -gt Neamt -gt - Can be made complete in finite spaces with
repeated-state checking - Time complexity
- O(bm), but good heuristic can give excellent
improvement - Space complexity
- O(bm), keeps all nodes in memory
- Optimality
- No, can wander off to suboptimal goal states
10A-search
- Improve greedy search by discouraging
wandering-off - f(n) g(n) h(n)g(n) cost of path to reach
node nh(n) estimated cost from node n to goal
nodef(n) estimated total cost through node n - Search along most promising path, not node
- Is A-search optimal?
11Optimality of A-search
- Theorem Let h(n) be at most ? higher than
t(n), for all n. Than, the A-search will be at
most ? steps longer than the optimal search. - Proof If n is a node on the path found by
A-search, then f(n) g(n) h(n) ? g(n) t(n)
? optimal ?
12A search
- How to make A-search optimal?
- Make ? 0.
- This means heuristic must always underestimate
the true cost to goal. h(n) has to be an
Optimistic estimate. - 0 ? h(n) ? t(n) is called an admissible
heuristic. - Theorem Tree A-search is optimal if h(n) is
admissible.
13Example of A search
Arad h 366
Arad
Sibiu
Fagaras
Rimnicu V.
Pitesti
Bucharest f 4180
14A optimality proof
- Suppose there is a suboptimal goal G on the
queue. Let n be an unexpanded node on a shortest
path to optimal goal G.
- f(G) g(G) h(G) g(G) since h(G)0
gt g(G) since G is suboptimal ?
f(n) g(n) h(n) since h is admissible - Hence, f(G) gt f(n), and f(G) will never be
expanded - Remember example on the previous page?
15Consistency of A
- Consistency conditionh(n) - c(n,n) ?
h(n) where n is any successor of n - Guarantees optimality of graph search (remember,
the proof was for tree search!) - Also called monotonicityf(n) g(n) h(n)
g(n) c(n,n) h(n) ? g(n) h(n)
f(n)f(n) ? f(n) - f(n) is monotonically non-decreasing
16Example of consistency/monotonicity
- A expands nodes in order of increasing f-value
- Adds f-contours of nodes
- BFS adds layers
17Properties of A
- Completeness
- Yes (for finite graphs)
- Time complexity
- Exponential in h(n) - t(n) x length of
solution - Memory requirements
- Keeps all nodes in memory
- Optimal
- Yes
18Admissible heuristics h(n)
- Straight-line distance for the maze and Romanian
examples - 8-puzzle
- h1(n) number of misplaced tiles
- h2(n) number of squares from desired location
of each tile (Manhattan distance)
- h1(S) 7
- h2(S) 40331021 14
19Dominance
- If h1(n) and h2(n) are both admissible and h1(n)
? h2(n), then h2(n) dominates over h1(n) - Which one is better for search?
- h2(n), because it is closer to t(n)
- Typical search costsd 14, IDS 3,473,941
nodes A(h1) 539 A(h2) 113d 24, IDS
54 billion nodes A(h1) 39135 A(h2)
1641
20Relaxed problems
- How to derive admissible heuristics?
- Can be derived from exact solutions to problems
that are simpler (relaxed) versions of the
problem one is trying to solve - Examples
- 8-puzzle
- Tile can move anywhere from initial position (h1)
- Tiles can occupy same square but have to move one
square at a time (h2) - maze
- Can move any distance and over any obstacles
- ImportantThe cost of optimal solution to
relaxed problems is no greater than the optimal
solution to the real problem.
21Local search
- In many problems one does not care about the
path, rather one wants to find the goal state
(based on a goal condition). - Use local search / iterative improvement
algorithms - Keep a single current state, try to improve it.
22Example
- N-queens problemfrom initial configuration
move to other configurations such that the number
of conflicts is reduced
23Hill-climbingGradient ascent / descent
function HillClimbing(problem) n
InitialState(problem) while (1) neighbors
Expand(problem,n) n arg max
Value(neighbors) If Value(n) lt Value(n), return
n n n end end
24Hill climbing (contd)
- ProblemDepending on initial state, can get
stuck in local maxima (minima), ridges, plateaus
25Beam search
- Problem of local minima (maxima) in hill-climbing
can be alleviated by starting HC from multiple
random starting points - Or make it stochastic (Stochastic HC) by choosing
successors at random, based on how good they
are - Local beam search somewhat similar to
random-restart HC - Start from N initial states.
- Expand all N states and keep N best successors.
- Stochastic beam search stochastic version of
LBS, similar to SHC.
26Simulated annealing
- Idea
- Allow bad moves, initially more, later fewer
- Analogy with annealing in metallurgy
function SimulatedAnnealing(problem,schedule) n
InitialState(problem) t 1 while (1) T
schedule(t) neighbors Expand(problem,n) n
Random(neighbors) ?V Value(n) - Value(n) If
?V gt 0, n n Else n n with probability
exp(?V/T) t t 1 end end
27Properties of simulated annealing
- At fixed temperature T, state occupation
probability reaches Boltzman distribution, exp(
V(n)/T ) - Devised by Metropolis et al. in 1953
28Genetic algorithms