Hierarchical task network htn planning
1 / 30

Hierarchical Task Network (HTN) Planning - PowerPoint PPT Presentation

  • Uploaded on

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

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Hierarchical Task Network (HTN) Planning' - abra-weaver

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript


  • JSHOP and JSHOP2 come with some sample domain files.

  • You CANNOT use those files.

  • Need to write your own.

Htn vs classical
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 classical1
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


Shows the order plan

will be executed later


Non-primitive task

method instance


Non-primitive task

primitive task

primitive task

operator instance

operator instance








Tasks vs control rules
Tasks vs Control Rules

  • We saw control rules – actions NOT to consider

  • HTN – actions and tasks to consider

Control rules
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

Only pick up if x is on top


  • 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))















Planning procedures


  • Domain dependent – Bridge Baron game

  • Domain independent – SHOP


  • 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: 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 task

    • Non-primitive (compound) – decomposed into subtasks.

    • 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
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)

Operators and methods

Non prim




Subtasks list


prim task

delete list

Add list

Operators and Methods

  • Method ( decomposes into subtasks)

    (:method (drive-truck ?truck ?loc-from ?loc-to)

    ((same ?loc-from ?loc-to))



    ((!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)


  • 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)

    • TFD – Total-order Forward Decomposition (used in SHOP)

      • Example later

        Input: tasks are totally ordered

        Output: totally ordered plan

    • PFD – Partial-order Forward Decomposition (SHOP2)

      • Example later

        Input: tasks are partially ordered

        Output: totally ordered plan

  • HTN – generalization of STN

    • More freedom about how to construct the task networks.

    • Can use other decomposition procedures not just forward-decomposition.

    • Like Partial-order planning combined with STN

      Input: partial-order tasks

      Output: The resulting plan is partially ordered

Task network
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 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,…,xnare 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 sequenceof tasks t1, …, tk


      task: move-stack(p,q)

      precond: top(pallet,p)

      subtasks: ()

Pseudo code for tfd
Pseudo-code for TFD

Applying an operator

Changing the state

Randomly pick an applicable method

Decompose method into tasks


  • Move the containers, preserving ordering

  • Use loc1 as example.

Example tfd
Example TFD

Goal: move-each-twice

Move-stack(p1a, p1b)

Move-stack(p1b, p1c)

Stack 2 and 3 empty.

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
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)

Axioms horn clauses
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)

Above example
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.


  • 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
For reference:

  • JSHOP manual in the jshop directory

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

  • Contact me [email protected]