Full size

Artificial Intelligence
Programming
More Planning
Chris Brooks
Department of Computer Science
University of San Francisco
Previously on CS662 ...
Planning combines search and knowledge
representation.
Construct a partially-ordered sequence of actions to
achieve a goal.
Insights:
Only select actions that help achieve our plan
Don’t have to solve the problem in order
Don’t have to produce a linear ordering on events.
Search through space of plans, rather than states.
Department of Computer Science — University of San Francisco – p.1/?
POP algorithm
Initial plan contains Start, F inish, Start ≺ F inish
While (no solution)
Select an open precondition p on an action B
Find each action A that satisfies that precondition;
generate a new plan for each action.
for each of these plans:
Add ordering constraints A ≺ B , plus causal links
A →p B
Resolve any conflicts between causal links. If no
consistent plan exists, discard.
Department of Computer Science — University of San Francisco – p.2/?
POP example
Start: at(Town) has(Coins), has(Dagger)
:not (grown (Beanstalk))
Finish: has(Gold)
Department of Computer Science — University of San Francisco – p.3/?
POP example
actions:
wield. Pre: has(w) Effect: holding(w)
go. Pre: at(x), !at(y) Effect: !at(x), at(y)
plantBeans. Pre: at(Field), has(Beans)
Effect: !has(Beans), grown(Beanstalk)
defeatDragon. Pre: at(Cave), wearing(Armor),
holding(Sword)
Effect: has(Gold)
wear. Pre: has(x) Effect: wearing(x)
climbBeanstalk: Pre: at(Field), grown(Beanstalk)
Effect: has(Armor)
buyBeans. Pre: at(Town), has(Coins)
Effect: !has(Coins), has(Beans)
getSwordFromLake Pre: at(Lake), wearing(Armor)
Effect: has(Sword)
Department of Computer Science — University of San Francisco – p.4/?
Weaknesses of POP
Doesn’t completely get at the issue of decomposability.
Difficult to reuse portions of a plan
Exponentially hard - can’t use for large action
sequences.
Hierarchical plans can help solve these problems.
Department of Computer Science — University of San Francisco – p.5/?
Hierarchical Task Networks
A Hierarchical Task Network (HTN) specifies a plan at
various levels of detail, or granularity.
Insight: if we can decompose a plan into several
independent subplans, we can solve these problems
(mostly) independently.
We can also reuse components of a plan in a new
setting.
The actions in our high-level plan will correspond to
entire plans in a lower-level representation.
Department of Computer Science — University of San Francisco – p.6/?
HTN Example
has(Brooks, ticket)
PackSuitcase
GoOnTrip
at(Brooks, Hawaii)
has(Brooks, suitcase)
at(Brooks, Hawaii)
at(Brooks, SFO) GetOnPlane
has(Brooks, suitcase)
at(Brooks, home)
GetToAirport
at(Brooks, SFO)
WalkToGate
FindSuitcase
FindSeat
FindSwimsuit
walkToCar
DriveToSFO
ParkCar
Department of Computer Science — University of San Francisco – p.7/?
Action Decomposition
The key idea with HTNs is that actions can be
represented at different levels of granularity.
An action at one level can decompose into an entire
plan at another level.
As long as the priitive actions in each subplan don’t
interfere with each other, all is well.
This allows for the development of plan libraries.
Reusable subplans that implement specific actions.
Department of Computer Science — University of San Francisco – p.8/?
HTN Algorithm
Begin with our initial plan Start, F inish, Start ≺ F inish
While (no solution)
Select an open precondition p on an action B or an abstract action a′ .
if we have selected a precondition:
Find each action A that satisfies that precondition; generate a new plan for
each action.
for each of these plans:
• Add ordering constraints A ≺ B, plus causal links A →p B
• Resolve any conflicts between causal links. If no consistent plan exists,
discard.
else if we have selected an abstract plan
Find each decomposition d of action a′
For each decomposition:
Add this new subplan
Check for task sharing.
Resolve conflicts.
Department of Computer Science — University of San Francisco – p.9/?
Subtask sharing
Primitive plans can interact in two ways
The positive interaction is called subtask sharing
Two subplans both contain the same action or achieve
the same effect.
PackSuitcase and GoToAirport might both contain
checkWeather as actions.
We can eliminate one of them. This is sometimes called
synergy.
Department of Computer Science — University of San Francisco – p.10/?
Conflict resolution
Actions in one subplan may also have ordering conflicts
with actions in another subplan.
This may require us to interleave these subplans.
For example, packSuitcase might contain buyToothpaste
as an action.
This might require that I have enough money for
toothpaste.
BuyTicket might have as an action payForTicket, which
could result in my not having enough money for
toothpaste (at least until I get paid).
I need to order actions in such a way that getting paid
comes before at least one of these actions.
Department of Computer Science — University of San Francisco – p.11/?
HTNs in practice
HTNs have been extremely successful in real-world
planning systems.
Most problems really are decomposable.
Subtask sharing is very xommon in practice.
Having the ability to reuse plan fragments is extremely
beneficial.
Plan fragments can also be learned (chunked) from
experience.
The first time I solve buyTicket, I can determine what
is specific to my problem and what is generic and
create a generalized version that keeps only generic
information.
Department of Computer Science — University of San Francisco – p.12/?
Nondeterminism
So far, we have only thought about planning (and
search, for that matter) in deterministic environments.
Actions always succeed.
What about worlds in which actions might fail?
What about problems in which our agent has incomplete
information?
Department of Computer Science — University of San Francisco – p.13/?
Planning with Nondeterminism
There are four basic approaches to nondeterminism:
Sensorless planning
Conditional planning
Execution monitoring and replanning
Continuous planning
Department of Computer Science — University of San Francisco – p.14/?
Sensorless planning
In sensorless planning, we construct a standard plan
and execute without any perception.
Our plan must work no matter what actions fail.
Assumes that the world can always be coerced into a
particular state.
We can just use our standard algorithms.
Many worlds cannot be coerced like this.
Department of Computer Science — University of San Francisco – p.15/?
Conditional Planning
Conditional planning accounts for the fact that actions
might fail by integrating sensing actions into the plan.
After we put the tire onto the axle, look at the axle to
ensure that the tire is actually there.
We need to modify our actions to have disjunctive
effects.
P utOnT ire(tire)
P reconditions : On(tire, Ground) ∧ Clear(Axle)
Ef f ect : (On(tire, Axle) ∧ ¬On(tire, Ground) ∧
¬Clear(Axle)) ∨ On(tire, Ground)
Department of Computer Science — University of San Francisco – p.16/?
Conditional Planning
We can extend POP by adding sensing actions.
Based on the output of these actions, we can choose
different subgoals.
We may have to add loops into our plan if actions can
fail.
Example: tire scenario.
Note that this assumes the environment is fully
observable.
Partial observability adds extra challenges.
Department of Computer Science — University of San Francisco – p.17/?
Execution Monitoring
Conditional planning assumes that all planning happens
offline.
We plan, and then execute.
This is fine when all possible failures are known in
advance.
But what about worlds where there are problems we
can’t anticipate?
In this case, our agent must be able to monitor its
execution and replan if necessary.
Department of Computer Science — University of San Francisco – p.18/?
Replanning
Our replanning agent starts with a normal plan.
Before taking an action, it examines the world to see if
any of the preconditions for that action have become
unsatisfied.
If so, the agent constructs a new plan that satisfies
these preconditions.
The agent can also look ahead at future actions to see if
there are unsatisfied preconditions that will not be
fulfilled by an effect.
This helps avoid proceeding with plans that cannot
succeed.
Department of Computer Science — University of San Francisco – p.19/?
Replanning
Replanning works well when an agent needs to make
fairly simple repairs to a plan.
More complex repairs may be very time-consuming.
The agent may have difficulty in situations where the
plan cannot be achieved for reasons it is unaware of.
Say the tire is the wrong size for the axle.
The agent is still operating within the context of a single
plan.
Department of Computer Science — University of San Francisco – p.20/?
Continuous planning
In some environments, we might want to completely
integrate planning and execution.
Rather than just accomplishing a single task, our agent
has an ongoing existence in which it is always deciding
what to do next.
Our agent can be thought of as always being partway
through a plan.
Cycle:
Perceive environment
Plan for a while
act
This can be integrated into real-time domains.
Department of Computer Science — University of San Francisco – p.21/?
Continuous planning
Example: tire problem.
Our agent begins by constructing a POP plan.
Decides to take the RemoveTireFromAxle action.
Agent senses, notices that flat tire has fallen off axle.
Updates internal model.
Department of Computer Science — University of San Francisco – p.22/?
Continuous planning
Agent can now select RemoveTireFromTrunk and
directly to PutOnTire.
The preconditions for PutOnTire have been satisfied.
Agent replans, senses again, executes PutOnTire.
This cycle continues.
If we add “formulate goals” as an action to be taken
when all preconditions are satisfied, the agent can run
indefinitely.
Department of Computer Science — University of San Francisco – p.23/?
Summary
Planning integrates search and knowledge
representation to discover sequences of actions that
satisfy a goal.
Works best with qualitative information
Later in the semester, we’ll see how to plan with
probabilities.
Hierarchical planning deals with problem structure and
reuse.
Conditional planning deals with stochastic
environments.
Department of Computer Science — University of San Francisco – p.24/?