Skip to content

Commit d937ad7

Browse files
authored
Merge pull request #18 from rpgoldman/hddl-parse-plan
2 parents 7810818 + 771cf5c commit d937ad7

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

hddl-utils/commons.lisp

+9-1
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,18 @@ element to *remain*.
441441
`(let ((*pddl-package* *hddl-package*))
442442
(setf (pddl-utils:domain-predicates ,domain) ,new-pred-list)))
443443

444+
(defun hddl-plan-p (sexp)
445+
(and (listp sexp) (eq (first sexp) :hddl-plan)))
446+
447+
(deftype hddl-plan ()
448+
"An HDDL-PLAN is an s-expression headed by :HDDL-PLAN and whose
449+
CDR is a property list with :ACTIONS, :ROOTS and :DECOMOPOSITIONS."
450+
'(satisfies hddl-plan-p))
451+
444452
(defun hddl-plan-to-pddl-plan (hddl-plan)
445453
"Take the S-expression form of an HDDL plan and return a PDDL plan extracted from it."
446454
(pddlify-tree
447-
(mapcar #'cdr (getf hddl-plan :actions))))
455+
(mapcar #'cdr (getf (cdr hddl-plan) :actions))))
448456

449457
(defun hddl-domain-to-pddl-domain (hddl-domain)
450458
(pddl-utils:make-domain (domain-name hddl-domain)

hddl-utils/package.lisp

+1
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@
9696
#:hddl-problem-to-pddl-problem
9797
#:canonicalize-problem
9898
#:hddl-variable
99+
#:hddl-plan ; type
99100
)
100101
)

hddl-utils/tests/extract-seq.hddl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
==>
2+
1 switch_on instrument0 satellite0
3+
29 turn_to satellite0 groundstation2 star0
4+
30 calibrate satellite0 instrument0 groundstation2
5+
4 turn_to satellite0 phenomenon6 groundstation2
6+
5 take_image satellite0 phenomenon6 instrument0 thermograph0
7+
6 turn_to satellite0 star5 phenomenon6
8+
7 take_image satellite0 star5 instrument0 thermograph0
9+
8 turn_to satellite0 phenomenon4 star5
10+
9 take_image satellite0 phenomenon4 instrument0 thermograph0
11+
12+
root 10
13+
10 main -> take-one 11 12
14+
11 have-image phenomenon6 thermograph0 -> prepare-then-take 13 14
15+
13 prepare-instrument satellite0 instrument0 -> prepare 17 18
16+
17 turn-on-instrument satellite0 instrument0 -> turn-on 1
17+
18 calibrate-instrument satellite0 instrument0 -> repoint-then-calibrate 29 30
18+
14 take-image satellite0 instrument0 phenomenon6 thermograph0 -> turn-then-take 4 5
19+
12 main -> take-one 15 16
20+
15 have-image star5 thermograph0 -> prepare-then-take 19 20
21+
19 prepare-instrument satellite0 instrument0 -> prepare 23 24
22+
23 turn-on-instrument satellite0 instrument0 -> already-on
23+
24 calibrate-instrument satellite0 instrument0 -> no-calibration-needed
24+
20 take-image satellite0 instrument0 star5 thermograph0 -> turn-then-take 6 7
25+
16 main -> take-one 21 22
26+
21 have-image phenomenon4 thermograph0 -> prepare-then-take 25 26
27+
25 prepare-instrument satellite0 instrument0 -> prepare 27 28
28+
27 turn-on-instrument satellite0 instrument0 -> already-on
29+
28 calibrate-instrument satellite0 instrument0 -> no-calibration-needed
30+
26 take-image satellite0 instrument0 phenomenon4 thermograph0 -> turn-then-take 8 9
31+
22 main -> all-done
32+
<==
33+

hddl-utils/tests/tests.lisp

+18
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,21 @@
254254
(copy-tree *method-subtasks*))
255255
(is (equalp template method)))
256256
)
257+
258+
(test extract-sequence
259+
(let* ((plan (hddl-utils:read-hddl-plan-file
260+
(asdf:system-relative-pathname "hddl-utils"
261+
"hddl-utils/tests/extract-seq.hddl")))
262+
(seq (hddl-utils:hddl-plan-to-pddl-plan plan)))
263+
(is (equalp
264+
(pddl-utils:pddlify-tree
265+
'((SWITCH_ON INSTRUMENT0 SATELLITE0)
266+
(TURN_TO SATELLITE0 GROUNDSTATION2 STAR0)
267+
(CALIBRATE SATELLITE0 INSTRUMENT0 GROUNDSTATION2)
268+
(TURN_TO SATELLITE0 PHENOMENON6 GROUNDSTATION2)
269+
(TAKE_IMAGE SATELLITE0 PHENOMENON6 INSTRUMENT0 THERMOGRAPH0)
270+
(TURN_TO SATELLITE0 STAR5 PHENOMENON6)
271+
(TAKE_IMAGE SATELLITE0 STAR5 INSTRUMENT0 THERMOGRAPH0)
272+
(TURN_TO SATELLITE0 PHENOMENON4 STAR5)
273+
(TAKE_IMAGE SATELLITE0 PHENOMENON4 INSTRUMENT0 THERMOGRAPH0)))
274+
seq))))

hddl/hddl-pprint.lisp

+9-21
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,6 @@ FOO BAR - TYPE1 BAZ - TYPE2."
5454
(let ((*package* (find-package *hddl-package*)))
5555
(read stream nil nil)))
5656

57-
58-
#|
59-
60-
(defun print-pddl-plan-to-file (sexp filename &optional (if-exists :error))
61-
"Print a PDDL plan to a file in IPC format that the VAL
62-
plan validator will read."
63-
(with-open-file (str filename :direction :output :if-exists if-exists)
64-
(print-pddl-plan sexp str)))
65-
66-
(defun print-pddl-plan (sexp &optional (stream t))
67-
"Print a PDDL plan in a format that the VAL
68-
validator will read it: one action s-expression per
69-
line."
70-
(let ((*package* (find-package *pddl-package*))
71-
(*print-pretty* nil))
72-
(dolist (step sexp)
73-
(prin1 step stream)
74-
(terpri stream))))
75-
|#
76-
7757
(defun read-HDDL-plan-file (filename)
7858
"Read a HDDL plan from FILENAME and return it
7959
in the form of a list of actions."
@@ -116,7 +96,15 @@ in the form of a list of actions."
11696
(t :default))))
11797
(setf actions
11898
(iter (for line initially first-line then (read-line stream))
119-
(when (string= (subseq line 0 4) "root")
99+
(when (string= (string-trim () line) "")
100+
(next-iteration))
101+
(when (string= (handler-case (subseq line 0 4)
102+
#+sbcl(sb-kernel:bounding-indices-bad-error ()
103+
"")
104+
;; AFAICT, neither Allegro nor CCL
105+
;; have distinct array bound errors.
106+
#-sbcl (error () ""))
107+
"root")
120108
;; done reading actions
121109
(setf root-line line)
122110
(finish))

version.lisp-expr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"3.2.4"
1+
"3.3.0"

0 commit comments

Comments
 (0)