Planning in AI
Planning in AI
R
els
ng
E
Artificial
ls. RIntelligence
R
ge s.
UnitE 4-1 Planning
n
E ngel
. R
els . R
ng
2020-2021 Odd BE CSE VII ls
semester
e
E ng
E
. R Engels. R
els . R
ng els
E ng
E
. R
els . R
ng els
E ng
E 1
Unit 4 – Planning
• Focus . R
els
– The focus here is deterministic planning n g
E
• Environment is fully observable
. R
• Results of actions is deterministic ls
ge . R
– Relaxing the above requiresEndealing with uncertainty els
ng
R contingency, exploration
• Problem types: sensor-less, E
ls.
• Planning ‘communities’ ge in AI . R
E n els
– Logic-based: Reasoning About Actions & Change ng
R E
s. representations: Classical AI Planning
– Less formal
l
ge . R
En
– Uncertainty (UAI): Graphical Modelsesuch ls as
ng
R E
• Markov Decision Processes (MDP), Partially Observable MDPs, etc.
ls.
g e . R
En els
ng
E 3
Actions, events, and change
. R
l
• Planning requires a representation of time
e s
ng
– E
to express & reason about sequences of actions
. Rthe world
– to express the effects of actions son
l
ge . R
• Propositional Logic E n els
ng
– does not offer a representation
R for time E
.
ls needs to be repeated for eachR step
ge
– Each action description .
E n els
• Situation Calculus ng
R E
. FOL
– Is basedlson
g e . R
– EachEntime step is a ‘situation’ els
ng
E about actions & change
–R Allows to represent plans and reason
ls.
g e . R
En els
ng
E 4
‘Famous’ Problems
• Frame problem . R
els
– Representing all things that stay the same n g from one situation to the next
E
– Inferential and representational R
ls.
– What happens to a gold bar placed ge on a slide? . R
E n els
• Qualification problem ng
R E
s.
– Defining the circumstances
l under which an action is guaranteed to work
ge . R
– Example: what Eifnthe gold is slippery or nailed down, els etc.
ng
• Ramification R problem E
ls.
ge
– Proliferation of implicit consequences of. Ractions as actions may have secondary
E n els
consequences ng
R E
ls.– Examples: How about the dust on the gold?
g e . R
En els
ng
E 5
Planning Languages
. R
els
• Languages must represent.. Eng
– States . R
els R
– Goals ng ls.
E ge
E n
– Actions . R
els R
ng ls.
• Languages must
E be ge
E n
– Expressive
. R for ease of representation
els R
g s.
En
– Flexible for manipulation by l
ng algorithms
e
R E
ls.
e R
E ng els.
ng
E 6
State Representation
. R
• A state is represented with a conjunction e s
l of positive literals
n g
– fluents that are ground, functionless Eatoms
.R
– a fluent is a condition that canlschange over time
ge . R
• Using En els
ng
– Logical Propositions:. RPoor Unknown E
els R
g
– FOL literals: At(Plane1,SFO) At(Plane2,JFK) ls.
En ge
• FOL literalsRmust be ground & function-free E n
ls.
ge
– Not allowed: R
At(x,y) [non-ground]or sAt(Father(Fred),Sydney)[Function],
.
E n el
poor (negation, false fluent) ng
R E
.
•elsClosed World Assumption R
ng ls.
E – What are not stated aregeassumed false
En
Action Representation
. R
els
• A set of ground (variable-free) actions
ng can be represented by a
E
single action schema R
ls.
– The schema is a lifted representation
ge . R
E n els
– it lifts the level of reasoning from propositional logic ng to a restricted
R E
subset of first-order
ls. logic
ge . R
En els
ng
R E
ls.
ge . R
En els
ng
R E
ls.
ge . R
En els
ng
E
Action Representation
. R
els
• Action Schema ng At(AI,CJB),Plane(AI),
E Airport(CJB), Airport(MAA)
– Action name
. R
– Preconditions
els Fly(AI,CJB,MAA) R
– Effects ng ls.
E g e
• Example E n
At(AI,MAA), At(AI,CJB)
. R
Action(Fly(p,from,to),els R
ng ls.
E e
PRECOND: At(p,from) Plane(p) Airport(from) gAirport(to)
E n
R
EFFECT:s.At(p,from) At(p,to))
l
e Effects are split into ADD list and R DELETE list
• Sometimes, g ls.
En ge
RESULT(s, a) = [s − DEL(a)] ∪ n
ADD(a)
E
. R
els s- state, a-action, s’-new state R
g s.
En DEL(a) – actions available el
g at s, ADD(a) – actions available at s’
E n
Applying an Action
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
Example: Spare Tire Problem
A PDDL description of
els problem:
els R
ng ls. Four actions:
E ge 1. Removing spare from
E n trunk,
. R 2. Removing flat tire
els R from axle,
ng ls. 3. Putting spare on axle,
E ge and
E n
. R 4. Leaving car
els R
unattended overnight
E ng els. problem:
ng
R
Solution E
ls.
ge . R
E n els
ng
E
Example: Blocks World
. R
• Initial state, Goal
els
• Actions: n g
E
• Move(b,x,y) (b-block, x-from, y – to) R
ls.
• MoveToTable(b,x) ge . R
En pre-condition and effects els
• Describe init, goal and actions(with
ng
R E
• Then give the solutionsplan
l .
g e . R
En els
ng
R E
ls.
g e of the blocks-world problem: . R
ls
A PDDL description
Goal is to E n one or more stacks of blocks, e
build
ng
R E
ls.can fit directly on top of another, or kept on the table
where the blocks can be stacked, but only one block
g e . R
En el s initial state goal state
g
En
Example: Blocks. RWorld
els
• Initial state, Goal n g
E
• Actions: Move(b,x,y), MoveToTable(b,x)
. R
els R A PDDL description of the
n g ls. blocks-world problem:
E e
E ng Goal is to build one or
els R
g ls. where the blocks can be
En ge stacked, but only one
E n block can fit directly on
. R top of another, or kept on
els R the table
g ls .
En ge
E n
. R
e ls R
g s .
En gel Solution?
E n
Example: Blocks. RWorld
els
• Initial state, Goal n g
E A PDDL description of the
• Actions: Move(b,x,y), MoveToTable(b,x)
. R blocks-world problem:
E n the table
. R
e ls R
g ls. Notice how the solution plan finding
En ge becomes extremely straight forward
els R
relevant states, starting at
precond
E n
G’ A G
effect
. R
e ls R
ng ls .
E
Represents a set of world g e
E n Represents a set of world
. R states states
els R
g s.
En gel
E n
© Daniel S. Weld 33
Planning Graphs
. R
s
• All of the heuristics can suffer from einaccuracies
l
ng
E
• A special data structure called a Planning Graph can be
. R
– used to give better heuristicelsestimates R
g s.
– applied to any of the search En techniques or another algorithmgel
E n
GRAPHPLAN . R
els R
• A planning problem g .
asks if we can reach eals goal state from the
En g
initial state E n
. R
ls
• A treeEnof ge all possible actions from . R
ls initial state to successor states,
ge
and their successors, and so on n
E to answer
. R
ls
e – Can we reach state G from Rstate S0
g s.
En el
g size and hence impractical
n
– This tree is of exponential
E 34
Planning Graphs
. R
• A planning graph = polynomial size e s
lapproximation to the
ng
exhaustively indexed tree E
– can be constructed quicklyels. R R
g s.
– May not answer definitively En whether G is reachable gfromel S0, but can
E n
estimate the number . R of steps
els R
g .
• The estimate is En always correct when it greports els the goal is not
E n
reachable ls. R
ge . R
• And it Ennever overestimates the e s
lnumber of steps
ng
E
. R it is an admissible heuristic
• lsSo
g e . R
En els
ng
E 35
Planning Graphs - 2
. R
• Planning graph is a directed graphgeorganized ls into levels
E n
– First a level S0 for the initial state, consisting of nodes representing
each fluent (a condition that . R change over time) that holds in S
can
els R 0
n g ls.
– then a level A0, consisting E of nodes for each ground gaction e that might
E n
be applicable in Sls0. R
ge . R
– then alternatingEn levels Si followed by Ai gels
E n
– until we . R
reach a termination condition
els R
g .
• PlanningEn graphs work only forgpropositional els planning problems
E n
.–R The problems with no variables
els R
g s.
En gel
E n
36
Planning Graphs - 3
. R
• Roughly
els
– ng I
Si contains all the literals that could hold atEtime
R
• depending on the actions executed at preceding
.
time steps
ls R in Si
– If it is possible that either P or ¬Pgecould hold, then both will be represented
n ls.
E
– Ai contains all the actions that could have their preconditions satisfied e
g at time I
E n
• Why roughly? . R
els R
g ls.
En only a restricted subset of thegepossible
– Planning graph records negative interactions
among actions; E n
. R
– therefore,
e s
l a literal might show up at level Sj when
R actually it could not be true until a
g if at all
laterEnlevel, ls.
ge
– It is guaranteed thought that A literalEwilln never show up too late
. R
•elsDespite the possible error, the Rlevel j at which a literal first appears is a good
ng ls.
E estimate of how difficult itgeis to achieve the literal from the initial state
En 37
Planning Graphs – Example problem
. R
els
ng
E
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
38
Planning Graphs – Example
. R
• The planning graph for the “have cake and eat cake too” problem
e ls
• Up to level S2 ng
• Rectangles indicate actions E
• small squares indicate persistence actions R
l
• Straight lines indicate preconditions and effectss.
g e . R
• Mutex links are shown as curved gray lines
E n els
• (not all mutex links are shown)
ng
R the persistence actions for those literals
• If two literals are mutex at Si, then E
ls .
will be mutex at Ai e
g link . R
• need not draw thatnmutex
E e ls
g
R En
ls.
ge . R
E n els
ng
R E
ls.
ge . R
E n els
ng
E 39
Planning Graphs – Example
R. its effects at
ls
• Each action at level Ai is connected to its preconditions at Si and
e
Si+1 n g
• So a literal appears because an action caused it AND a E literal can persist if no
action negates it
• Known as persistence action or no-op ls.
R
ge . R
• For every literal C, add to the problem anpersistence
E
action with precondition C
els
and effect C
ng
R
• Level A0 in figure shows one “real” action, Eat (Cake) E
ls. actions drawn as small square boxes
e
• along with two persistence
g . R
E n els
g
R En
ls.
ge . R
E n els
ng
R E
ls.
ge . R
E n els
ng
E 40
Planning Graphs – Example
•
R
Level A0 contains all the actions that could occur in state S0 ls.
ge from occurring together
•
•
Also records conflicts between actions that would prevent
E n them
Grey links indicate mutual exclusion (or mutex) links
• For example, Eat (Cake) is mutually exclusive withRthe persistence of either Have(Cake) or ¬ Eaten(Cake)
• Also Have(Cake) and Eaten(Cake) are mutex ls .
g estates . R
• n
S1 represents a belief state: a set of possible
E els
•
n
Continue alternating between state level Si and action level Ai until two consecutiveglevels are identical
• Graph has leveled off R E
ls. choosing among actions
•
e
Planning graph does not require
g . R
E n
• which would entail combinatorial search
els
• ng
It just records the impossibility of certain choices using mutex links
E
. R
els R
E ng els.
ng
R E
ls.
ge . R
E n els
ng
E 41
Mutex Relation
. R if any of the following three
e ls
• Mutex relation holds between two actions at a given level
conditions holds: ng
• Inconsistent effects:
E
– One action negates an effect of the other . R
e ls have inconsistent effects because theyRdisagree on the
ng
– Ex: Eat (Cake) and the persistence of Have(Cake)
ls.
effect Have(Cake) E ge
• Interference: R En
.
ls is the negation of a precondition of the other
e
– one of the effects of one action
g . R
En with the persistence of Have(Cake) by negating
– Ex: Eat (Cake) interferes e ls its precondition
n g
• Competing needs:
R E
s .
– One of the lpreconditions of one action is mutually exclusive with a precondition of the other
ge . R
En
– Ex: Bake(Cake) and Eat (Cake) are mutex because they
els compete on the value of the Have(Cake) precondition
• Inconsistent support ng
R E
ls.– A mutex relation holds between two literals at the same level if one is the negation of the other
g . R achieve the two literals is mutually exclusive
e – or if each possible pair of actions that could
En els
ng
E 42
Planning Graph complexity
. R
e ls
ngthe planning problem
• A planning graph is polynomial in the size Eof
• For a planning problem with l literalsRand a actions
.
elsl2 mutex links, and
– each Si has no more than l nodes and
g . R
En (including the no-ops), (a + l)2 mutex
– each Ai has no more than a + l nodes e s
llinks, and
ng
R
2(al + l) precondition and effect links E
ls.
• Thus, an entire graph gewith n levels has a size of O(n(a +. R
l) 2
)
E n els
• The time to build the graph has the same complexity ng
R E
ls.
g e . R
En e ls
ng
R E
ls.
ge . R
En els
ng
E 43
The GRAPHPLAN algorithm
. R
els
ng
E
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
e ls R
g .
algorithm repeatedly adds a level toelasplanning graph with EXPAND-GRAPH
En
• The GRAPHPLAN
g GRAPHPLAN calls EXTRACT-SOLUTION to search for a
• Once all the goals show up as nonmutex in the graph,E n
R
. that solves the problem
lsplan
R again, terminating with failure when there is no reason to go on
e• If that fails, it expands another level and tries
g s.
En g el
E n
44
Planning Graphs – Spare tire example
. R
els
ng
E
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
45
Planning Graphs – Spare tire example
. R
els
ng
E
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
. R
els R
ng ls.
E ge
E n
46
Planning Graphs – Spare tire example
. R
• GRAPHPLAN initializes the planning graph to a one-level e s
l (S0) graph representing the initial state
n g the problem description’s initial state are
E
– The positive fluents and the relevant negative fluents from
shown
. R (such as Tire(Spare)) and the irrelevant negative literals
ls
– Not shown are the unchanging positive literals
e R
ng in S0, so we need not call EXTRACT-SOLUTION
• The goal At(Spare, Axle) is not present ls.
E ge
– There is no solution yet
R En
.
• EXPAND-GRAPH adds into Als0 the three actions whose preconditions exist at S 0
ge . R
n
– all the actions exceptEPutOn(Spare, Axle) els
ng
– along with persistence actions for all the literals in S
R 0 E
• The effects of ls . actions are added at level S
the
ge 1
. R
En
• EXPAND-GRAPH then looks for mutex relations els adds them to the graph
and
n g
R
• At(Spare, Axle) is still not present in S E
ls . 1
E
• Hence a solution might exist, and EXTRACT-SOLUTIONn will try to find it
• Can. Rformulate EXTRACT-SOLUTION as a Boolean constraint satisfaction problem (CSP)
ls as a as a backward search problem, whereR
•geOr
n ls. to a level in the planning graph and a set of unsatisfied goals
E • each state in the search contains a
g e
pointer
En 49
Planning Graphs – Spare tire example
. R
els
ng
E
. R
els R
ng ls.
E ge
E n
. R
els R
• Start at S ng
with the goalEAt(Spare, Axle) els.
• The only choice for achieving the goal set is PutOn(Spare, Axle) Eng
2
s
• Can only take to. aRsearch state at S with goals At(Spare, Ground) and ¬ At(Flat, Axle)
e l Ground) can be achieved only by Remove(Spare,
1
R Trunk ), and
g
• At(Spare, .
• ¬ At(Flat, els
En Axle) can be achieved only by eithergRemove(Flat , Axle) or LeaveOvernight
E n
• But LeaveOvernight is mutex with Remove(Spare, Trunk )
R
. • So the only solution is to choose Remove(Spare, Trunk ) and Remove(Flat, Axle)
ls R At(Spare, Trunk ) and At(Flat, Axle)
e• Brings us to a search state at S with the goals
g s.
En • Both of these are present in the state, e lso we have a solution
0
ng
• The actions Remove(Spare, TrunkE ) and Remove(Flat, Axle) in level A , followed by PutOn(Spare, Axle) in A
0 1 50
Planning Graphs – Summary
. R
• Planning is a search problem els
n g
E
– Possible to apply search heuristics to improve the process
. R
• One approach is to construct els a “graph” of the searchR space
n g ls.
– and use this to guide searchE ge
E n
. R
ls
• This leads to thegeconcept of a planning graph R
ls.
En ge
E n
. R
els R
g ls .
En ge
E n
. R
els R
g s .
En gel
E n
51
Unit 4 – Planning - Summary