Chapter 2 Problem Solving by Search
Chapter 2 Problem Solving by Search
Example 1: Romania
Formulating problems as search problems
4
State-space diagrams
State-space
description can be represented by a state-
space diagram, which shows
◼ States (incl. initial and goal)
◼ Operators/actions (state transitions)
◼ Path costs
Formulating problems as search problems
8
Example 2: 8-Puzzle
States:
Operators:
Goal test:
Path cost: ?
Formulating problems as search problems
10
function Breath_First_Search
{
1. Initialize list L using the initial state of problem
2. loop do
if L empty then return failure;
choose a node u at the front of L;
if u is goal state then return the corresponding
solution
else for each node v adjacent to node u do
{insert v into the queue of L; father(v)=u};
}
Breadth-first search
17
Example 1:
Initial state: A; Goal state: H
Breadth-first search
18
Example 1:
Depth first search
19
function Depth_First_Search
{
1. Initialize list L using the initial state of problem
2. loop do
if L empty then return failure;
choose a node u at the front of L;
if u is goal state then return the corresponding
solution
else for each node v adjacent to node u do
{insert v into the front of L; father(v)=u};
}
Depth first search
20
Example 1:
Blind search
21
Example 2:
Initial state: A; Goal state: G
Blind search
22
Example 2:
Blind search
23
Example 3:
Initial state: A; Goal state: G
Search strategy
24
5 8 1 2 3
4 2 1 4 5 6
7 3 6 7 8
STATE(N) Goal state
h1(N) = number of misplaced numbered tiles = 6
h2(N) = sum of the (Manhattan) distance of every numbered tile to its goal
position.
h2(N) = 2 + 3 + 0 + 1 + 3 + 0 + 3 + 1 = 13
Best-First Search
26
function Best_First_Search
{
1. Initialize list L using the initial state of problem
2. loop do
if L empty then return failure;
choose a node u at the front of L;
if u is goal state then return the corresponding solution
else for each node v adjacent to node u do
{insert v into of L so that L is sorted in ascending order of
the evaluation function; father(v)=u};
}
Best-First Search
28
Hill-Climbing Search
29
function Hill_Climbing_Search
{
1. Initialize list L using the initial state of problem
2. loop do
if L empty then return failure;
choose a node u at the front of L;
if u is goal state then return the corresponding solution
else for each node v adjacent to node u do
{insert v into of L1 so that L1 is sorted in ascending order of the
evaluation function; father(v)=u
Move list L1 to the beginning of list L
};
}
Hill-Climbing Search
30
Exercise
31