You are on page 1of 38

Problem Solving

One of our abilities of which we are most


proud, is the ability to solve problems
the ability to invent a sequence of actions to
achieve a goal, from some given situation

In some cases, the problems we tackle are


natural everyday ones
getting the keys out of a locked car
obtaining food for lunch

In other cases, we solve artificial problems


purely for amusement
Rubiks cube
word problems

Here, we will examine a class of problems


that can be solved using a single general
method

cps721 Artificial Intelligence Hector Levesque Problem Solving 1


Problem 1: Three Coins

Here is the first example:


Given 3 coins arranged as below, make them all
the same (i.e. either all heads or all tails) using
exactly 3 moves. By a move is meant flipping
one of the coins over (so that a head becomes a
tail, or a tail becomes a head)

H H T

Example moves:
after before

flip left
H H T T H T

flip middle
T T H T H H

cps721 Artificial Intelligence Hector Levesque Problem Solving 2


Problem 1: Solution

There are many solutions


flip middle, flip right, flip middle
middle right middle
HHH HTH HTT HHT
end start

flip left, flip left, flip right

right left left


HHH HHT THT HHT

and so on.

General properties:
all of them end up with HHH
why? after 1 move have even # of Ts
after 2 moves have odd # of Ts
after 3 moves have even # of Ts

all of them move the right coin 1 or 3 times


those that move it 1 time, move another 2 times

cps721 Artificial Intelligence Hector Levesque Problem Solving 3


Problem 2: Monkey

The monkey and bananas:


A monkey is in a room where a bunch of
bananas is hanging from the ceiling, too high to
reach. In the corner of the room is a box, which
is not under the bananas. The box is sturdy
enough to support the monkey if he climbs on it,
and light enough so that he can move it easily.
If the box is under the bananas, and the monkey
is on the box, he will be able to reach the
bananas.
How can the monkey get the bananas?

cps721 Artificial Intelligence Hector Levesque Problem Solving 4


The monkeys moves

What are the possible actions?


go to anywhere in the room
provided that monkey is not on the box

climb on the box


provided the monkey is at the box

climb off the box


provided the monkey is on the box

push the box anywhere


provided the monkey is at the box, but not on it

grab the bananas


provided the monkey can reach the bananas

These lead to states like this:

Nice try...

cps721 Artificial Intelligence Hector Levesque Problem Solving 5


Problem 2: Solution

Here is what the monkey needs to do:

end

grab the
bananas

climb onto
the box

push the box to


under the bananas

go to where
the box is

start

cps721 Artificial Intelligence Hector Levesque Problem Solving 6


States and operators

In general, problems of this form can be thought of as


characterized by
states: the configurations we pass through
what side each coin is showing
locations of monkey, bananas, and box

operators: ways of moving between states


flipping a coin
climbing on a box

initial state: the starting state(s) for a problem


HHT
as per first picture of monkey and bananas

goal state: the desired final state(s)


HHH or TTT
any state where the monkey has the bananas

The problem is always the same:


find a way of going from an initial state to a goal
state by applying a sequence of operators

cps721 Artificial Intelligence Hector Levesque Problem Solving 7


State Space

Generates a state space: the graph of all states


label each node with the state it represents
put an edge between S1 and S2 iff there is an
operator that takes you from S1 to S2
put an arrow on the edge to indicate direction
put a label on the edge to indicate the operator

TTH TTT

where

flip
HTH HTT middle
flip
left

THH THT
flip right

all edges are


bi-directional
HHH HHT

A problem: find a path in the graph from an initial


state to a goal state

cps721 Artificial Intelligence Hector Levesque Problem Solving 8


Using Prolog

Would like to solve problems of this type


using Prolog:
We tell it
the initial state, goal state, operators

It should tell us
a list of moves that solve the problem

How?

It will have to reason about the problem


If I was in state S and I did move M, that would
put me into state S.
I start in an initial state. I would like to end up
in a goal state.

Along the way, it will need to keep track of


the moves it needs to make.

cps721 Artificial Intelligence Hector Levesque Problem Solving 9


Getting to any state

For a state S to be reachable from an initial


state, there are only two general rules:
1. if S is an initial state, then S is trivially
reachable with no moves;

2. if the state S is reachable using moves


[Mn, Mn-1, ..., M1]
and
there is a move M which takes you
from state S to state S,
then state S is reachable using moves
[M, Mn, Mn-1, ..., M1].

new move at front of list


For example
the state HTH of the coin problem is reachable
using moves [flip_right, flip_middle],
and there is a move which goes from HTH to HHH:
its M = flip_middle
so the state HHH is reachable
using [flip_middle, flip_right, flip_middle]
last first

cps721 Artificial Intelligence Hector Levesque Problem Solving 10


A Prolog problem solver

The predicate reachable(S,L) means the state S


is reachable using list of moves L

reachable(S,[]) :- An initial state S is reachable


initial_state(S). and no moves are required

reachable(S1,[M|L]) :- If S is reachable using moves L,


and there is a legal move M from
reachable(S,L),
S to S1, then S1 is reachable
legal_move(S1,M,S). using moves [M | L].

To solve a problem, we try to reach a goal state:

solve_problem(L) :- A problem is solvable using a list


reachable(S,L), of moves L if some goal state S
is reachable using L
goal_state(S).

This is a general problem solver. For each specific


problem we only need to specify the predicates:
initial_state(S)
goal_state(S)
legal_move(S1,M,S)

cps721 Artificial Intelligence Hector Levesque Problem Solving 11


Representing the 3 coins

States: [left coin, middle coin, right coin],


where each has a value of h or t

Operators: flip_left, flip_middle, flip_right


with the obvious effects

Initial state: [h,h,t]


initial_state([h,h,t]).

Goal state: [h,h,h] or [t,t,t]


goal_state([X,X,X]).

Legal moves: for each flip


S S
legal_move([X,Y,Z],flip_middle,[X1,Y1,Z1])

provided that
X = X1,
Y and Y1 are flip sides,
Z = Z1.
which gives us...

cps721 Artificial Intelligence Hector Levesque Problem Solving 12


In Prolog

The 3 coin program: the general solver +

initial_state([h,h,t]).
goal_state([X,X,X]).
legal_move([X,Y,Z],flip_left,[X1,Y,Z]) :-
flip(X,X1).
legal_move([X,Y,Z],flip_middle,[X,Y1,Z]) :-
flip(Y,Y1).
legal_move([X,Y,Z],flip_right,[X,Y,Z1]) :-
flip(Z,Z1).
flip(h,t).
flip(t,h).

want exactly
The query: 3 moves

solve_problem([M3,M2,M1]).

The result:
M3 = flip_right
M2 = flip_left
M1 = flip_left first move

cps721 Artificial Intelligence Hector Levesque Problem Solving 13


Tracing the solver
reachable(S,[M3,M2,M1]),
goal_state(S)

reachable(Sa,[M2,M1])
legal_move(S,M3,Sa),
goal_state(S)

reachable(Sb,[M1]),
legal_move(Sa,M2,Sb),
legal_move(S,M3,Sa),
goal_state(S)

reachable(Sc,[]),
legal_move(Sb,M1,Sc),
legal_move(Sa,M2,Sb),
legal_move(S,M3,Sa),
goal_state(S)

initial_state(Sc),
legal_move(Sb,M1,Sc),
legal_move(Sa,M2,Sb),
legal_move(S,M3,Sa),
goal_state(S)
Sc= [h,h,t]

legal_move(Sb,M1,[h,h,t]),
legal_move(Sa,M2,Sb),
legal_move(S,M3,Sa),
goal_state(S)
cps721 Artificial Intelligence Hector Levesque Problem Solving 14
Tracing continued
M1=flip_left, Sb=[Xa,h,t]

flip(Xa,h),
legal_move(Sa,M2,[Xa,h,t]),
legal_move(S,M3,Sa),
goal_state(S)
Xa=t

legal_move(Sa,M2,[t,h,t]),
legal_move(S,M3,Sa),
goal_state(S)
M2=flip_left, Sa=[Xb,h,t]

flip(Xb,t),
legal_move(S,M3,[Xb,h,t]),
goal_state(S)
Xb=h

legal_move(S,M3,[h,h,t]),
goal_state(S)
M3=flip_left, S=[X,h,t] M3=flip_right, S=[h,h,Z]

M3=flip_middle, S=[h,Y,t] flip(Z,t),


flip(X,h), goal_state([h,h,Z])
goal_state([X,h,t])
Z=h
flip(Y,h),
X=t
goal_state([h,Y,t])
Y=t
goal_state([h,h,h])
goal_state([t,h,t])

goal_state([h,t,t]) success
fail

fail

cps721 Artificial Intelligence Hector Levesque Problem Solving 15


Execution notes

The Prolog program solve_problem works in two


phases:
first it reduces the problem to a number of
legal_move subgoals using reachable
solve_problem([M3,M2,M1])

initial_state(S1),
legal_move(S2,M1,S1),
legal_move(S3,M2,S2),
legal_move(S,M3,S3),
goal_state(S)

then it selects an initial state and tries to find


appropriate legal moves from there to the goal

The list returned by solve_problem shows the


moves in reverse order: the first element of the list is
the one closest to the goal

When testing your own programs, it is a very good


idea to make sure that reachable works correctly
with intermediate states, close to an initial state.
e.g. reachable([h,h,h],[M])
reachable([t,h,h],[M2,M1])

cps721 Artificial Intelligence Hector Levesque Problem Solving 16


Getting bananas in Prolog

States: [bananas, monkey, box, OnBox?, HasBananas?]


where first 3 are locations and last 2 are y/n
For simplicity, assume 4 locations:
loc1, loc2, loc3, loc4

Operators: climb_on, climb_off, grab, go(X), push(X).

The program:

initial_state([loc3,loc4,loc1,n,n]).
1 2 3 4
goal_state([_,_,_,_,y]).

legal_move([B,L,L,y,H],climb_on,[B,L,L,n,H]).
legal_move(S1,climb_off,S) :-
legal_move(S,climb_on,S1).
legal_move([L,L,L,y,y],grab,[L,L,L,y,n]).
legal_move([B,X,L,n,H],go(X),[B,M,L,n,H]) :-
loc(X), not(X=M).
legal_move([B,X,X,n,H],push(X),[B,M,M,n,H]) :-
loc(X), not(X=M).

loc(loc1). loc(loc2). loc(loc3). loc(loc4).

cps721 Artificial Intelligence Hector Levesque Problem Solving 17


Banana queries

Responses to queries:
solve_problem([M3,M2,M1]). no 3 step
solution
no

solve_problem([M4,M3,M2,M1]).
M4 = grab
M3 = climb_on a unique
4 step
M2 = push(loc3)
solution
M1 = go(loc1) ; first
move
no

solve_problem([M5,M4,M3,M2,M1]).
M5 = grab
M4 = climb_on several
M3 = push(loc3) 5 step
M2 = push(loc2) solutions
M1 = go(loc1) ;
... (many other solutions)

Can also do:


solve_problem(L).
L = [grab,climb_on,push(loc3),go(loc1)].
yes

cps721 Artificial Intelligence Hector Levesque Problem Solving 18


A rough trace

reachable(G,L),
goal_state(G)

is there a 0 initial_state(G),
move solution? goal_state(G) reachable(S1,L1),
X legal_move(G,A1,S1),
goal_state(G)

initial_state(S1),
is there a 1
legal_move(G,A1,S1),
move solution?
goal_state(G)
reachable(S2,L2),
X legal_move(S1,A2,S2),
legal_move(G,A1,S1),
goal_state(G)
initial_state(S2),
is there a 2 legal_move(S1,A2,S2),
move solution? legal_move(G,A1,S1),
goal_state(G) reachable(S3,L3),
X legal_move(S2,A3,S3),
legal_move(S1,A2,S2),
legal_move(G,A1,S1),
goal_state(G)
initial_state(S3),
legal_move(S2,A3,S3),
is there a 3
legal_move(S1,A2,S2),
move solution? reachable(S4,L4),
legal_move(G,A1,S1),
goal_state(G) legal_move(S3,A4,S4),
legal_move(S2,A3,S3),
X legal_move(S1,A2,S2),
legal_move(G,A1,S1),
initial_state(S4), goal_state(G)
legal_move(S3,A4,S4),
is there a 4 legal_move(S2,A3,S3),
move solution? legal_move(S1,A2,S2),
legal_move(G,A1,S1),
goal_state(G)

eventually succeeds ...

cps721 Artificial Intelligence Hector Levesque Problem Solving 19


Warning: unbounded search

As can be seen, the predicate reachable first looks


for solutions of length 0, then 1, then 2, then 3, etc.

This means that it will run forever if there happens to


be no sequence of moves that works!

So it is much safer to first bound the length of the list.

We can write a predicate max_length(L,N) that


holds when the length of list L is not more than N.
max_length([],N).
max_length([_|L],N1) :-
N1 > 0,
N is N1-1,
max_length(L,N).

Then we get: max_length(X,2).


X = [] ;
X = [_4526] ;
X = [_4526,_4531] ;
no

And so we can use


max_length(L,7), solve_problem(L).
L = [grab,climb_on,push(loc3),go(loc1)]

cps721 Artificial Intelligence Hector Levesque Problem Solving 20


Reversing a list

How about listing the actions in the correct order?

We define a predicate reverse(L1,L2) to mean that


L2 has the elements of L1 in reverse order.
This is most easily defined using an auxiliary
predicate rev(L1,L2,L3) which holds when L3 is
made up of the elements of L1 in reverse order
followed by those of L2 in regular order

reverse(L1,L2) :- rev(L1,[],L2).
rev([],L,L).
rev([X|L1],L2,L3) :- rev(L1,[X|L2],L3).

reverse([1,2,3], L)

rev([1,2,3], [ ], L)

rev([2,3], [1], L)

rev([3], [2,1], L)

rev([ ], [3,2,1], L)
L = [3,2,1]
!
Then we pose a query like:
solve_problem(L), reverse(L,In_order).
cps721 Artificial Intelligence Hector Levesque Problem Solving 21
Next problem: 15-puzzle

The 15-puzzle consists of 15 consecutively numbered


tiles located in a 4 4 grid. The object of the puzzle is
to move the tiles within the grid so that each tile ends
up at its correct location, as shown:
1 2 3 4 1 6 3 8

5 6 7 8 10 2 7 15

9 10 11 12 13 5 4

13 14 15 9 14 11 12

goal state initial state

This can be handled in Prolog as before:


States: [pos1, pos2, pos3, ..., pos16]
where each posi is the number of the tile in that
position in the grid: 0 ! posi ! 15
pos5 = 10 means position 5 has tile 10
pos12 = 0 means position 12 is vacant

goal state: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0]


initial state: [1,6,3,8,10,2,7,15,13,5,4,0,9,14,11,12]

Operators: move a tile up, down, left, or right


assuming the vacant spot is adjacent

cps721 Artificial Intelligence Hector Levesque Problem Solving 22


Simplified program

Here is the program for the 2 3 version of the puzzle


1 5
initial_state([0,1,5,4,3,2]).
4 3 2

goal_state([1,2,3,4,5,0]).

legal_move([C,A,B,0,D,E],up(C),[0,A,B,C,D,E]).
legal_move([A,D,B,C,0,E],up(D),[A,0,B,C,D,E]).
legal_move([A,B,E,C,D,0],up(E),[A,B,0,C,D,E]).
legal_move(S1,down(X),S2) :-
legal_move(S2,up(X),S1).
legal_move([A,0,B,C,D,E],left(A),[0,A,B,C,D,E]).
legal_move([A,B,0,C,D,E],left(B),[A,0,B,C,D,E]).
legal_move([A,B,C,D,0,E],left(D),[A,B,C,0,D,E]).
legal_move([A,B,C,D,E,0],left(E),[A,B,C,D,0,E]).
legal_move(S1,right(X),S2) :-
legal_move(S2,left(X),S1).

For which we get:


solve_problem(L).
L = [left(5), up(2), right(3), down(5),
left(2), up(3), left(1)] .
yes
first
move

cps721 Artificial Intelligence Hector Levesque Problem Solving 23


Scaling up?

As the problem to be solved becomes more


and more complex, two difficulties arise:
1. Representation of state
It becomes increasingly awkward and inefficient to
deal with explicit states and the legal_move predicate.
state: [aspect1, aspect2, ... aspect10000]
Although all the aspects of a state can be changed by
some operator, each operator only changes a very
small number of them.
sliding a box under the bananas does not affect the
position of the bananas, the color of the box, whether or
not the window is open, objects in other rooms, ..., the
current Prime Minister, the price of tea in China, ....

2. Searching
Blindly searching (in phase two) for n moves
becomes infeasible.
legal_move( ), ..., legal_move( )
the number of states that may
need to be examined grows
exponentially in the number 3
of required moves n
9
Weve been lucky so far! 27
... ... ...
81

cps721 Artificial Intelligence Hector Levesque Problem Solving 24


Search strategy 1

Many problems have a natural notion of sub-


problem that can be solved independently
and then combined
15-puzzle: 1 2 3 4

5 - - - 6 7 8

9 - - - 10 - - 11 12

13 - - 14 - 15

first goal next final goal

Why does this help?


Suppose a problem can be partitioned into
subproblems A and B such that
A can be solved in 15 moves
B can be solved in 10 moves
so that 25 moves are sufficient overall.

solve each subproblem independently:


215 + 210 " 33,000 states, at worst
Assuming just two
vs. solve the problem directly: possible moves at
each choice point
225 " 33,000,000 states, at worst

cps721 Artificial Intelligence Hector Levesque Problem Solving 25


Search strategy 2

The search strategy weve been using so far:


for state S, choose a legal move: get new S#
check to see if remaining moves can be found
if that fails, choose another legal move: get S##

initial state
possibly the entire tree
below S# will be explored S#
before even looking at S##
what is below S##

this is depth-first search


... goal state

A better strategy: best-first search


keep a big list of all states that have yet to be
explored in the search (and how we got there)
at the next step, find the legal moves for
the most promising state on the list
add these new states to the list

Need to determine most promising states


cps721 Artificial Intelligence Hector Levesque Problem Solving 26
Estimating the value of a state

Many problems have a natural measure that


can be used to estimate how far a state is
from a goal state.
Then, the most promising state during the
search is the one which, according to the
estimate, is the closest to a goal state.

For example, in the 15-puzzle, we can use


the Manhattan distance to the goal state
For each tile, the minimum number
of vertical and horizontal moves 6

required to move the tile from


where it is now to the goal state
dist for tile 6 is 3 moves
Then sum over every tile

This number is easy to calculate and is a


lower bound on how many moves will
actually be required from an initial state.
It is only a lower bound, since tiles get
in the way of each other

cps721 Artificial Intelligence Hector Levesque Problem Solving 27


Planning

Much of the reasoning research in AI has


centered around planning
problem solving (of the sort we have seen)
where the moves are physical actions to be
carried out by an autonomous agent / robot

Typical use:
present a planning problem: some goal we are
interested in achieving
solve the problem: find a sequence of actions
that achieves the goal
send the actions to the robot for execution

However, it is not feasible in practice to use


the representation of a state as an explicit list
in typical planning problems, there are too many
objects with too many properties to list them all
in each clause of legal_move
we want to use the fact that most objects are
unaffected by most actions!

cps721 Artificial Intelligence Hector Levesque Problem Solving 28


A representation strategy

The purpose of a state is to track various aspects of


the world affected by actions
the action climb_on changes the OnBox? aspect of
the state from n to y
the action push(X) changes the box location to X

When it is too awkward to enumerate all the aspects of


a state in a big list, there is another possible strategy:
just keep track of what actions were performed
from the initial state to get to the current state
calculate what holds in a state as needed
this will depend on
what actions were performed (in what order)
what was true initially

For example, suppose we want to know the location of the


box given only a list of the actions performed so far
if push(X) is the most recent push action in the list,
then the box is located at that X
if there is no push(X) action, then the box is located
wherever it was initially

cps721 Artificial Intelligence Hector Levesque Problem Solving 29


Situations and fluents

A list of actions used to represent a state is called a


situation
[ ] the initial state, where nothing has
yet been done
[a1] the state that results from performing
the action a1 (in the initial state)
[a2, a1, a1] the state that results from performing
the action a1 twice and then a2

initial
a2 a1 a1

this one

We will need predicates whose truth depends on the


current situation. These are called fluents
on_box(s) the monkey is on the box in
situation s
has_bananas(s) the monkey has the bananas
in situation s
location(x,l,s) the location of x (monkey or box)
is l in situation s

Convention: the last argument of a fluent is a situation

cps721 Artificial Intelligence Hector Levesque Problem Solving 30


Planning with situations and fluents

We would like to use the same Prolog program as


before for solve_problem and reachable.

However, observe that now


there is only a single initial situation: [].
the legal moves always go from a situation S to
a situation [A|S], provided the action A is
possible to execute.

So we add the following 2 clauses to the general


problem solver: new
predicate
initial_state([]).
legal_move([A|S],A,S) :- poss(A,S).

For each specific problem, what is left to specify is:


1. how goal_state is defined in terms of fluents
2. how poss is defined, for each action
3. how the individual fluents are defined
which ones hold in the initial state
how they are affected by actions.

cps721 Artificial Intelligence Hector Levesque Problem Solving 31


Using fluents

Because a situation does not mention explicitly what


does or does not hold in a state, we use fluents to
characterize the goal state:
goal_state(S) :- has_bananas(S).

Similarly, fluents will be used to state when an action


is possible to execute in a situation:
poss(climb_off,S) :- on_box(S).
poss(climb_on,S) :-
location(monkey,L,S),
location(box,L,S),
not(on_box(S)).
poss(grab,S) :-
location(monkey,L,S),
Note: not a
banana_location(L), fluent
on_box(S).
poss(go(X),S) :-
loc(X),
location(monkey,L,S),
not(X=L),
not(on_box(S)). These are called
precondition axioms
poss(push(X),S) :- ... for the actions

cps721 Artificial Intelligence Hector Levesque Problem Solving 32


Defining fluents

Finally, we need to state which fluents hold in


which situations. This is typically done in two
steps:

First, we state what fluents hold in the initial


situation [ ]:
location(monkey,loc4,[]).
location(box,loc1,[]).
/* all the remaining fluents fail for [] */

Then, we characterize whether a fluent holds


in any non-initial situation [A | S].
This involves partitioning the actions into
those that can make the fluent true
those that can make the fluent false
those that can leave the fluent unchanged
from what it was in the previous situation

cps721 Artificial Intelligence Hector Levesque Problem Solving 33


Examples

For being on the box, climbing on the box makes it


true, climbing off makes it false, and all other actions
leave it unchanged.
on_box([climb_on|S]). The money is on the box
if it just did a climb_on action
on_box([A|S]) :- or
the action it just did was not
not(A=climb_off), climb_off and it was already
on_box(S). on the box.

For having the bananas, the grab action makes it true,


and all other actions leave it unchanged.
The money has the bananas
has_bananas([grab|S]). if it just did a grab action
or
has_bananas([A|S]) :- it already had the bananas
has_bananas(S). prior to the action it just did.

For the monkey being at x, going to x or pushing the


box to x makes it true, going to or pushing to anywhere
else makes it false, and the rest leave it unchanged.
location(monkey,X,[go(X)|S]).
location(monkey,X,[push(X)|S]).
location(monkey,X,[A|S]) :- These are called
not(A=go(_)), successor-state
not(A=push(_)), axioms for the
location(monkey,X,S). fluents

cps721 Artificial Intelligence Hector Levesque Problem Solving 34


Reformulated monkeys & bananas
goal_state(S) :- has_bananas(S).

poss(grab,S) :- on_box(S),
banana_location(L), location(box,L,S).
poss(climb_on,S) :- location(monkey,L,S),
location(box,L,S), not(on_box(S)).
poss(climb_off,S) :- on_box(S).
poss(go(X),S) :- loc(X), location(monkey,L,S),
not(X=L), not(on_box(S)).
poss(push(X),S) :- loc(X), location(monkey,L,S),
location(box,L,S), not(X=L), not(on_box(S)).

on_box([climb_on|S]).
on_box([A|S]) :- not(A=climb_off), on_box(S).
has_bananas([grab|S]).
has_bananas([A|S]) :- has_bananas(S).
location(monkey,X,[go(X)|S]).
location(monkey,X,[push(X)|S]).
location(monkey,X,[A|S]) :- not(A=go(_)),
not(A=push(_)), location(monkey,X,S).
location(box,X,[push(X)|S]).
location(box,X,[A|S]) :- not(A=push(_)),
location(box,X,S).

location(monkey,loc4,[]).
location(box,loc1,[]).
/* all the remaining fluents fail for [] */
loc(loc1). loc(loc2). loc(loc3). loc(loc4).
banana_location(loc3).

cps721 Artificial Intelligence Hector Levesque Problem Solving 35


Why is this good?

Although much more verbose than the previous


representation which used explicit states, this version
has one very significant advantage:

we are able to describe the problem


incrementally without having to know in
advance all possible actions and fluents

Consider, for example, on_box. Once we decide that


there are only two relevant actions (climb_on making
it true, and climb_off making it false), we are done:
on_box([climb_on|S]). $ what makes it true
on_box([A|S]) :-
not(A=climb_off), $ what makes it false
on_box(S).

Even if we now decide to introduce new properties,


(such as box_colour) and new actions which affect
them (such as paint_box), nothing has to change in
the above.

This has the effect of making complex states with very


large numbers of properties conceptually manageable.

cps721 Artificial Intelligence Hector Levesque Problem Solving 36


Controlling a robot

Even taking into account the representation and


search strategies we have seen, in practice, it often
remains impractical to use planning as a way of
generating actions for a robot

Here at the University of Toronto, we have been


pursuing a different approach:
characterize actions and fluents as we did here
instead of goals to be achieved, give the robot
high-level programs to execute
these programs are similar to goals, but can
have strong hints about what to do and when
do this program then do that program
repeat this program until this condition holds
do this program or do that program
etc.

the job of the robot is to find (using these hints)


a sequence of actions that constitute a legal
execution of the program
a working prototype exists ...

cps721 Artificial Intelligence Hector Levesque Problem Solving 37


Other complications

In reasoning about actions and their effects,


a number of other complications need to be
dealt with, such as
actions with duration
going to another room vs. turning on a light
planning needs to be sensitive to temporal
constraints

continuous actions
dropping a ball
filling a container with water

exogenous actions
performed by other agents (or nature)

sensing actions
some actions, like reading a thermometer, are
not used to change the world, but only to change
what is known about the world

Handling these properly in a planning context


remains a current topic of AI research
cps721 Artificial Intelligence Hector Levesque Problem Solving 38

You might also like