Skip to content

Instantly share code, notes, and snippets.

@rpgoldman
Created November 3, 2023 20:28
Show Gist options
  • Save rpgoldman/cac881bf42ffe2f059bd58a77cdfc40d to your computer and use it in GitHub Desktop.
Save rpgoldman/cac881bf42ffe2f059bd58a77cdfc40d to your computer and use it in GitHub Desktop.

Revisions

  1. rpgoldman created this gist Nov 3, 2023.
    240 changes: 240 additions & 0 deletions domain.hddl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,240 @@
    ;; openstacks, strips version

    (define (domain openstacks-sequencedstrips-ADL-nocosts)
    (:requirements :typing :adl)
    (:types order product count)
    (:predicates (includes ?o - order ?p - product)
    (waiting ?o - order)
    (started ?o - order)
    (shipped ?o - order)
    (goal-shipped ?o - order)
    (made ?p - product)
    (stacks-avail ?s - count)
    (next-count ?s ?ns - count))

    (:task make-product-complex :parameters (?p - product))
    (:task start-an-order-for :parameters (?p - product ?o - order))
    (:task start-an-order :parameters (?o - order))
    (:task ship-an-order :parameters (?o - order))
    (:task start-orders :parameters (?p - product))
    (:task ship-products :parameters (?o - order))
    (:task plan :parameters ())
    (:task plan-for-goals :parameters ())
    (:task open-all-stacks :parameters ())
    ; (:task reset-order-status :parameters ())
    (:task one-step :parameters ())
    (:task make-a-product :parameters ())
    (:task open-new-stack-complex :parameters (?n ?n1 - count))

    ;; modified so that the precondition is that none of the orders may
    ;; be waiting, which means it could be "shipped", which makes plan
    ;; repair (and the construction of plan repair problems), easier.
    (:action make-product
    :parameters (?p - product)
    :precondition (and (not (made ?p))
    (forall (?o - order)
    (imply (includes ?o ?p)
    (not (waiting ?o)))))
    :effect (made ?p))

    (:action start-order
    :parameters (?o - order ?avail ?new-avail - count)
    :precondition (and (waiting ?o)
    (stacks-avail ?avail)
    (next-count ?new-avail ?avail))
    :effect (and (not (waiting ?o))
    (started ?o)
    (not (stacks-avail ?avail))
    (stacks-avail ?new-avail))
    )

    (:action ship-order
    :parameters (?o - order ?avail ?new-avail - count)
    :precondition (and (started ?o)
    (forall (?p - product)
    (imply (includes ?o ?p) (made ?p)))
    (stacks-avail ?avail)
    (next-count ?avail ?new-avail))
    :effect (and (not (started ?o))
    (shipped ?o)
    (not (stacks-avail ?avail))
    (stacks-avail ?new-avail))
    )

    (:action open-new-stack
    :parameters (?open ?new-open - count)
    :precondition (and (stacks-avail ?open)
    (next-count ?open ?new-open))
    :effect (and (not (stacks-avail ?open))
    (stacks-avail ?new-open))
    )
    ;;This action should only be used during replanning to reset order status
    ;; (otherwise, the stack system will be offset and break the state)
    ; (:action reset
    ; :parameters (?o - order)
    ; :precondition (and (started ?o) (not (shipped ?o)) (not (waiting ?o)))
    ; :effect (and (waiting ?o) (not (started ?o)))
    ; )


    (:method plan-method-1
    :parameters ()
    :task (plan)
    :precondition
    (exists (?o - order)
    (and (goal-shipped ?o) (not (shipped ?o))))
    :ordered-subtasks
    (and (open-all-stacks)
    ;(reset-order-status)
    (plan-for-goals)))
    (:method open-a-stack-and-recurse
    :parameters (?n ?n1 - count)
    :task(open-all-stacks)
    :precondition
    (exists (?n ?n1 - count) (and (stacks-avail ?n) (next-count ?n ?n1)))
    :ordered-subtasks (and (open-new-stack-complex ?n ?n1) (open-all-stacks)))
    (:method done-opening-stacks
    :parameters (?n - count)
    :task
    (open-all-stacks) :precondition
    (and (stacks-avail ?n)
    (forall (?n1 - count) (not (next-count ?n ?n1))))
    :ordered-subtasks (and))
    (:method open-new-stack-method-1 :parameters (?n ?n1 - count)
    :task (open-new-stack-complex ?n ?n1) :precondition
    (and (stacks-avail ?n) (next-count ?n ?n1)) :ordered-subtasks
    (and (open-new-stack ?n ?n1)))
    ; (:method reset-an-order-and-recurse :parameters (?o - order)
    ; :task
    ; (reset-order-status) :precondition
    ; (and (started ?o) (not (shipped ?o)))
    ; :ordered-subtasks
    ; (and (reset ?o) (reset-order-status)))
    ; (:method done-resetting :parameters () :task (reset-order-status)
    ; :precondition (forall (?o - order) (not (started ?o)))
    ; :ordered-subtasks (and))
    (:method ship-one-order :parameters () :task (plan-for-goals)
    :precondition (exists (?o - order) (not (shipped ?o)))
    :ordered-subtasks (and (one-step) (plan-for-goals)))
    (:method done-shipping-orders :parameters () :task (plan-for-goals)
    :precondition (forall (?order - order) (shipped ?order))
    :ordered-subtasks (and))

    ;;; ONE-STEP methods
    (:method one-step-make-product :parameters () :task (one-step)
    :precondition
    (forall (?order - order)
    (imply (not (shipped ?order))
    (exists (?p - product)
    (and (includes ?order ?p) (not (made ?p))))))
    :ordered-subtasks (and (make-a-product)))

    ; (:method repair-an-order
    ; :parameters (?o - order ?avail-prime ?avail - count)
    ; :task (one-step)
    ; :precondition
    ; (and (goal-shipped ?o)
    ; (not (shipped ?o))
    ; (not (started ?o))
    ; ;; if we must, we could maintain this predicate
    ; ;; to avoid use of FORALL.
    ; ;; (ready-to-ship ?o)
    ; (forall (?p - product) (imply (includes ?o ?p) (made ?p)))
    ; (next-count ?avail-prime ?avail))
    ; :ordered-subtasks
    ; (start-order ?o ?avail ?avail-prime))

    (:method one-step-ship-order
    :parameters (?o - order ?p - product)
    :task (one-step)
    :precondition
    ;; prefer to ship an order, if possible...
    (and (goal-shipped ?o)
    (not (shipped ?o))
    ;; if we must, we could maintain this predicate
    ;; to avoid use of FORALL.
    ;; (ready-to-ship ?o)
    (forall (?p - product) (imply (includes ?o ?p) (made ?p)))
    (started ?o))
    :ordered-subtasks
    (ship-an-order ?o))

    (:method start-an-order-and-recurse
    :parameters (?p - product ?order - order)
    :task (start-orders ?p)
    :precondition
    (exists (?o - order) (and (includes ?o ?p) (not (started ?o))))
    :ordered-subtasks
    (and (start-an-order-for ?p ?order) (start-orders ?p)))
    (:method done-starting-orders :parameters (?p - product) :task (start-orders ?p)
    :precondition
    (forall (?o - order) (imply (includes ?o ?p) (started ?o)))
    :ordered-subtasks (and))



    ;; here's a problem -- we want the product to be made only if
    ;; there are no products we can ship. But we can't make that a
    ;; precondition for this method.
    (:method make-a-product-1
    :parameters (?o - order ?p - product)
    :task (make-a-product)
    :precondition
    ; (:sort-by ?h
    (and
    (includes ?o ?p)
    (not (shipped ?o))
    (not (made ?p))
    ;; (ship-cost-heuristic ?p ?h)
    ); )
    :ordered-subtasks
    (make-product-complex ?p))

    (:method ship-an-order-1
    :parameters (?order - order ?avail ?new - count)
    :task (ship-an-order ?order)
    :precondition
    (and (goal-shipped ?order)
    (not (shipped ?order))
    (forall (?p - product) (imply (includes ?order ?p) (made ?p)))
    (stacks-avail ?avail)
    (next-count ?avail ?new))
    :ordered-subtasks
    (ship-order ?order ?avail ?new))

    (:method make-product-complex-1
    :parameters (?p - product)
    :task (make-product-complex ?p)
    :ordered-subtasks (and
    (start-orders ?p)
    (make-product ?p)))

    (:method start-an-order-for-1
    :parameters (?p - product ?o - order ?avail ?avail-prime - count)
    :task (start-an-order-for ?p ?o)
    :precondition
    (and (includes ?o ?p)
    (not (started ?o))
    (stacks-avail ?avail)
    (next-count ?avail-prime ?avail))
    :ordered-subtasks
    (start-order ?o ?avail ?avail-prime))

    (:method start-an-order-1
    :parameters (?order - order ?count ?next - count)
    :task (start-an-order ?order)
    :precondition
    (and (stacks-avail ?next)
    (next-count ?count ?next))
    :ordered-subtasks (start-order ?order ?next ?count))

    (:method ship-products-1
    :parameters (?order - order ?count ?next - count)
    :task (ship-products ?order)
    :precondition
    (and (stacks-avail ?count)
    (next-count ?count ?next))
    :ordered-subtasks
    (ship-order ?order ?count ?next))

    )
    47 changes: 47 additions & 0 deletions p01.hddl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@

    (define (problem os-sequencedstrips-p5_1)
    (:domain openstacks-sequencedstrips-adl-nocosts)
    (:requirements :hierarchy :typing :adl)
    (:objects
    n0 - count
    n1 - count
    n2 - count
    n3 - count
    n4 - count
    n5 - count
    p1 - product
    p2 - product
    p3 - product
    p4 - product
    p5 - product
    o1 - order
    o2 - order
    o3 - order
    o4 - order
    o5 - order)
    (:init
    (goal-shipped o1)
    (goal-shipped o2)
    (goal-shipped o3)
    (goal-shipped o4)
    (goal-shipped o5)
    (next-count n0 n1)
    (next-count n1 n2)
    (next-count n2 n3)
    (next-count n3 n4)
    (next-count n4 n5)
    (stacks-avail n0)
    (waiting o1)
    (includes o1 p2)
    (waiting o2)
    (includes o2 p1)
    (includes o2 p2)
    (waiting o3)
    (includes o3 p3)
    (waiting o4)
    (includes o4 p3)
    (includes o4 p4)
    (waiting o5)
    (includes o5 p5))
    (:htn :ordered-subtasks (plan))
    (:goal ()))
    86 changes: 86 additions & 0 deletions shop-plans-p01.hddl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    ==>
    1 (open-new-stack n0 n1)
    2 (open-new-stack n1 n2)
    3 (open-new-stack n2 n3)
    4 (open-new-stack n3 n4)
    5 (open-new-stack n4 n5)
    6 (start-order o5 n5 n4)
    7 (make-product p5)
    8 (ship-order o5 n4 n5)
    9 (start-order o4 n5 n4)
    10 (make-product p4)
    11 (start-order o3 n4 n3)
    12 (make-product p3)
    13 (ship-order o4 n3 n4)
    14 (ship-order o3 n4 n5)
    15 (start-order o2 n5 n4)
    16 (make-product p1)
    17 (start-order o1 n4 n3)
    18 (make-product p2)
    19 (ship-order o2 n3 n4)
    20 (ship-order o1 n4 n5)
    root 21
    21 (plan) -> plan-method-1 22 23
    22 (open-all-stacks) -> open-a-stack-and-recurse 24 25
    23 (plan-for-goals) -> ship-one-order 26 27
    24 (open-new-stack-complex n0 n1) -> open-new-stack-method-1 1
    25 (open-all-stacks) -> open-a-stack-and-recurse 28 29
    26 (one-step) -> one-step-make-product 30
    27 (plan-for-goals) -> ship-one-order 31 32
    28 (open-new-stack-complex n1 n2) -> open-new-stack-method-1 2
    29 (open-all-stacks) -> open-a-stack-and-recurse 33 34
    30 (make-a-product) -> make-a-product-1 35
    31 (one-step) -> one-step-ship-order 36
    32 (plan-for-goals) -> ship-one-order 37 38
    33 (open-new-stack-complex n2 n3) -> open-new-stack-method-1 3
    34 (open-all-stacks) -> open-a-stack-and-recurse 39 40
    35 (make-product-complex p5) -> make-product-1 41 7
    36 (ship-an-order o5) -> ship-an-order-1 8
    37 (one-step) -> one-step-make-product 42
    38 (plan-for-goals) -> ship-one-order 43 44
    39 (open-new-stack-complex n3 n4) -> open-new-stack-method-1 4
    40 (open-all-stacks) -> open-a-stack-and-recurse 45 46
    41 (start-orders p5) -> start-an-order-and-recurse 47 48
    42 (make-a-product) -> make-a-product-1 49
    43 (one-step) -> one-step-make-product 50
    44 (plan-for-goals) -> ship-one-order 51 52
    45 (open-new-stack-complex n4 n5) -> open-new-stack-method-1 5
    46 (open-all-stacks) -> done-opening-stacks
    47 (start-an-order-for p5 o5) -> start-an-order-for-1 6
    48 (start-orders p5) -> done-starting-orders
    49 (make-product-complex p4) -> make-product-1 53 10
    50 (make-a-product) -> make-a-product-1 54
    51 (one-step) -> one-step-ship-order 55
    52 (plan-for-goals) -> ship-one-order 56 57
    53 (start-orders p4) -> start-an-order-and-recurse 58 59
    54 (make-product-complex p3) -> make-product-1 60 12
    55 (ship-an-order o4) -> ship-an-order-1 13
    56 (one-step) -> one-step-ship-order 61
    57 (plan-for-goals) -> ship-one-order 62 63
    58 (start-an-order-for p4 o4) -> start-an-order-for-1 9
    59 (start-orders p4) -> done-starting-orders
    60 (start-orders p3) -> start-an-order-and-recurse 64 65
    61 (ship-an-order o3) -> ship-an-order-1 14
    62 (one-step) -> one-step-make-product 66
    63 (plan-for-goals) -> ship-one-order 67 68
    64 (start-an-order-for p3 o3) -> start-an-order-for-1 11
    65 (start-orders p3) -> done-starting-orders
    66 (make-a-product) -> make-a-product-1 69
    67 (one-step) -> one-step-make-product 70
    68 (plan-for-goals) -> ship-one-order 71 72
    69 (make-product-complex p1) -> make-product-1 73 16
    70 (make-a-product) -> make-a-product-1 74
    71 (one-step) -> one-step-ship-order 75
    72 (plan-for-goals) -> ship-one-order 76 77
    73 (start-orders p1) -> start-an-order-and-recurse 78 79
    74 (make-product-complex p2) -> make-product-1 80 18
    75 (ship-an-order o2) -> ship-an-order-1 19
    76 (one-step) -> one-step-ship-order 81
    77 (plan-for-goals) -> done-shipping-orders
    78 (start-an-order-for p1 o2) -> start-an-order-for-1 15
    79 (start-orders p1) -> done-starting-orders
    80 (start-orders p2) -> start-an-order-and-recurse 82 83
    81 (ship-an-order o1) -> ship-an-order-1 20
    82 (start-an-order-for p2 o1) -> start-an-order-for-1 17
    83 (start-orders p2) -> done-starting-orders
    <==