Printable

Artificial Intelligence
Programming
More Planning
Chris Brooks
Department of Computer Science
Previously on CS662 ...
POP algorithm
Planning combines search and knowledge
representation.
Initial plan contains Start, F inish, Start ≺ F inish
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.
University of San Francisco
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 Fra
Department of Computer Science — University of San Francisco – p.1/??
POP example
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/??
Weaknesses of POP
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/??
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 Fra
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.
HTN Example
has(Brooks, ticket)
PackSuitcase
GoOnTrip
Action Decomposition
at(Brooks, Hawaii)
has(Brooks, suitcase)
at(Brooks, Hawaii)
at(Brooks, SFO)
has(Brooks, suitcase)
at(Brooks, home)
GetToAirport
at(Brooks, SFO)
WalkToGate
FindSuitcase
DriveToSFO
Department of Computer Science — University of San Francisco – p.6/??
HTN Algorithm
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.
FindSeat
FindSwimsuit
walkToCar
Begin with our initial plan Start, F inish, Start ≺ F inish
GetOnPlane
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.
ParkCar
Department of Computer Science — University of San Francisco – p.7/??
Department of Computer Science — University of San Fra
Subtask sharing
Conflict resolution
Primitive plans can interact in two ways
Actions in one subplan may also have ordering conflicts
with actions in another subplan.
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.
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.9/??
Department of Computer Science — University of San Francisco – p.10/??
Department of Computer Science — University of San Fran
HTNs in practice
Nondeterminism
Planning with Nondeterminism
HTNs have been extremely successful in real-world
planning systems.
Most problems really are decomposable.
So far, we have only thought about planning (and
search, for that matter) in deterministic environments.
Actions always succeed.
Subtask sharing is very xommon in practice.
What about worlds in which actions might fail?
Having the ability to reuse plan fragments is extremely
beneficial.
What about problems in which our agent has incomplete
information?
There are four basic approaches to nondeterminism:
Sensorless planning
Conditional planning
Execution monitoring and replanning
Continuous planning
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.13/??
Department of Computer Science — University of San Francisco – p.12/??
Department of Computer Science — University of San Fran
Sensorless planning
Conditional Planning
Conditional Planning
In sensorless planning, we construct a standard plan
and execute without any perception.
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 can extend POP by adding sensing actions.
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.
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.15/??
Department of Computer Science — University of San Francisco – p.16/??
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 Fran
Execution Monitoring
Replanning
Replanning
Conditional planning assumes that all planning happens
offline.
We plan, and then execute.
Our replanning agent starts with a normal plan.
Replanning works well when an agent needs to make
fairly simple repairs to a plan.
More complex repairs may be very time-consuming.
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.
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.
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.19/??
Department of Computer Science — University of San Francisco – p.18/??
Department of Computer Science — University of San Fran
Continuous planning
Continuous planning
Continuous planning
In some environments, we might want to completely
integrate planning and execution.
Example: tire problem.
Our agent begins by constructing a POP plan.
Agent can now select RemoveTireFromTrunk and
directly to PutOnTire.
Rather than just accomplishing a single task, our agent
has an ongoing existence in which it is always deciding
what to do next.
Decides to take the RemoveTireFromAxle action.
The preconditions for PutOnTire have been satisfied.
Agent senses, notices that flat tire has fallen off axle.
Agent replans, senses again, executes PutOnTire.
Our agent can be thought of as always being partway
through a plan.
Updates internal model.
This cycle continues.
If we add “formulate goals” as an action to be taken
when all preconditions are satisfied, the agent can run
indefinitely.
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/??
Department of Computer Science — University of San Francisco – p.22/??
Department of Computer Science — University of San Fran
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/??