-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanlib.lisp
More file actions
139 lines (121 loc) · 5.18 KB
/
Copy pathplanlib.lisp
File metadata and controls
139 lines (121 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(in-package :monroe)
;; code for generating the plan library file
;; (defun lplib ()
;; ;; loads this
;; (load "planlib"))
(defmethod get-top-goal-schemas ((obj monroe-config))
;; returns a list of the top goals of the domain
;; they are found in the variable *top-goals*
(mapcar #'(lambda (val)
(car val))
*top-goals*))
(defmethod get-goal-schemas ((obj monroe-config))
;; returns a list of the goals of the domain
;; in case of flat recognition, these are also the top goals
;; for hierarchical, they include the top and subgoals
(if *flat-output*
(get-top-goal-schemas obj)
(get-method-schemas obj)))
(defmethod get-method-schemas ((obj monroe-config))
;; returns a list of *unique* method schemas from the domain
;; so things like get-to will just be 1 schema, even though there
;; are many different method bodies
(let ((mhash (make-hash-table)))
;; make unique list to return
(mapcar #'(lambda (method)
(let ((name (schema-name method)))
(setf (gethash name mhash) method)))
;; get a list of all methods (including duplicates)
(mymaphash #'(lambda (key val)
(declare (ignore key))
(method-schema val))
(shop2::domain-methods (find-domain (domain-name obj)))))
(gethashvals mhash)))
(defun method-schema (method)
(cadar method))
(defun get-operator-schemas (config)
;; returns a list of operator schemas from domain
(mymaphash #'(lambda (key val)
(declare (ignore key))
(operator-schema val))
(shop2::domain-operators (find-domain (domain-name config)))))
(defun schema-name (schema)
;; returns name of a schema header
(first schema))
(defun schema-arity (schema)
;; returns arity of a schema header
(length (rest schema)))
(defun operator-schema (operator)
;; given an operator, returns its schema header (in form (!op ?arg ?arg))
(shop2::operator-head operator))
(defun output-max-depth (outfile max-depth)
;; outputs a line saying how deep the max depth for this
;; library is
(format outfile "Max Depth: ~d~%~%" max-depth))
(defun output-top-goals (config-obj outfile)
;; outputs a list of the top-level goals of the domain, as defined
;; in the <domain>_plib.lisp file as *top-goals*
(format outfile "Top-level Goals:~%")
(mapcar (lambda (val)
(format outfile
"~A~%"
(act-to-string val)))
(get-top-goal-schemas config-obj)))
(defun output-subgoals (config-obj outfile)
;; outputs all subgoals. this includes top-goals as well, as they
;; could potentially be subgoals
(format outfile "~%Subgoals:~%")
(mapcar (lambda (val)
(format outfile
"~A~%"
(act-to-string val)))
(get-goal-schemas config-obj)))
(defun output-atomic-actions (config outfile)
(format outfile "~%Atomic Actions:~%")
(mapcar (lambda (val)
;; FIXME: probably should remove *all* internal operators.
(if (not (eq (car val) '!!inop)) ;; don't include internal !!INOP
(format outfile
"~A~%"
(act-to-string val))))
(get-operator-schemas config)))
(defun output-common-state (config stream)
(format stream "~%Common problem state:")
(let ((fixed-state (sort (copy-tree (common-state config)) 'prop-compare)))
(let ((*print-readably* t)
(*package* (plan-package config)))
(mapc #'(lambda (prop) (print prop stream)) fixed-state))))
(defun prop-compare (prop1 prop2)
(labels ((compare-next (l1 l2)
(cond ((null l1)
;; if L1 is shorter, it's first
(not (null l2)))
((null l2) nil)
(t
(let ((elem1 (first l1))
(elem2 (first l2)))
(cond ((listp elem2)
(if (listp elem1)
(compare-next elem1 elem2)
nil))
;; neither is a list (function), so both atoms
(t (let ((se1 (string elem1))
(se2 (string elem2)))
(cond
((string-lessp se1 se2)
t)
((string-lessp se2 se1)
nil)
(t (compare-next (rest l1) (rest l2))))))))))))
(compare-next prop1 prop2)))
(defun output-planlib (config-obj plib-filename max-depth)
;; main function: writes out a planlib file
;; which can be compiled into a plan library for perl
(with-open-file (outfile plib-filename :direction :output
:if-exists :supersede
:if-does-not-exist :create)
(output-max-depth outfile max-depth)
(output-top-goals config-obj outfile)
(output-subgoals config-obj outfile)
(output-atomic-actions config-obj outfile)
(output-common-state config-obj outfile)))