Chapter 5 and Chapter 6 Solving Problems by Searching
Chapter 5 and Chapter 6 Solving Problems by Searching
INTELLIGENCE
12/01/2023
The 8-puzzle
2 8 3 1 2 3
1 6 4 8 4
7 5 7 6 5
Start Goal
2 8 3 2 8 3 2 8 3
1 6 4 1 4 1 6 4
7 5 7 6 5 7 5
2 8 3 2 8 3 2 3 2 8 3
6 4 1 4 1 8 4 1 6 4
1 7 5 7 6 5 7 6 5 7 5
12/01/2023
Toy Problems and Real Problems
• 8-puzzle
• Farmer, wolf, goat, and cabbage problem
• Vacuum World
• Crypt arithmetic
• The water jug problem
• Missionaries and Cannibals
• Towers of Hanoi
• 8-queens
12/01/2023
Problem Solving terms:
• World State – values of all features of interest in the world.
• State Space – the set of all possible world states.
• Operators – change one state into another; cost of applying operator.
• Goal – An (often partial) world state or states; in an agent, often implemented as a
function of state and current percept.
• Initial State – The values of attributes that are in effect at the beginning of a
problem before any operators have been applied.
• Note: The states and the operators define a directed (possibly weighted) graph.
2 8 3 1 2 3
1 6 4 8 4
7 5 7 6 5
Start Goal
• States: 3x3 array of integer values
• Operators: Move tile number i left, right, up, down
• Goal Test: goal state (given)
• Path Cost: 1 per move
• Constraints: Can only move in a direction if that space is empty
12/01/2023
Example: The 8-puzzle
2 8 3 1 2 3
1 6 4 8 4
7 5 7 6 5
Start Goal
• States: Integer location of tiles (ignore intermediate positions)
• Operators: Move blank left, right, up, down
• Goal Test: goal state (given)
• Path Cost: 1 per move
Can only move blank in a direction if it stays in puzzle
• Constraints:
12/01/2023
Example: The 8-puzzle
1 2 3 2 8 3 1 2 3
4 5 6 1 6 4 8 4
7 8 9 7 5 7 6 5
Start Goal
12/01/2023
Class Work: The 8-Puzzle
5 4 1 2 3
Goal
Start
6 1 8 8 4
7 3 2 7 6 5
Misplaced tiles = ?
Total Distance = ?
12/01/2023
Class Work: the 8-Puzzle
5 1 4 1 2 3
Goal
Start
6 8 8 4
7 3 2 7 6 5
12/01/2023
• The Wolf, Goat, and Cabbage
Brain Teasers
12/01/2023
This problem can be found in eighth century texts.
A man has to take a wolf, a goat, and some cabbage
across a river. His rowboat has enough room for the
man plus either the wolf or the goat or the cabbage. If
he takes the cabbage with him, the wolf will eat the
goat. If he takes the wolf, the goat will eat the
cabbage. Only when the man is present are the goat
and the cabbage safe from their enemies. All the
same, the man carries wolf, goat, and cabbage
across the river. How?
Puzzle provided by Kordem sky: The Moscow
12/01/2023 Puzzles (Dover)
Farmer, wolf, goat, and cabbage problem
12/01/2023
State space graph
F, W, G, C
FW
FG FC
FW
12/01/2023
Water Jugs Problem
• You are given:
• a spigot,
• a 3 Gallon jug,
• a 4 Gallon jug.
12/01/2023
Water Jugs
• States: How full are the • Initial State:
two jugs? 4G = 0
3G=0
• State Representation:
4G = ? • Goal State:
3G = ? 4G=2
• Constraints:
0 4G 4
0 3G 3
12/01/2023
Operators
• F3: Fill the 3 Gallon jug from the tap.
• F4: Fill the 4 Gallon jug from the tap.
• E4: Empty the 4-Gallon jug on the ground.
• P43: Pour water from 4G jug into the 3G jug until 3G jug is
full.
• P34: Pour water from 3G jug into the 4G jug until 4G jug is full
or 3G is empty.
12/01/2023
Solution Path
• Initial State Goal State?
12/01/2023
Partial State Graph And Solution Path
12/01/2023
Missionaries and cannibals
12/01/2023
Missionaries and cannibals
• States: three numbers (i,j,k) representing the number of missionaries,
cannibals, and canoe s on the left bank of the river.
• Operators: take one missionary, one cannibal, two missionaries, two cannibals,
one missionary and one cannibal across the river in a given direction (I.e. ten
operators).
12/01/2023
Missionaries and Cannibals
(3,3,1) (0,0,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
A missionary and cannibal cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(2,2,0) (1,1,1)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
One missionary returns
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(3,2,1) (0,1,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
Two cannibals cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(3,0,0) (0,3,1)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
A cannibal returns
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(3,1,1) (0,2,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
Two missionaries cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(1,1,0) (2,2,1)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
A missionary and cannibal return
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(2,2,1) (1,1,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
Two Missionaries cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(0,2,0) (3,1,1)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
A cannibal returns
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(0,3,1) (3,0,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
Two cannibals cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(0,1,0) (3,2,1)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
A cannibal returns
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(0,2,1) (3,1,0)
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
The last two cannibals cross
R
I
V
E
R
12/01/2023
Missionaries and Cannibals
(0,0,0) (3,3,1)
R
I
V
E
R
12/01/2023
Class Work:
4 Missionaries and 4 Cannibals
(4,4,1) (0,0,0)
R
I
V
E
R
12/01/2023
Chapter 6
Search Methods
12/01/2023
Example: House Cleaning
Single-state, start in
#5. Solution?
•
12/01/2023
Example: House Cleaning
Single-state, start in #5.
Solution? [Right, Suck]
•
Sensorless, start in
{1,2,3,4,5,6,7,8} e.g.,
Right goes to {2,4,6,8}
Solution?
•
12/01/2023
Example: House Cleaning
• Sensorless, start in
{1,2,3,4,5,6,7,8} e.g.,
Right goes to {2,4,6,8}
Solution?
[Right,Suck,Left,Suck]
• Contingency
• Nondeterministic: Suck may
dirty a clean carpet
• Partially observable: location, dirt at current location.
• Percept: [L, Clean], i.e., start in #5 or #7
Solution?
12/01/2023
Example: House Cleaning
• Sensorless, start in
{1,2,3,4,5,6,7,8} e.g.,
Right goes to {2,4,6,8}
Solution?
[Right,Suck,Left,Suck]
• Contingency
• Nondeterministic: Suck may
dirty a clean carpet
• Partially observable: location, dirt at current location.
• Percept: [L, Clean], i.e., start in #5 or #7
Solution? [Right, if dirt then Suck]
12/01/2023
Example: robotic assembly
• states?
• actions?
• goal test?
• path cost?
12/01/2023
•
Vacuum world state space graph
12/01/2023
Vacuum world state space graph
• states: 2*22 =8
• Initial state: Any state can be designated
• Successor function: legal states (Left, Right and suck)
• Goal test: All squares clean
• path cost: 1 per action
12/01/2023
Problem-solving agents
• Goal Formulation: Before agent can start searching for
solutions, it must formulate a goal and then use it to
formulate a problem
12/01/2023
Problem-solving agents
i,e., c(x,a,b)≥0
cost (Bosaso,action,Armo)=100
12/01/2023
12/01/2023
A Toy Example: A Romanian Holiday
12/01/2023