Today’s class
• Goal-basedagents
• Representing states and operators
• Example problems
• Generic state-space search algorithm
• Specific algorithms
– Breadth-first search
– Depth-first search
– Uniform cost search
– Depth-first iterative deepening
• Example problems revisited
3.
Building goal-based agents
Tobuild a goal-based agent we need to answer the
following questions:
– What is the goal to be achieved?
– What are the actions?
– What is the representation?
• E.g., what relevant information is necessary to encode in order to
describe the state of the world, describe the available transitions,
and solve the problem?)
Initial
state
Goal
state
Actions
4.
What is thegoal to be achieved?
• Could describe a situation we want to achieve, a set of
properties that we want to hold, etc.
• Requires defining a “goal test” so that we know what it
means to have achieved/satisfied our goal.
• This is a hard question that is rarely tackled in AI, usually
assuming that the system designer or user will specify the
goal to be achieved.
• Certainly psychologists and motivational speakers always
stress the importance of people establishing clear goals for
themselves as the first step towards solving a problem.
5.
What are theactions?
• Characterize the primitive actions or events that are
available for making changes in the world in order to
achieve a goal.
• Deterministic world: no uncertainty in an action’s effects.
Given an action (a.k.a. operator or move) and a description
of the current world state, the action completely specifies
– whether that action can be applied to the current world
(i.e., is it applicable and legal), and
– what the exact state of the world will be after the action
is performed in the current world (i.e., no need for
“history” information to compute what the new world
looks like).
6.
What are theactions? (cont’d)
• Note also that actions in this framework can all be considered
as discrete events that occur at an instant of time.
– For example, if “Mary is in class” and then performs the action “go
home,” then in the next situation she is “at home.” There is no
representation of a point in time where she is neither in class nor at
home (i.e., in the state of “going home”).
• The actions are largely problem-specific and determined
(intelligently ;-) ) by the system designer.
• There usually are multiple action sets for solving the same
problem.
• Let’s look an example…
7.
8-Puzzle
Given an initialconfiguration of 8 numbered tiles on a 3 x
3 board, move the tiles in such a way so as to produce a
desired goal configuration of the tiles.
8.
Representing actions
• Thenumber of actions / operators depends on the
representation used in describing a state.
– In the 8-puzzle, we could specify 4 possible moves for each of the 8
tiles, resulting in a total of 4*8=32 operators.
– On the other hand, we could specify four moves for the “blank” square
and we would only need 4 operators.
• Representational shift can greatly simplify a problem!
9.
Representing states
• Whatinformation is necessary to encode about the world to
sufficiently describe all relevant aspects to solving the goal? That
is, what knowledge needs to be represented in a state description to
adequately describe the current state or situation of the world?
• The size of a problem is usually described in terms of the number
of states that are possible.
– The 8-puzzle has 181,440 states.
– Tic-Tac-Toe has about 39
states.
– Rubik’s Cube has about 1019
states.
– Checkers has about 1040
states.
– Chess has about 10120
states in a typical game.
10.
Closed World Assumption
•We will generally use the Closed World
Assumption.
• All necessary information about a problem domain
is available in each percept so that each state is a
complete description of the world.
• There is no incomplete information at any point in
time.
11.
Some example problems
•Toy problems and micro-worlds
–8-Puzzle
–Missionaries and Cannibals
–Cryptarithmetic
–Remove 5 Sticks
–Water Jug Problem
• Real-world problems
12.
8-Puzzle
Given an initialconfiguration of 8 numbered tiles on a 3 x
3 board, move the tiles in such a way so as to produce a
desired goal configuration of the tiles.
13.
• State Representation:3 x 3 array configuration of the
tiles on the board.
• Operators: Move Blank Square Left, Right, Up or Down.
– This is a more efficient encoding of the operators than one in
which each of four possible moves for each of the 8 distinct tiles is
used.
• Initial State: A particular configuration of the board.
• Goal: A particular configuration of the board.
8-Puzzle
• State Representation: 3 x 3 array configuration of the
tiles on the board.
• Operators: Move Blank Square Left, Right, Up or Down.
– This is a more efficient encoding of the operators than one in
which each of four possible moves for each of the 8 distinct tiles is
used.
• Initial State: A particular configuration of the board.
• Goal: A particular configuration of the board.
14.
The 8-Queens Problem
StateRepresentation: ?
Initial State: ?
Operators: ?
Goal: Place eight queens
on a chessboard such that
no queen attacks any other!
15.
Missionaries and Cannibals
Threemissionaries and three cannibals wish to cross the river.
They have a small boat that will carry up to two people.
Everyone can navigate the boat. If at any time the Cannibals
outnumber the Missionaries on either bank of the river, they
will eat the Missionaries. Find the smallest number of crossings
that will allow everyone to cross the river safely.
16.
• Goal: Moveall the missionaries and
cannibals across the river.
• Constraint: Missionaries can never be
outnumbered by cannibals on either side
of river, or else the missionaries are
killed.
• State: configuration of missionaries and
cannibals and boat on each side of river.
• Initial State: 3 missionaries, 3 cannibals
and the boat are on the near bank
• Operators: Move boat containing some
set of occupants across the river (in either
direction) to the other side.
Missionaries and Cannibals
• Goal: Move all the missionaries and
cannibals across the river.
• Constraint: Missionaries can never be
outnumbered by cannibals on either side
of river, or else the missionaries are
killed.
• State: configuration of missionaries and
cannibals and boat on each side of river.
• Initial State: 3 missionaries, 3
cannibals and the boat are on the near
bank
• Operators: Move boat containing some
set of occupants across the river (in
either direction) to the other side.
17.
Missionaries and CannibalsSolution
Near side Far side
0 Initial setup: MMMCCC B -
1 Two cannibals cross over: MMMC B CC
2 One comes back: MMMCC B C
3 Two cannibals go over again: MMM B CCC
4 One comes back: MMMC B CC
5 Two missionaries cross: MC B MMCC
6 A missionary & cannibal return: MMCC B MC
7 Two missionaries cross again: CC B MMMC
8 A cannibal returns: CCC B MMM
9 Two cannibals cross: C B MMMCC
10 One returns: CC B MMMC
11 And brings over the third: - B MMMCCC
18.
Cryptarithmetic
• Find anassignment of digits (0, ..., 9) to letters so that a
given arithmetic expression is true. examples: SEND +
MORE = MONEY and
FORTY Solution: 29786
+ TEN 850
+ TEN 850
----- -----
SIXTY 31486
F=2, O=9, R=7, etc.
19.
• State: mappingfrom letters to digits
• Initial State: empty mapping
• Operators: assign a digit to a letter
• Goal Test: whether the expression is
true given the complete mapping
Cryptarithmetic
Find an assignment of digits to
letters so that a given arithmetic
expression is true. examples:
SEND + MORE = MONEY and
FORTY Solution: 29786
+ TEN 850
+ TEN 850
----- -----
SIXTY 31486
F=2, O=9, R=7, etc.
• State: mapping from letters to digits
• Initial State: empty mapping
• Operators: assign a digit to a letter
• Goal Test: whether the expression is
true given the complete mapping
Note: In this problem, the solution is NOT a
sequence of actions that transforms the initial
state into the goal state; rather, the solution is a
goal node that includes an assignment of a digit to
each letter in the given problem.
20.
Remove 5 Sticks
Giventhe following
configuration of sticks, remove
exactly 5 sticks in such a way
that the remaining configuration
forms exactly 3 squares.
• State: ?
• Initial State: ?
• Operators: ?
• Goal Test: ?
21.
Water Jug Problem
Givena full 5-gallon jug and a full 2-gallon jug, fill the 2-gallon jug with
exactly one gallon of water.
• State: ?
• Initial State: ?
• Operators: ?
• Goal State: ?
5
2
22.
Water Jug Problem
•State = (x,y), where x is
the number of gallons
of water in the 5-gallon
jug and y is # of gallons
in the 2-gallon jug
• Initial State = (5,2)
• Goal State = (*,1),
where * means any
amount
Name Cond. Transition Effect
Empty5 – (x,y)→(0,y) Empty 5-gal.
jug
Empty2 – (x,y)→(x,0) Empty 2-gal.
jug
2to5 x ≤ 3 (x,2)→(x+2,0) Pour 2-gal.
into 5-gal.
5to2 x ≥ 2 (x,0)→(x-2,2) Pour 5-gal.
into 2-gal.
5to2part y < 2 (1,y)→(0,y+1) Pour partial
5-gal. into 2-
gal.
Operator table
5
2
23.
Graph Search
function graph-search(problem, QUEUEING-FUNCTION)
;; problem describes the start state, operators, goal test, and operator costs
;; queueing-function is a comparator function that ranks two states
;; graph-search returns either a goal node or failure
nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE))
closed = {}
loop
if EMPTY(nodes) then return "failure"
node = REMOVE-FRONT(nodes)
if problem.GOAL-TEST(node.STATE) succeeds
then return node.SOLUTION
if node.STATE is not in closed
then ADD(node, closed)
nodes = QUEUEING-FUNCTION(nodes,
EXPAND(node, problem.OPERATORS))
end
;; Note: The goal test is NOT done when nodes are generated
;; Note: closed should be implemented as a hash table for efficiency
24.
Graph Search Strategies
•Breadth-first search and uniform-cost search are optimal
graph search strategies.
• Iterative deepening search and depth-first search can follow
a non-optimal path to the goal.
• Iterative deepening search can be used with modification:
– It must check whether a new path to a node is better than the
original one
– If so, IDS must revise the depths and path costs of the node’s
descendants.