Lecture 3
Lecture 3
Search
1
Informed Methods Add
Domain-Specific Information
• 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 n with respect to reaching a goal.
• Specifically, h(n) = estimated cost (or distance) of minimal
cost path from n to a goal state.
• h(n) is about cost of the future search, g(n) past search
• h(n) is an estimate (rule of thumb), based on domain-
specific information that is computable from the current
state description. Heuristics do not guarantee feasible
solutions and are often without theoretical basis.
2
Heuristics
• Examples:
– Missionaries and Cannibals: Number of people on starting river
bank
– 8-puzzle: Number of tiles out of place (i.e., not in their goal
positions)
– 8-puzzle: Sum of Manhattan distances each tile is from its goal
position
– 8-queen: # of un-attacked positions – un-positioned queens
• In general:
– h(n) >= 0 for all nodes n
– h(n) = 0 implies that n is a goal node
– h(n) = infinity implies that n is a deadend from which a goal
cannot be reached
3
Best First Search
• Order nodes on the OPEN list by increasing
value of an evaluation function, f(n) , that
incorporates domain-specific information in
some way.
• Example of f(n):
– f(n) = g(n) (uniform-cost)
– f(n) = h(n) (greedy algorithm)
– f(n) = g(n) + h(n) (algorithm A)
• This is a generic way of referring to the class
of informed methods.
4
Greedy Search
• Evaluation function f(n) = h(n), sorting
open nodes by increasing values of f. a
• Selects node to expand believed to be
closest (hence it's "greedy") to a goal h=2 b g h=4
node (i.e., smallest f = h value)
• Not admissible, as in the example. h=1 c h h=1
8
Some Observations on A*
1 A 8 5 B 4 8 C 3
3 9 h value
7 4 5 g value
4 D 8 E 9 G 0
goal state
10
Example
n g(n) h(n) f(n) h*(n)
S 0 8 8 9
A 1 8 9 9
B 5 4 9 4
C 8 3 11 5
D 4 inf inf inf
E 8 inf inf inf
G 9 0 9 0
f(n) = h(n)
12
A* Search
f(n) = g(n) + h(n)
14
Iterative Deepening A* (IDA*)
• Idea:
– Similar to IDDF except now at each iteration the DF search is
not bound by the current depth_limit but by the current f_limit
– At each iteration, all nodes with f(n) <= f_limit will be
expanded (in DF fashion).
– If no solution is found at the end of an iteration, increase
f_limit and start the next iteration
• f_limit:
– Initialization: f_limit := h(s)
– Increment: at the end of each (unsuccessful) iteration,
f_limit := max{f(n)|n is a cut-off node}
• Goal testing: test all cut-off nodes until a solution is found
• Admissible if h is admissible
15
Automatic generation of h functions
• Original problem P Relaxed problem P'
A set of constraints removing one or more constraints
P is complex P' becomes simpler
• Use cost of a best solution path from n in P' as h(n) for P
• Admissibility:
h* h
cost of best solution in P >= cost of best solution in P'
Solution space of P
17
h3:
repeat
if the current empty cell A is to be occupied by tile x
in the goal, move x to A. Otherwise, move into A any
arbitrary misplaced tile.
until the goal is reached
• h2>= h3 >= h1
h1(start) = 7
h2(start) = 18
h3(start) = 7
18
• Example: TSP. A legal tour is a (Hamiltonian) circuit
– It is a connected second degree graph (each node has
exactly two adjacent edges)
Removing the connectivity constraint leads to h1:
find the cheapest second degree graph from the
given graph
(with o(n^3) complexity)
19
– It is a spanning tree (when an edge is removed) with the
constraint that each node has at most 2 adjacent edges)
Removing the constraint leads to h2:
find the cheapest minimum spanning tree from the
given graph
(with O(n^2/log n)
20
Complexity of A* search
• In general, exponential time and space complexity
• For subexponential growth of # of nodes expanded, need
|h(n)-h*(n)| <= O(log h*(n)) for all n
For most problem we have |h(n)-h*(n)| <= O(h*(n)
• Relaxing optimality
– Weighted evaluation function
F(n)=(1-w)*g(n)+w*h(n)
w=0: uniformed-cost search
w=1: greedy algorithm
w=1/2: A* algorithm
21
– Dynamic weighting
f(n)=g(n)+h(n)+ [1- d(n)/N]*h(n)
d(n): depth of node n
N: anticipated depth of an optimal goal
at beginning of search: d (n) << N
f (n) g (n) (1 )h(n) encourages DF search
n) N
d (search:
at beginning of
f ( n) g ( n) h( n) back to A*
It is -admissible (solution cost found is <= (1+ )
solution found by A*)
22
• A * : another -admissible algorithm
do not put a new node n on OPEN unless
f(n) <= smallest f value among all nodes already in OPE
• Pruning OPEN list
– Find a solution using some quick but non-admissible
method (e.g., greedy algorithm, hill-climbing, neural
networks) with cost f+
– Do not put a new node n on OPEN unless f(n)<=f+
– Admissible: suppose f(n)>f+>=f*, the least cost solution
sharing the current path from s to n would have cost
g(n)+h*(n)>=g(n)+h(n)=f(n)>f*
23
Iterative Improvement Search
• Another approach to search involves starting
with an initial guess at a solution and
gradually improving it until it is one.
• Some examples:
– Hill Climbing
– Simulated Annealing
– Genetic algorithm
24
Hill Climbing on a Surface of States
Height Defined by
Evaluation Function
25
Hill Climbing Search
• If there exists a successor n’ for the current state n such that
– h(n’) < h(n)
– h(n’) <= h(t) for all the successors t of n,
• then move from n to n’. Otherwise, halt at n.
• Looks one step ahead to determine if any successor is better
than the current state; if there is, move to the best successor.
• Similar to Greedy search in that it uses h, but does not
allow backtracking or jumping to an alternative path since it
doesn’t “remember” where it has been.
• OPEN = {current-node}
• Not complete since the search will terminate at "local
minima," "plateaus," and "ridges."
26
Hill climbing example
2 8 3 1 2 3
start 1 6 4 h=4 goal 8 4 h=0
7 5 7 6 5
5 5 2
2 8 3 1 2 3
1 4 h=3 8 4 h=1
7 6 5 7 6 5
3 4
2 3 2 3
1 8 4 1 8 4 h=2
7 6 5 7 6 5
h=3 4
28
Simulated Annealing
• Simulated Annealing (SA) exploits an analogy between the way
in which a metal cools and freezes into a minimum energy
crystalline structure (the annealing process) and the search for a
minimum in a more general system.
• Each state n has an energy value f(n), where f is an evaluation
function
• SA can avoid becoming trapped at local minimum energy state
by introducing randomness into search so that it not only
accepts changes that decreases state energy, but also some that
increase it.
• SAs use a a control parameter T, which by analogy with the
original application is known as the system “temperature”
irrespective of the objective function involved.
• T starts out high and gradually (very slowly) decreases toward 0.
29
Algorithm outline for SA
current := a randomly generated state;
T := T_0 /* initial temperature T0 >>0 */
forever do
if T <= T_end then return current;
next := a randomly generated new state; /* next != current */
E = f(next) – f(current); 1
current := next with probability pE E / T ;
1 e
T := schedule(T); /* reduce T by a cooling schedule */
30
Observations with SA
1
• T E E
1 e E / T
1 positive 0.5 increase
negative 0.5 decrease
0 positive 0.0 no change
negative 1.0 decrease
• Probability of the system is at any particular state
depends on the state’s energy (Boltzmann distribution)
1 E / T
P e , where Z e E / T
Z
• If time taken to cool is infinite then
P (stays at minimum energy state g*)
P (stays at any other state n)
31
Genetic Algorithms
• Emulating biological evolution (survival of the fittest by natural selection
process )
population
selection of parents for reproduction
(based on a fitness function)
parents
reproduction (cross-over + mutation)
next generation of population