30
Hierarchical Task Hierarchical Task Network (HTN) Network (HTN) Planning Planning Hai Hoang Hai Hoang 4/17/2007 4/17/2007

Hierarchical Task Network (HTN) Planning

  • Upload
    vui

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

Hierarchical Task Network (HTN) Planning. Hai Hoang 4/17/2007. Reminder. JSHOP and JSHOP2 come with some sample domain files. You CANNOT use those files. Need to write your own. HTN vs Classical. Like classical planning: Each state of the world is represented by a set of atoms - PowerPoint PPT Presentation

Citation preview

Page 1: Hierarchical Task Network (HTN) Planning

Hierarchical Task Network Hierarchical Task Network (HTN) Planning(HTN) Planning

Hierarchical Task Network Hierarchical Task Network (HTN) Planning(HTN) Planning

Hai HoangHai Hoang4/17/20074/17/2007

Page 2: Hierarchical Task Network (HTN) Planning

Reminder

• JSHOP and JSHOP2 come with some sample domain files.

• You CANNOT use those files.

• Need to write your own.

Page 3: Hierarchical Task Network (HTN) Planning

HTN vs Classical

• Like classical planning:– Each state of the world is represented by a

set of atoms– Each action corresponds to a deterministic

state transition– (block b1) (block b2) (block b3) (block b4)

(on-table b1) (on b2 b1) (clear b2) (on-table b3) (on b4 b3) (clear b4)

Page 4: Hierarchical Task Network (HTN) Planning

HTN vs Classical

• Differs:– Objective: to perform a set of tasks not a set

of goals– Terms, literals, operators, actions, plans

have same meaning as classical planning.– Added tasks, methods, task networks– Tasks decompose into subtasks

• Constraints• Backtrack if necessary

Page 5: Hierarchical Task Network (HTN) Planning

Decomposition

Non-primitive task

precond

method instance

s0 precond effects precond effectss1 s2

primitive taskprimitive task

operator instance operator instance

Non-primitive task

Shows the order plan will be executed later

Page 6: Hierarchical Task Network (HTN) Planning

Tasks vs Control Rules

• We saw control rules – actions NOT to consider

• HTN – actions and tasks to consider

Page 7: Hierarchical Task Network (HTN) Planning

Control Rules

• Classical planning efficiency suffers from combinatorial complexity (intractable)

• Prune function detects and cuts unpromising nodes– Can improve solving: exponential to polynomial

• Φ1(c,d,p) = [GOAL(in(c,p)) q GOAL(in(c,q))] [GOAL(on(c,d) e GOAL(on(c,e))]– No goal requiring c in another pile or on top of something else

(prune if exist?)– Holds if acceptable when container c is on item d in pile p

By: Steve Lee-Urban

Page 8: Hierarchical Task Network (HTN) Planning

HTN

• Instead of detecting and cutting unpromising nodes

• HTN methods are only applied only when the preconditions are satisfied.(:method (pick-up ?x)

((clear ?x))((!pick-up ?x))

)

Only pick up if x is on top

Page 9: Hierarchical Task Network (HTN) Planning

Domain

• Domain dependent – Bridge Baron game

• Domain independent – SHOP

D1 D2 D3

P1 P2 P3

D1 D2 D3

P

Domain

Planner

Planning procedures

Page 10: Hierarchical Task Network (HTN) Planning

HTN

• Domain consists of – methods and operators (SHOP- axioms)

• Problem consists of – domain, initial state, initial task network

(tasks to accomplish, with some ordering of the tasks defined)

• Solution– A plan: Totally ordered collection of primitive

tasks (SHOP)– General HTN planner - partially ordered collection of primitive tasks.

Page 11: Hierarchical Task Network (HTN) Planning

TASK• Task: an expression of the form t(u1,…,un)

– t is a task symbol, and each ui is a term (variable, constant, function expression (f t1 t2 tn)

– (move-block ?nomove)– (move-block (list ?x . ?nomove))

• Two types of task1. Non-primitive (compound) – decomposed into

subtasks.

2. Primitive – cannot be decomposed, know how to perform directly (task name is the operator name).

• (!drive-truck ?truck ?loc-from ?loc-to)

Page 12: Hierarchical Task Network (HTN) Planning

Methods and Operators• Defined a little differently in the textbook, but we’re more concerned with

coding it in SHOP so forget the book for now (book notations later on).

• Explain both with an example instead of notations. – Spent a good amount of time arranging the next slide – Help to visualize how they map to a real shop method or operator.

• method as defined by SHOP (see manual)(:method h [n1] C1 T1 [n2] C2 T2 … [nk] Ck Tk) h method head – task atom with no call terms [n1] OPTIONAL name for succeeding Ci Ti pair C1 conjunct or tagged conjunct? Precondition list?? T1 task list

• Operator(:operator h P D A) h head – primitive task atom with no call terms P precondition list (logical atoms) D delete list (logical atoms) A add list (logical atoms)

Page 13: Hierarchical Task Network (HTN) Planning

Operators and Methods• Method ( decomposes into subtasks)

(:method (drive-truck ?truck ?loc-from ?loc-to) ((same ?loc-from ?loc-to)) ((!do-nothing)) () ((!drive-truck ?truck ?loc-from ?loc-to)))– Notice the if else structure– Invoke non-primitive task: (drive-truck ?t ?x ?y)

• Operator (achieves PRIMITIVE TASKS) (:operator (!drive-truck ?truck ?locfrom ?locto) () ((truck-at ?truck ?locfrom)) ((truck-at ?truck ?locto)))Invoke primitive task: (!drive-truck ?t ?l1 ?l2)

Non prim

preconditions

Subtasks list

prim task

preconditions

delete list

Add list

Primitive task

Page 14: Hierarchical Task Network (HTN) Planning

Review

• Relationship between non-primitive tasks and methods– Decomposed by applying a method

• Relationship between primitive tasks and operators– Primitive task is achieved by applying an

operator

• Important that you understand this!!!

Page 15: Hierarchical Task Network (HTN) Planning

STN and HTN• STN – Simple Task Network (simplified version of HTN)

1. TFD – Total-order Forward Decomposition (used in SHOP)1. Example later

Input: tasks are totally orderedOutput: totally ordered plan

2. PFD – Partial-order Forward Decomposition (SHOP2)1. Example later

Input: tasks are partially orderedOutput: totally ordered plan

• HTN – generalization of STN1. More freedom about how to construct the task networks.2. Can use other decomposition procedures not just forward-

decomposition.3. Like Partial-order planning combined with STN Input: partial-order tasks Output: The resulting plan is partially ordered

Page 16: Hierarchical Task Network (HTN) Planning

Task Network• STN

w = (U, E) - an acyclic graph

U – set of task nodes

E – set of edges

• HTNw = (U, C)

U – set of task nodes

C – set of constraints (allow for generic task networks). Different planning procedures.

Page 17: Hierarchical Task Network (HTN) Planning

STN• STN method: 4-tuple

m = (name(m), task(m), precond(m), subtasks(m))– name(m): an expression of the form n(x1,…,xn)

• n – name of the method – method symbol

• x1,…,xn are parameters - variable symbols– task(m): a nonprimitive task

• task that this method could apply to• In SHOP, the task is the head of the method.

– precond(m): preconditions (literals)– subtasks(m): a sequence

of tasks t1, …, tk

do-nothing(p,q)task: move-stack(p,q)precond: top(pallet,p)subtasks: ()

Page 18: Hierarchical Task Network (HTN) Planning

Pseudo-code for TFD

Applying an operatorChanging the state

Decompose method into tasks

Randomly pick an applicable method

Page 19: Hierarchical Task Network (HTN) Planning

DWR• Move the containers, preserving ordering• Use loc1 as example.

Page 20: Hierarchical Task Network (HTN) Planning

Total Order Tasks (SHOP- STD)

Page 21: Hierarchical Task Network (HTN) Planning

Example TFDGoal: move-each-twice

Move-stack(p1a, p1b)

Move-stack(p1b, p1c)

Stack 2 and 3 empty.

Page 22: Hierarchical Task Network (HTN) Planning

Partially Ordered tasks (SHOP2 - PFD)

Page 23: Hierarchical Task Network (HTN) Planning

PFD Example

Page 24: Hierarchical Task Network (HTN) Planning

TFD & PFD

• STN doesn’t allow parallel execution, but can interleave steps (PFD)

• At the end the resulting plan is totally ordered (both TFD & PFD)

Page 25: Hierarchical Task Network (HTN) Planning

SHOP & SHOP2

• SHOP: Simple Hierarchical Ordered Planner

• SHOP is basically TFD STN

• SHOP2 is PFD STN – mainly with the addition of the unordered keyword for the task list. Note: resulting plan is still a totally-ordered task list.

Page 26: Hierarchical Task Network (HTN) Planning

Prefix Notation

• Domain and problem file are in Lisp like format.

• 7 + 3

• (+ 7 3)

• p(a,?x) -> (p a ?x)

• Any volunteer? p(f (a,b), ?y)

• Answer: (p (f a b) ?y)

• (call + 3 7)

Page 27: Hierarchical Task Network (HTN) Planning

Axioms (Horn clauses)

• (:- a C1 C2 C3 … Cn)

– a is true if C1 is true, else if C1 is false and C2 is true, or else if C1 to Cn-1 is false and Cn is true.

• (:- (same ?x ?x) nil)

• (same 5 5)

• (same 5 7)

Page 28: Hierarchical Task Network (HTN) Planning

Above Example• (:- (above ?a ?b) ((on ?a ?b)))• (:- (above ?a ?b) ((on ?a ?c) (above ?c ?b)))

• S0 = (on 1 2) (on 2 3) (on 3 4)• Is (above 1 4) true?

(on 1 2) (above 2 4)(on 1 2) (on 2 3) (above 3 4)(on 1 2) (on 2 3) (on 3 4)When all conjuncts are true, (above 1 4) is

true.

Page 29: Hierarchical Task Network (HTN) Planning

JSHOP

• Domain file: operators, methods, axioms

• Problem file: initial state, initial task list (goals)

• On Vega in /home/hah3/jshop

• To run one of the sample problemjava umd.cs.shop.JSJshop logistic/logistic.shp

logistic/Log_ran_problems_10.shp 1 all > output.txt

java –jar shop.jar logistic/logistic.shp logistic/Log_ran_problems_10.shp 1 all > output.txt

java umd.cs.shop.JSJshop domainfile problemfile logLevel numofplan

Page 30: Hierarchical Task Network (HTN) Planning

For reference:

• JSHOP manual in the jshop directory

• http://www.cs.umd.edu/~nau/papers/shop-ijcai99.pdf

• Contact me [email protected]