Local Search Algorithms
Local Search Algorithms
Example: n-queens
problem
Example: n-queens
problem
Put n queens on an n n board with no two queens
on the same row, column, or diagonal
exchanges
Hill-climbing search
Random-Restart Hill-Climbing
Random-restart hill-climbing
conducts a series of hill-climbing
searches from randomly generated
initial states, running each until it
halts or makes no distinct progress.
Simulated annealing
search
Simulated annealing
search
Effect of temperature
exp(/T)
Simulated annealing
search
Greedy search
Beam search
Genetic algorithms
Genetic algorithms
Genetic algorithm
function GENETIC_ALGORITHM( population, FITNESS-FN) return an
individual
input: population, a set of individuals
FITNESS-FN, a function which determines the quality of the
individual
repeat
new_population empty set
loop for i from 1 to SIZE(population) do
x RANDOM_SELECTION(population, FITNESS_FN)
y RANDOM_SELECTION(population, FITNESS_FN)
child REPRODUCE(x,y)
if (small random probability) then child MUTATE(child )
add child to new_population
population new_population
until some individual is fit enough or enough time has elapsed
return the best individual
19
AI 1
Exploration problems
contingencies.
20
AI 1
Agent knowledge:
ACTION(s): list of allowed actions in state s
C(s,a,s): step-cost function (! After s is determined)
GOAL-TEST(s)
Online DF-search
function ONLINE_DFS-AGENT(s) return an action
input: s, a percept identifying current state
static: result, a table indexed by action and state, initially empty
unexplored, a table that lists for each visited state, the action not yet tried
unbacktracked, a table that lists for each visited state, the backtrack not yet tried
s,a, the previous state and action, initially null
if GOAL-TEST(s) then return stop
if s is a new state then unexplored[s] ACTIONS(s)
if s is not null then do
result[a,s] s
add s to the front of unbackedtracked[s]
if unexplored[s] is empty then
if unbacktracked[s] is empty then return stop
else a an action b such that result[b, s]=POP(unbacktracked[s])
else a POP(unexplored[s])
s s
return a
GOAL-TEST((,1,1))?
{RIGHT,UP}
s is null?
True (initially)
UX[(1,1)] empty?
False
POP(UX[(1,1)])->a
A=UP
AI 1
s = (1,1)
Return a
GOAL-TEST((2,1))?
{DOWN}
s is null?
false (s=(1,1))
result[UP,(1,1)] <- (2,1)
UB[(2,1)]={(1,1)}
UX[(2,1)] empty?
False
GOAL-TEST((1,1))?
s is null?
false (s=(2,1))
result[DOWN,(2,1)] <- (1,1)
UB[(1,1)]={(2,1)}
UX[(1,1)] empty?
False
GOAL-TEST((1,2))?
S not = G thus false
UX[(1,2)]={RIGHT,UP,LEFT}
s is null?
false (s=(1,1))
result[RIGHT,(1,1)] <- (1,2)
UB[(1,2)]={(1,1)}
UX[(1,2)] empty?
False
GOAL-TEST((1,1))?
AI 1
6/11/15
True
UB[(1,1)] empty? False
A= b for b in result[b,
(1,1)]=(1,2)
false (s=(1,2))
result[LEFT,(1,2)] <- (1,1)
UB[(1,1)]={(1,2),(2,1)}
UX[(1,1)] empty?
false
s is null?
B=RIGHT
A=RIGHT, s=(1,1)
Online DF-search