Presentation on theme: "Hierarchical Task Network (HTN) Planning Hai Hoang 4/17/2007."— Presentation transcript:
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 –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)
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
Decomposition Non-primitive task precond method instance s0s0 precondeffectsprecondeffects s1s1 s2s2 primitive task operator instance Non-primitive task Shows the order plan will be executed later
Tasks vs Control Rules We saw control rules – actions NOT to consider HTN – actions and tasks to consider
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
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
Domain Domain dependent – Bridge Baron game Domain independent – SHOP D1D2D3 P1P2P3 D1D2D3 P Domain Planner Planning procedures
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.
TASK Task: an expression of the form t(u 1,…,u n ) –t is a task symbol, and each u i is a term (variable, constant, function expression (f t 1 t 2 t n ) –(move-block ?nomove) –(move-block (list ?x. ?nomove)) Two types of task 1.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)
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 [n 1 ] C 1 T 1 [n 2 ] C 2 T 2 … [n k ] C k T k ) h method head – task atom with no call terms [n 1 ] OPTIONAL name for succeeding C i T i pair C 1 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)
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 preconditionsdelete listAdd list Primitive task
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!!!
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 ordered Output: totally ordered plan 2.PFD – Partial-order Forward Decomposition (SHOP2) 1.Example later Input: tasks are partially ordered Output: totally ordered plan HTN – generalization of STN 1.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
Task Network STN w = (U, E) - an acyclic graph U – set of task nodes E – set of edges HTN w = (U, C) U – set of task nodes C – set of constraints (allow for generic task networks). Different planning procedures.
STN STN method: 4-tuple m = (name(m), task(m), precond(m), subtasks(m)) –name(m): an expression of the form n(x 1,…,x n ) n – name of the method – method symbol x 1,…,x n 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 t 1, …, t k do-nothing(p,q) task: move-stack(p,q) precond: top(pallet,p) subtasks: ()
Pseudo-code for TFD Applying an operator Changing the state Decompose method into tasks Randomly pick an applicable method
DWR Move the containers, preserving ordering Use loc1 as example.
Total Order Tasks (SHOP- STD)
Example TFD Goal: move-each-twice Move-stack(p1a, p1b) Move-stack(p1b, p1c) Stack 2 and 3 empty.
Partially Ordered tasks (SHOP2 - PFD)
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)
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.
Prefix Notation Domain and problem file are in Lisp like format (+ 7 3) p(a,?x) -> (p a ?x) Any volunteer? p(f (a,b), ?y) Answer: (p (f a b) ?y) (call + 3 7)
Axioms (Horn clauses) (:- a C 1 C 2 C 3 … C n ) –a is true if C 1 is true, else if C 1 is false and C 2 is true, or else if C 1 to C n-1 is false and C n is true. (:- (same ?x ?x) nil) (same 5 5) (same 5 7)
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.
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 problem java 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
For reference: JSHOP manual in the jshop directory -ijcai99.pdfhttp://www.cs.umd.edu/~nau/papers/shop -ijcai99.pdf Contact me