Artificial Intelligence: Lecture 4: Problem Solving Search
Artificial Intelligence: Lecture 4: Problem Solving Search
1 2 3 1 2 3
4 8 4 5 6
7 6 5 7 8
2/16
8-Puzzle
Problem formulation 1 3
1 2 3
Goal State 4 5 6
7 8
Operators:
slide-blank-up, slide-blank-down,
slide-blank-left, slide-blank-right
3/16
Path Cost: The number of steps to reach the goal state
Problem Formulation
A description of the desired state of the world (goal state), this could be
implicit or explicit.
2 1 3 1 2 3
Slide blank square left.
4 7 6 Slide blank square right. 4 5 6
….
5 8 7 8
5/16
Problem Formulation :8-Puzzle Problem
Representing states:
3 by 3 array
5, 6, 7 5 6 7
8, 4, BLANK
8 4
3, 1, 2
3 1 2
A vector of length nine
5,6,7,8,4, BLANK,3,1,2
A list of facts
Upper_left = 5
Upper_middle = 6
6/16
Upper_right = 7
Middle_left = 8
Problem Formulation :8-Puzzle Problem
Initial state 1 2 3
4 8
7 6 5
Goal state 1 2 3
4 5 6
7 8
Operators: slide blank up, slide blank down, slide blank left, slide blank right
Solution: ?
Path cost: ?
7/16
Problem Formulation: 8-Puzzle Problem
Solution1: sb-down, sb-left, sb-up, sb-right, sb-down
Operators: slide blank up, slide blank down, slide blank left, slide blank right
1 2 3 1 2 3 1 2 3
4 8 4 8
5 5
6 4 5 6
7 6 5 7 6
8 5
6 7 8
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
4 8 4 8 5 4 8 5 4 5 4 5 4 5 6
7 6 5 7 6 7 6 7 8 6 7 8 6 7 8
8/16
Path cost: 5 steps to reach the goal
Problem Formulation: 8-Puzzle Problem
1 2 3 1 2 3 1 2 3
4 8 4 8
6
5 8
6 4 5 6
7 6 5 7 6
5
8 5
8 7 8
1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
4 8 4 8 4 6 8 4 6 8 4 6 4 6
7 6 5 7 6 5 7 5 7 5 7 5 8 7 5 8
1 2 3 1 2 3
4 5 6 4 5 6
9/16
Path cost: 6 steps to reach the goal 7 8 7 8
Problem Formulation: River problem
A farmer wishes to carry a wolf, a duck and corn across a river, from the south to the north
shore. The farmer is the proud owner of a small rowing boat called Bounty which he feels is
easily up to the job. Unfortunately the boat is only large enough to carry at most the farmer and
one other item. Worse again, if left unattended the wolf will eat the duck and the duck will eat
the corn.
Farmer, Wolf,
Duck and Corn
10/16
Give a Formulation for this problem.
Problem Formulation: River problem
Initial State: farmer, wolf, duck and corn in the south shore FWDC/-
Goal State: farmer, duck and corn in the north shore -/FWDC
Operators: the farmer takes in the boat at most one item from one side to the
other side (F-Takes-W, F-Takes-D, F-Takes-C, F-Takes-Self [himself only])
11/16
Path cost: the number of crossings
Problem Formulation: River problem
F D D F W D
F-Takes-D F-Takes-S F-Takes-W
F W D C W C F W C C
Initial State WC/FD FWC/D C/FWD
F-Takes-D
F W D C W C F W C W
12/16
F-Takes-D F-Takes-S F-Takes-C
F D D F D C
Goal State FD/WC D/FWC FDC/W
Problem Formulation: River problem
by search Method
F WD C
F-Takes-D, F-Takes-Self, F-Takes-W,
F-Takes-D, F-Takes-C, F-Takes-Self, F
WD C
FW
DC
F
W C
D F
WD
C
F-Takes-D.
FW C F WD C
D
W C C W
F D F WD F DC
F C FW C F DC FW F WD FW C
WD D W DC C D
DC C D WD D W
FW F WD FW C F C FW C F DC
F D F WD F DC
W C C W
D
FW C F WD C
Problem Formulation: Missionaries and cannibals
Three missionaries and three cannibals are on the left bank of a river.
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.
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).
Cost = 11 crossings
Operations (i, j, k)
16/16
states?: real-valued coordinates of robot joint angles parts of the object to be assembled
Formulate goal:
be in Bucharest
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Single-state problem formulation
A solution is a sequence of actions leading from the initial state to a goal state
Tree search algorithms
Basic idea:
offline, simulated exploration of state space by generating successors of
already-explored states (a.k.a.~expanding states)
Tree search example
Tree search example
Tree search example
Implementation: states vs. nodes
The Expand function creates new nodes, filling in the various fields and using the
SuccessorFn of the problem to create the corresponding states.
Implementation: general tree search
26
Search strategies
A search strategy is defined by picking the order of node expansion
Strategies are evaluated along the following dimensions:
completeness: does it always find a solution if one exists?
time complexity: number of nodes generated
space complexity: maximum number of nodes in memory
optimality: does it always find a least-cost solution?
Implementation:
fringe is a FIFO queue, i.e., new successors go at end
Breadth-first search
Expand shallowest unexpanded node
Implementation:
fringe is a FIFO queue, i.e., new successors go at end
Breadth-first search
Implementation:
fringe is a FIFO queue, i.e., new successors go at end
Breadth-first search
Implementation:
fringe is a FIFO queue, i.e., new successors go at end
Properties of breadth-first search
Optimal? No
Depth-limited search
= depth-first search with depth limit l,
i.e., nodes at depth l have no successors
Recursive implementation:
49
Iterative deepening search
Iterative deepening search l =0
Iterative deepening search l =1
Iterative deepening search l =2
Iterative deepening search l =3
Iterative deepening search
Number of nodes generated in a depth-limited search to depth d with branching factor b:
NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd
For b = 10, d = 5,
Space? O(bd)
Iterative deepening search uses only linear space and not much more time than
other uninformed algorithms