Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... ·...

25
Hierarchical Task Network (HTN) Planning Section 11.2 Sec. 11.2 – p.1/25

Transcript of Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... ·...

Page 1: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Hierarchical Task Network (HTN) Planning

Section 11.2

Sec. 11.2 – p.1/25

Page 2: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Outline

Example

Primitive vs. non-primitive operators

HTN planning algorithm

Practical planners

Additional references used for the slides:

desJardins, M. (2001). CMSC 671 slides.www.cs.umbc.edu

Sec. 11.2 – p.2/25

Page 3: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Hierarchical Task Network (HTN) planning

Idea: Many tasks in real life already have a built-inhierarchical structure

For example: a computational task, a militarymission, an administrative task

It would be a waste of time to construct plans fromindividual operators. Using the built-in hierarchyhelp escape from exponential explosion

Running example: the activity of building a houseconsists of obtaining the necessary permits, findinga builder, constructing the exterior/interior, ...

HTN approach: use abstract operators as well asprimitive operators during plan generation.

Sec. 11.2 – p.3/25

Page 4: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Building a house

ObtainPermit

Construct PayBuilder

HireBuilder

decomposes to

decomposes to

BuildHouse

BuildFoundation

BuildFrame

BuildRoof

BuildWalls

BuildInterior

Sec. 11.2 – p.4/25

Page 5: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Hierarchical decomposition

HTN is suitable for domains where tasks arenaturally organized in a hierarchy.

Uses abstract operators to start a plan.

Use partial-order planning techniques and actiondecomposition to come up with the final plan

The final plan contains only primitive operators.

What is to be considered primitive is subjective:what an agent considers as primitive can be anotheragent’s plans.

Sec. 11.2 – p.5/25

Page 6: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Representing action decompositions

A plan library contains both primitive andnon-primitive actions.

Non-primitive actions have external preconditions,as well as external effects.

Sometimes useful to distinguish between primaryeffects and secondary effects.

Sec. 11.2 – p.6/25

Page 7: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Building a house with causal links

PayBuilder

ObtainPermit

Construct

HireBuilder

decomposes to

BuildHouse

Land House

Land

Money

House

~ Money

Start Finish

Sec. 11.2 – p.7/25

Page 8: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Another way of building a house

Construct

ObtainPermit

GetFriend

decomposes to

BuildHouse

Land House

Land

House

BadBack

Start Finish

Cut logs

GoodFriend

Sec. 11.2 – p.8/25

Page 9: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Example action descriptions

Action(BuyLand, PRECOND:Money, EFFECT: Land ∧¬ Money)Action(GetLoan, PRECOND:GoodCredit, EFFECT: Money ∧ Mortgage)Action(BuildHouse, PRECOND:Land, EFFECT: House)

Action(GetPermit, PRECOND:Land, EFFECT: Permit)Action(HireBuilder, EFFECT: Contract)Action(Construct, PRECOND:Permit ∧ Contract,

EFFECT: HouseBuilt ∧¬ Permit)Action(PayBuilder, PRECOND:Money ∧ HouseBuilt,

EFFECT: ¬ Money ∧ House ∧¬ Contract)

Sec. 11.2 – p.9/25

Page 10: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Example action descriptions

Decompose(BuildHouse,Plan(STEPS:{S1: GetPermit, S2: HireBuilder,Plan(STEPS:{ S3: Construction, S4: PayBuilder,}Plan( ORDERINGS: { Start ≺ S1 ≺ S2 ≺ S3 ≺ S4 ≺ Finish,Plan( ORDERINGS: { Start ≺ S2 ≺ S3 },Plan( L INKS: { Start Land

−−−→S1, Start Money

−−−−→S4,

Plan( L INKS: { S1 Permit−−−−−→

S3, S2 Contract−−−−−−→

S3, S3 HouseBuilt−−−−−−−−→

S4,

Plan( L INKS: { S4 House−−−−→

Finish, S4 ¬Money−−−−−−→

Finish}))

Sec. 11.2 – p.10/25

Page 11: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Correctness

A decomposition should be a correctimplementation of the action.

A plan d implements an action a correctly if d is acomplete and consistent partial-order plan for theproblem of achieving the effects of a given thepreconditions of a (result of a sound POP).

The plan library contains several decompositions forany high-level action.

Each decomposition might have differentpreconditions and effects. The preconditions of thehigh-level action should be the intersection of thepreconditions of the decompositions (similarly forthe external effects.)

Sec. 11.2 – p.11/25

Page 12: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Information hiding

The high-level description hides all the internaleffects of decompositions (e.g., Permit andContract).

It also hides the duration the internal preconditionsand effects hold.

Advantage: reduces complexity by hiding details

Disadvantage: conflicts are hidden too

Sec. 11.2 – p.12/25

Page 13: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Example

Start

PayBuilder

Finish

FinishBuy Land

GetPermit

Construct

HireBuilder

decomposes to

BuildHouse

House

House

~ Money

Start

Land

Buy Land

GetLoan

Money

GoodCredit

Land

Money

Money

~ Money

Sec. 11.2 – p.13/25

Page 14: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

For each decomposition d of an action a

Remove the high level action, and insert/reuseactions for each action in d.reuse → subtask sharing

Merge the ordering constraints (If there is anordering constraint of the form B ≺ a, should everystep of d come after B?)

Merge the causal links

Sec. 11.2 – p.14/25

Page 15: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Action ordering

Start

GiveChain

Start

~ WatchCombHappy(She)

Finish Start

GiveComb

Finish

WatchHair

WatchHair Happy(He)

Chain

Give Combon credit

DeliverWatch

Start

DeliverHair

Give Chainon credit

WatchHair

Hair

Watch

comb

chainowe(hair)happy(He)

watch

hair~hair~owe(hair)

happy(she)owe(watch)

~owe(hair)~watch

~Hair

HairWatch

Happy(She)Happy(He)

Sec. 11.2 – p.15/25

Page 16: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

HTN planners

Most industrial strength planners are HTN based.

O-PLAN combines HTN planning with scheduling todevelop production plans for Hitachi.

SIPE-2 is an HTN planner with many advancedfeatures

SHOP is an HTN planner developed at the Universityof Maryland. It can deal with action durations.

Sec. 11.2 – p.16/25

Page 17: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

The features of SIPE-2

Plan critics

Resource reasoning

Constraint reasoning (complex numerical orsymbolic variable and state constraints)

Interleaved planning and execution

Interactive plan development

Sophisticated truth criterion

Conditional effects

Parallel interactions in partially ordered plans

Replanning if failures occur during execution

Sec. 11.2 – p.17/25

Page 18: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

An operator with constraints

OPERATOR decomposePURPOSE: ConstructionCONSTRAINTS:

Length (Frame) <= Length (Foundation),Strength (Foundation) > Wt(Frame) + Wt(Roof)

+ Wt(Walls) + Wt(Interior) + Wt(Contents)PLOT: Build (Foundation)

Build (Frame)PARALLEL

Build (Roof)Build (Walls)

END PARALLELBuild (Interior)

Sec. 11.2 – p.18/25

Page 19: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

More on SIPE-2

Russell & Norvig explicitly represent causal links;these can also be computed dynamically by using amodel of preconditions and effects (this is whatSIPE-2 does)

Dynamically computing causal links means thatactions from one operator can safely be interleavedwith other operators, and subactions can safely beremoved or replaced during plan repair

Russell & Norvig’s representation only includesvariable bindings, but more generally we canintroduce a wide array of variable constraints

Sec. 11.2 – p.19/25

Page 20: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Truth Criterion

Determining whether a formula is true at a particularpoint in a partially ordered plan is, in the generalcase, NP-hard

Intuition: there are exponentially many ways tolinearize a partially ordered plan

In the worst case, if there are N actions unorderedwith respect to each other, there are N!linearizations

Sec. 11.2 – p.20/25

Page 21: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Truth Criterion

Ensuring soundness of the truth criterion requireschecking the formula under all possiblelinearizations

Use heuristic methods instead to make planningfeasible

Check later to be sure no constraints have beenviolated

Sec. 11.2 – p.21/25

Page 22: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Truth Criterion in Sipe-2

Heuristic: prove that there is one possible orderingof the actions that makes the formula true, but don’tinsert ordering links to enforce that order

Such a proof is efficientSuppose you have an action A1 with aprecondition PFind an action A2 that achieves P (A2 could beinitial world state)Make sure there is no action necessarilybetween A2 and A1 that negates P

Applying this heuristic for all preconditions in theplan can result in infeasible plans

Sec. 11.2 – p.22/25

Page 23: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Comments on HTN planning

The major idea is to gain efficiency by using thelibrary of preconstructed plans.

When there is recursion, it is undecidable even if theunderlying state space is finite.

recursion can be ruled outthe length of solutions can be boundcan use a hybrid POP and HTN approach

Sec. 11.2 – p.23/25

Page 24: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Comments on HTN planning (cont’d)

Subtask sharing is nice, but it takes time/resourcesto notice the opportunities

Would interprocedural optimization be a possibility?Consider tan(x) − sin(x). Both have Taylor seriesapproximations:tan(x) ≈ x + x3

3 + 2x5

15 + 17x7

315

sin(x) ≈ x −x3

6 + x5

120 −x7

5040

It would be nice to share terms but a compiler canonly optimize within the code because it does nothave the source; and if it did interproceduraloptimization tan and sin would always have to bechanged together.

Sec. 11.2 – p.24/25

Page 25: Hierarchical Task Network (HTN) Planningnilufer/classes/cs5811/2014-fall/lecture-slides/... · Hierarchical Task Network (HTN) planning Idea: Many tasks in real life already have

Comments on HTN planning (cont’d)

Suppose that we want to construct a plan with n

actionsForward state space planning takes O(bn) with b

allowable actions at each state.HTN planning can construct d

(n−1)/(k−1)

decomposition trees with d possibledecompositions with k actions each→ keeping d small and k large can result in hugesavings (long macros usable across a widerange of problems)HTN-based planners do not address uncertainty

Sec. 11.2 – p.25/25