Skip to content

Commit 104fc01

Browse files
committed
Minor fix to FLATTEN-CONJUNCTION and its tests.
1 parent 56432b1 commit 104fc01

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

hddl-utils/hddl-checker.lisp

+5-3
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ including :task, :method, :action, :type, :predicate, :object"
220220
(unless (eq hyphen '-)
221221
(error "Ill-formed constant definition: ~a" `(,name ,hyphen ,type)))
222222
(set-name-type (domain-info name "constant definitions") :object)
223-
(verify-type-name domain-info type "constant definitions"))))
223+
(verify-type-name domain-info type "constant definitions")))
224224

225225
(defun check-objects (domain-info objects)
226226
(iter (for (name hyphen type . rest) on objects by 'cdddr)
227227
(declare (ignorable rest))
228228
(unless (eq hyphen '-)
229229
(error "Ill-formed constant definition: ~a" `(,name ,hyphen ,type)))
230230
(set-name-type (domain-info name "problem object definitions") :object)
231-
(verify-type-name domain-info type "problem object definitions"))))
231+
(verify-type-name domain-info type "problem object definitions")))
232232

233233
(defun check-initial-state (domain-info facts)
234234
(iter (for fact in facts)
@@ -277,7 +277,9 @@ Return the arity of the parameter list."
277277
(assert (eq keyword :method))
278278
(verify-task-name domain-info task-name (format nil "method task for definition of method ~a" name))
279279
(set-name-type (domain-info name (format nil "method definition of method named ~a" name)) :method)
280-
(check-method-subtasks domain-info (rest (flatten-conjunction (method-subtasks method)))
280+
(check-method-subtasks domain-info
281+
;; this way puts subtasks in flattened-conj form and then takes the list of subtasks
282+
(rest (flatten-conjunction (method-subtasks method) nil))
281283
(format nil "Subtasks of method ~a" name))))
282284

283285
(defun check-method-subtasks (domain-info subtasks &optional context)

pddl-utils.asd

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@
3030
:version (:read-file-form "version.lisp-expr")
3131
:serial t
3232
:class :fiveam-tester-system
33-
:test-names ((#:problem-acc . :pddl-utils-tests)
34-
(#:domain-acc . :pddl-utils-tests)
35-
(#:domain-well-defined-p . :pddl-utils-tests)
36-
(#:predicate-definitions-correct-p . :pddl-utils-tests)
37-
(#:predicate-DONE-member-p . :pddl-utils-tests)
38-
(#:types-correct-p . :pddl-utils-tests)
33+
:test-names ((#:pddl-utils-tests . :pddl-utils-tests)
3934
)
4035
:pathname "utils/tests/"
4136
:components ((:file "package")

utils/commons.lisp

+11-6
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,10 @@ Translates to (constant . type) alist."
611611
(member (first sexp) predicates)
612612
t)))
613613

614-
(defun flatten-conjunction (conj)
615-
"Take an s-expression and, if it is a multilayer conjunction,
616-
make it a single-layer conjunction (intermediate AND's removed)."
614+
(defun flatten-conjunction (conj &optional (strict t))
615+
"Take an s-expression and, if it is a multilayer conjunction.
616+
Returns a single-layer conjunction (intermediate AND's, if any,
617+
removed)."
617618
(labels ((flatten-conj-list (cl)
618619
(alexandria:mappend #'flatten-1 cl))
619620
(flatten-1 (conj)
@@ -628,6 +629,10 @@ make it a single-layer conjunction (intermediate AND's removed)."
628629
(error "Cannot handle negations other than negated literals in flatten-conjunction: ~s"
629630
conj)))
630631
(otherwise (list conj)))))
631-
(if (eq (first conj) 'and)
632-
`(and ,@ (flatten-conj-list (rest conj)))
633-
(flatten-1 conj))))
632+
(cond ((eq (first conj) 'and)
633+
`(and ,@(flatten-conj-list (rest conj))))
634+
(strict (error "FLATTEN-CONJUNCTION expects a conjunction as input, not an implicit conjunction."))
635+
(t
636+
;; in this case we have an implicit conjunction with no initial 'and
637+
;; supply one.
638+
`(and ,@(flatten-conj-list conj))))))

utils/tests/domain-test.lisp

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(in-package :pddl-utils-tests)
22

3+
(def-suite* pddl-utils-tests)
4+
35
(defparameter *tests-dir*
46
(namestring
57
(translate-logical-pathname
@@ -16,10 +18,10 @@
1618
(if (and (not (= pos 0))
1719
(eql (nth (1- pos) typed-list) '-))
1820
;; then the TYPE-EL is a parent type itself.
19-
;; Skip this occurrence of the symbol in the TYPED-LIST.
21+
;; Skip this occurrence of the symbol in the TYPED-LIST.
2022
(problem-free-p type-el (subseq typed-list (1+ pos)))
2123
;; Otherwise, TYPE-EL is a subtype so look for if we have its
22-
;; parent.
24+
;; parent.
2325
(let ((next-parent-type
2426
(position '- (subseq typed-list (1+ pos)))))
2527
(if (null next-parent-type)
@@ -32,7 +34,7 @@
3234
(return-from problem-free-p nil))
3335
;; Else there is a parent type. That's ok, but check if this
3436
;; TYPE-EL belongs to another parent now...
35-
(problem-free-p type-el
37+
(problem-free-p type-el
3638
(subseq typed-list (1+
3739
next-parent-type)))))))
3840
t))
@@ -79,14 +81,14 @@
7981
(read-planning-input
8082
(merge-pathnames "airport-nontemporal-adl-domain.pddl"
8183
*tests-dir*))))
82-
(setf (domain-predicates domain)
84+
(setf (domain-predicates domain)
8385
(append (domain-predicates domain)
8486
(list '(DONE))))
8587
(&body)))
8688

8789

8890
(test types-correct-p
89-
(with-fixture
91+
(with-fixture
9092
well-defined-pddl-objects ()
9193
;; Check for simple subtyping -- every
9294
;; type should have a parent type, except the type
@@ -95,13 +97,13 @@
9597
(problem-free-p element
9698
(copy-tree (domain-types domain))))
9799
(domain-types domain)))))
98-
100+
99101
(test predicate-definitions-correct-p
100102
(with-fixture
101103
well-defined-pddl-objects ()
102104
;; Check for duplicates...
103105
(is (every #'(lambda (element)
104-
(let ((element-trail
106+
(let ((element-trail
105107
(member element (domain-predicates
106108
domain)
107109
:test #'equal)))
@@ -116,10 +118,10 @@
116118
:test #'equal))))
117119

118120
(test domain-well-defined-p
119-
(with-fixture
121+
(with-fixture
120122
well-defined-pddl-objects ()
121123
(is (every #'keywordp (domain-reqs domain)))
122-
(is (every #'(lambda (el)
124+
(is (every #'(lambda (el)
123125
(member el *pddl-keywords* :test #'eql))
124126
(domain-reqs domain)))))
125127

@@ -224,4 +226,8 @@
224226
(flatten-conjunction *conjunction*)))
225227
(is
226228
(equalp *flattened-nested-conjunction*
227-
(flatten-conjunction *nested-conjunction*))))
229+
(flatten-conjunction *nested-conjunction*)))
230+
(is (equalp *conjunction*
231+
(flatten-conjunction (rest *conjunction*) nil)))
232+
;; check strict mode
233+
(signals error (flatten-conjunction (rest *conjunction*) t)))

utils/tests/package.lisp

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
(:use common-lisp pddl-utils)
55
(:import-from :pddl-utils #:flatten-conjunction)
66
(:import-from fiveam
7+
#:def-suite*
78
#:def-fixture
89
#:with-fixture
910
#:is
1011
#:test
12+
#:signals
1113
#:run!
1214
#:*on-error*))

0 commit comments

Comments
 (0)