(Week 2) Lecture 2b Search 2 2022
(Week 2) Lecture 2b Search 2 2022
3
Optimization Problems
An optimization problem is a kind of computational problems
that is defined by the following:
A search space of possible solutions to the problem
A set of constraints
That guides the feasibility of solutions-a solution that violates a hard
constraint cannot be regarded as valid.
An objective function
Can either be maximized or minimized, depending on the nature of the
problem.
4
Optimization Problems (2)
7
Advantages of Local Search algorithms
8
Hill Climbing Search
(Just ascend, we might hit gold)
function HILL-CLIMBING(problem) returns a state, a local maximum one
current ← problem.INITIAL
while true do
neighbour ← a highest-valued successor state of current
if Is-Better(VALUE(neighbour),VALUE(current)) then return current
current ← neighbour
The idea of hill climbing is that it keeps track of one current state and on each
iteration moves to the neighbouring state with highest value—that is, it heads in the
direction that provides the steepest ascent.
10
Current configuration
Queen 1 = 1 (row) + 2
(diagonal) = 3
Q
Queen 2 = 2 (row) + 1 Q Q Q
(diagonal) = 3 Q Q
Q Q
H = Queen 1 + Queen 2 +
… + Queen 8
Image at the centre: the current configuration of an 8-queens problem and the
numbers shown depict the heuristic function values after moving a queen within
its column to the spot where the number is.
Can you compute the value of h for the configuration on the far right? 11
Simulated Annealing
function SIMULATED-ANNEALING(problem, schedule) returns a solution state
current ← problem.INITIAL
for t = 1 to do
T ← schedule(t)
if T = 0 then return current
next ← a randomly selected successor of current
E ← VALUE(current) – VALUE(next)
if E > 0 then current ← next
else current ← next only with probability
12
Evolutionary Algorithms
13
Core Concepts in Evolutionary Algorithms
(EAs)
Generation
An iteration/epoch of an EA run.
Population size
The number of individuals, i.e. chromosomes encoding/representing a
solution of a problem.
Selection
The process of selecting which individuals will become the parents of
the next generation.
14
Core Concepts in Evolutionary Algorithms
(EAs)
Recombination/Crossover
The act of combining two parents to produce offspring
Mutation
Editing a little portion of an individual
Elitism
The phenomenon whereby the fittest individuals are usually
chosen/considered when recombination is to take place.
15
Various forms of EA
16
function GENETIC-ALGORITHM(population, fitness) 1
repeat
weights ← WEIGHTED-BY(population, fitness)
population2 ← empty list
for i = 1 to SIZE(population) do
parent1, parent2 ← WEIGHTED-RANDOM-CHOICES(population,weights,2)
child ← REPRODUCE(parent1, parent2)
if(small random probability) then child ← MUTATE(child)
add child to population2
population ← population2
until some individual is fit enough, or enough time has elapsed
return the best individual in population, according to fitness
18
Fitness function = Number of non-attacking pairs = Number of pairs – Number of attacking pairs
20
Programming Project 1 - Task
21
Programming Project 1 – Task (2)
22
Search with non-deterministic actions
23
A vacuum cleaner in a non-deterministic environment
There are eight states in the sample environment (see next slide).
There are three possible actions
Suck: attempt to soak up the dirt on the floor
Right: move to the right side of the room
Left: move to the left side of the room
The goal of the vacuum cleaner is to completely clean the floor
(without dirt in any area).
24
In the erratic vacuum world, the Suck action
works as follows:
When applied to a dirty square the action
cleans the square and sometimes cleans up
dirt in an adjacent square, too.
When applied to a clean square the action
sometimes deposits dirt on the carpet
25
Solving non-deterministic environment using AND-OR Search
trees
26
Solving non-deterministic environment using AND-OR Search
trees (Cont’d)
27
Solving non-deterministic environment using AND-OR Search
trees (Cont’d)
28
Explanation of the AND-OR search tree
State nodes are OR nodes where some
action must be chosen.
At the AND nodes, shown as circles, every
outcome must be handled, as indicated by
the arc linking the outgoing branches.
32
Online search
33
Self-Study/Activity
34
Appendix
35