0% found this document useful (0 votes)
7 views

Chapter 5 and Chapter 6 Solving Problems by Searching

The document discusses several classic artificial intelligence problem solving examples including the 8-puzzle, water jug problem, missionaries and cannibals problem, and towers of Hanoi. It describes the key components of formulating a problem for search-based solving including defining the state space, possible operators or actions, an initial starting state, and a goal test. Several examples are provided of representing problems as state space graphs that can be traversed to find a solution path.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 5 and Chapter 6 Solving Problems by Searching

The document discusses several classic artificial intelligence problem solving examples including the 8-puzzle, water jug problem, missionaries and cannibals problem, and towers of Hanoi. It describes the key components of formulating a problem for search-based solving including defining the state space, possible operators or actions, an initial starting state, and a goal test. Several examples are provided of representing problems as state space graphs that can be traversed to find a solution path.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 62

ARTIFICIAL

INTELLIGENCE

Chapter 5: Solving problems by


searching
Outline
• Problem-solving agents
• Problem types
• Problem formulation
• Example problems
• Basic search algorithms

12/01/2023
The 8-puzzle

2 8 3 1 2 3

1 6 4 8 4

7 5 7 6 5

Start Goal

How do we goal from start configuration to the


goal configuration?
12/01/2023
The corresponding search tree
2 8 3
1 6 4
7 5

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.

• Solution (path) – a sequence of operators leading from the


initial state to a goal state.
12/01/2023
• Path cost – e.g. sum of distances, number of operators executed…
Example: The 8-puzzle

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

Initial State = [2, 8, 3, 1, 6, 4, 7, B, 5]


Misplaced tiles = [4]
Total Distance = [1 + 2 + 0 + 1 + 1 + 0 + 0 + 0]=5
Goal State = [1, 2, 3, 8, B 4, 7, 6, 5]

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

Misplaced tiles = [7]


Total Distance = [4 + 2 + 2+ 2 + 2 + 0+ 3 + 3] = 18

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.

• The goal: Get 2 gallons of water in the 4 gallon jug.

• Actions: Filling jugs from spigot, dumping water in jugs onto


ground, dumping 4 gallon into 3 gallon jug until 3 gallon jug is full.
Dumping 3 gallon jug into 4 gallon jug until empty or until 4 gallon is
full, etc, etc.

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

• 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
Class Work: Water Jugs
• You are given:
• a spigot,
• a 3 Gallon jug,
• a 5 Gallon jug.

• The goal: Get 2 gallons of water in the 5 gallon jug.

• Actions: Filling jugs from spigot, dumping water in jugs onto


ground, dumping 5 gallon into 3 gallon jug until 3 gallon jug is full.
Dumping 3 gallon jug into 5 gallon jug until empty or until 5 gallon
is full, etc, etc.

12/01/2023
Missionaries and cannibals

• Three missionaries and three cannibals are on the left bank of


a river.

• There is one canoe which can hold one or two people.

• Find a way to get everyone to the right bank, without ever


leaving a group of missionaries in one place outnumbered by
cannibals in that place.

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.

• Initial state: (3, 3, 1)

• 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).

• Goal Test: reached state (0, 0, 0)


• Path Cost: Number of crossings.

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

Uninformed & Informed


search
Problem types
• Deterministic, fully observable  single-state problem
• Agent knows exactly which state it will be in; solution is a sequence

• Non-observable  sensor less problem (conformant problem)
• Agent may have no idea where it is; solution is a sequence

• Nondeterministic and/or partially observable  contingency or
stability problem
• percepts provide new information about current state
• often interleave} search, execution
• Unknown state space  exploration problem

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?: real-valued coordinates of robot joint angles parts of the object to be


assembled

• actions?: continuous motions of robot joints

• goal test?: complete assembly

• path cost?: time to execute

12/01/2023
Vacuum world state space graph

• states?
• actions?
• goal test?
• path cost?
12/01/2023

Vacuum world state space graph

• states? integer dirt and robot location


• actions? Left, Right, Suck
• goal test? no dirt at all locations
• path cost? 1 per action

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

• Problem formulation: deciding what actions and states to


consider for a given goal
• Search: process of looking for such a sequence

12/01/2023
Problem-solving agents

• Step cost: sum of costs of the individual actions


along the path

i,e., c(x,a,b)≥0

cost (Bosaso,action,Armo)=100

12/01/2023
12/01/2023
A Toy Example: A Romanian Holiday

• State space: Cities in Romania


• Initial state: Town of Arad
• Goal: Airport in Bucharest
• Operators: Drive between cities
• Solution: Sequence of cities
• Path cost: Number of cities,
distance, time, fuel

12/01/2023

You might also like