Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alternative HDDL plan formats. #12

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions hddl-utils/tests/example-plan-comma-separated.hddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
==>
0 drive truck-0, city-loc-2, city-loc-1
1 pick-up truck-0, city-loc-1, package-0, capacity-0, capacity-1
2 drive truck-0, city-loc-1, city-loc-0
3 drop truck-0, city-loc-0, package-0, capacity-0, capacity-1
4 drive truck-0, city-loc-0, city-loc-1
5 pick-up truck-0, city-loc-1, package-1, capacity-0, capacity-1
6 drive truck-0, city-loc-1, city-loc-2
7 drop truck-0, city-loc-2, package-1, capacity-0, capacity-1
root 15 14
8 load truck-0, city-loc-1, package-0 -> m-load 1
9 unload truck-0, city-loc-0, package-0 -> m-unload 3
10 get-to truck-0, city-loc-1, -> m-drive-to 0
11 unload truck-0, city-loc-2, package-1 -> m-unload 7
12 get-to truck-0, city-loc-0 -> m-drive-to 2
13 load truck-0, city-loc-1, package-1 -> m-load 5
14 deliver package-0, city-loc-0 -> m-deliver 10 8 12 9
15 deliver package-1, city-loc-2 -> m-deliver 16 13 17 11
16 get-to truck-0, city-loc-1 -> m-drive-to 4
17 get-to truck-0, city-loc-2 -> m-drive-to 6
20 changes: 20 additions & 0 deletions hddl-utils/tests/example-plan-sexp.hddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
==>
0 (drive truck-0 city-loc-2 city-loc-1)
1 (pick-up truck-0 city-loc-1 package-0 capacity-0 capacity-1)
2 (drive truck-0 city-loc-1 city-loc-0)
3 (drop truck-0 city-loc-0 package-0 capacity-0 capacity-1)
4 (drive truck-0 city-loc-0 city-loc-1)
5 (pick-up truck-0 city-loc-1 package-1 capacity-0 capacity-1)
6 (drive truck-0 city-loc-1 city-loc-2)
7 (drop truck-0 city-loc-2 package-1 capacity-0 capacity-1)
root 15 14
8 (load truck-0 city-loc-1 package-0) -> m-load 1
9 (unload truck-0 city-loc-0 package-0) -> m-unload 3
10 (get-to truck-0 city-loc-1) -> m-drive-to 0
11 (unload truck-0 city-loc-2 package-1) -> m-unload 7
12 (get-to truck-0 city-loc-0) -> m-drive-to 2
13 (load truck-0 city-loc-1 package-1) -> m-load 5
14 (deliver package-0 city-loc-0) -> m-deliver 10 8 12 9
15 (deliver package-1 city-loc-2) -> m-deliver 16 13 17 11
16 (get-to truck-0 city-loc-1) -> m-drive-to 4
17 (get-to truck-0 city-loc-2) -> m-drive-to 6
59 changes: 55 additions & 4 deletions hddl-utils/tests/hddl-data.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,67 @@
(cl:defparameter hddl-utils-tests::*method*
'(:task get-to :parameters (?l - location)))

#|
(cl:defparameter hddl-utils-tests::*parsed-plan*
'(:HDDL-PLAN :ACTIONS
((0 DRIVE TRUCK-0 CITY-LOC-2
CITY-LOC-1)
(1 PICK-UP TRUCK-0 CITY-LOC-1
PACKAGE-0 CAPACITY-0 CAPACITY-1)
(2 DRIVE TRUCK-0 CITY-LOC-1
CITY-LOC-0)
(3 DROP TRUCK-0 CITY-LOC-0
PACKAGE-0 CAPACITY-0 CAPACITY-1)
(4 DRIVE TRUCK-0 CITY-LOC-0
CITY-LOC-1)
(5 PICK-UP TRUCK-0 CITY-LOC-1
PACKAGE-1 CAPACITY-0 CAPACITY-1)
(6 DRIVE TRUCK-0 CITY-LOC-1
CITY-LOC-2)
(7 DROP TRUCK-0 CITY-LOC-2
PACKAGE-1 CAPACITY-0 CAPACITY-1))
:ROOTS (15 14) :DECOMPOSITIONS
((8
(LOAD TRUCK-0 CITY-LOC-1
PACKAGE-0)
M-LOAD 1)
(9
(UNLOAD TRUCK-0 CITY-LOC-0
PACKAGE-0)
M-UNLOAD 3)
(10 (GET-TO TRUCK-0 CITY-LOC-1)
M-DRIVE-TO 0)
(11
(UNLOAD TRUCK-0 CITY-LOC-2
PACKAGE-1)
M-UNLOAD 7)
(12 (GET-TO TRUCK-0 CITY-LOC-0)
M-DRIVE-TO 2)
(13
(LOAD TRUCK-0 CITY-LOC-1
PACKAGE-1)
M-LOAD 5)
(14 (DELIVER PACKAGE-0 CITY-LOC-0)
M-DELIVER 10 8 12 9)
(15 (DELIVER PACKAGE-1 CITY-LOC-2)
M-DELIVER 16 13 17 11)
(16 (GET-TO TRUCK-0 CITY-LOC-1)
M-DRIVE-TO 4)
(17 (GET-TO TRUCK-0 CITY-LOC-2)
M-DRIVE-TO 6))))

(cl:defparameter hddl-utils-tests::*expected-task*
'(drive truck-0 city-loc-2 city-loc-1))

#|
(cl:defparameter pddl-utils-tests::*pddl-keywords*
'(:adl :strips
:typing
'(:adl :strips
:typing
:negative-preconditions
:disjunctive-preconditions
:equality
:existential-preconditions
:universal-preconditions
:quantified-preconditions
:quantified-preconditions
:existential-preconditions
:universal-preconditions
:conditional-effects
Expand Down
22 changes: 22 additions & 0 deletions hddl-utils/tests/tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,25 @@
(is (equalp goal-expr (hddl-utils:problem-goal problem)))
)
)



(test check-reading-plan
(let ((plan (hddl-utils:read-hddl-plan-file
(asdf:system-relative-pathname "hddl-utils" "hddl-utils/tests/example-plan.hddl"))))
(is (equalp *parsed-plan* plan))))

(test check-reading-plan-sexp
(let ((plan (hddl-utils:read-hddl-plan-file
(asdf:system-relative-pathname "hddl-utils" "hddl-utils/tests/example-plan-sexp.hddl"))))
(is (equalp *parsed-plan* plan))))

(test check-comma-separated-task
(let ((string "drive truck-0, city-loc-2, city-loc-1"))
(is (equalp *expected-task*
(hddl-pprinter::comma-separated-task->sexp string)))))

(test check-reading-plan-comma-separated
(let ((plan (hddl-utils:read-hddl-plan-file
(asdf:system-relative-pathname "hddl-utils" "hddl-utils/tests/example-plan-comma-separated.hddl"))))
(is (equalp *parsed-plan* plan))))
26 changes: 21 additions & 5 deletions hddl/hddl-pprint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ in the form of a list of actions."
(with-open-file (str filename)
(read-HDDL-plan str)))

(defun comma-separated-task->sexp (raw-string)
(let* ((string (string-upcase raw-string))
(task-name-pos (or (position #\space string)
(error "Unable to parse task from \"~a\"" raw-string)))
(task-name (string-right-trim (list #\space) (subseq string 0 task-name-pos)))
(parameters
(mapcar #'(lambda (x) (string-right-trim (list #\space)
(string-left-trim (list #\space) x)))
(cl-ppcre:split "," string :start (1+ task-name-pos)))))
(mapcar #'hddl-symbol (cons task-name parameters))))

(defun read-HDDL-plan (stream)
;; FIXME: rewrite the docstring with return value
"Read a HDDL plan from STREAM and return it
Expand Down Expand Up @@ -115,11 +126,9 @@ in the form of a list of actions."
(cons id
(ecase format
(:comma-separated
(let ((components
(cl-ppcre:split "," line :start (1+ pos))))
(mapcar #'hddl-symbol components)))
(comma-separated-task->sexp (subseq (string-upcase line) (1+ pos))))
(:s-expression
(let ((*package* *hddl-package*))
(let ((*package* (find-package *hddl-package*)))
(read-from-string line t nil :start (1+ pos))))
(:default
(space-separated-string->hddl-list (subseq line pos))
Expand All @@ -144,7 +153,14 @@ in the form of a list of actions."
(partition-method-line (subseq line (1+ pos)))
(declare (type string task-string method-id subtasks))
(collecting `(,id
,(space-separated-string->hddl-list task-string)
,(ecase format
(:default
(space-separated-string->hddl-list (string-upcase task-string)))
(:s-expression
(let ((*package* (find-package *hddl-package*)))
(read-from-string task-string)))
(:comma-separated
(comma-separated-task->sexp (string-upcase task-string))))
.
(,(intern (string-upcase method-id) *hddl-package*)
,@(read-integer-list subtasks))))))))
Expand Down
2 changes: 1 addition & 1 deletion version.lisp-expr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"3.1.0"
"3.1.1"