-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpddl_domainfile_vtl_template.pddl
147 lines (130 loc) · 6.53 KB
/
pddl_domainfile_vtl_template.pddl
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
140
141
142
143
144
145
146
147
## Set main PDDL domain file
#set($pddlDomainElement = $elementScope.get(0))
## Check if element scope has stereotype PDDL_Domainfile
#if(!$report.containsStereotype($pddlDomainElement, "PDDL_Domain"))
ERROR: SCOPE IS NO "PDDL_Domainfile"
#else
## Set domain name variable from SysML model
#set($pddlDomainName = $pddlDomainElement.name)
(define (domain $pddlDomainName)
(:requirements :typing :negative-preconditions :fluents)
(:types
#foreach($typeElement in $pddlDomainElement.types)
#set($currentTypeElement = $typeElement)
## Recursive function to handle all levels of subtypes
#macro (generateTypeHierarchy $parentTypeElement)
#foreach($subtypeElement in $parentTypeElement.subtype)
$subtypeElement.name - $parentTypeElement.name
#generateTypeHierarchy($subtypeElement) ## Recursive call for further subtypes
#end
#end
## Call the macro for the current type
#generateTypeHierarchy($currentTypeElement)
#end
)
(:predicates
#foreach($predicateElement in $pddlDomainElement.predicates)
#set($predicateName = $predicateElement.predicatename)
## Check if predicate has a name and parts before proceeding
#if($predicateName && $predicateElement.predicatepart)
($predicateName
#foreach($predicatePart in $predicateElement.predicatepart)
#set($variableName = $predicatePart.variable.variable)
#set($variableTypeName = $predicatePart.variabletype.name)
#if($variableName && $variableTypeName)
$variableName - $variableTypeName
#else
ERROR: MISSING VARIABLE OR VARIABLE TYPE FOR PREDICATE $predicateName
#end
#end)
#else
ERROR: PREDICATE $predicateElement IS MISSING NAME OR PARTS
#end
#end
)
(:functions
(total-cost) - number
#foreach($functionElement in $pddlDomainElement.functions)
#set($functionName = $functionElement.functionname)
## Check if function name and parts are defined
#if($functionName && $functionElement.functionpart)
($functionName
#foreach($functionPart in $functionElement.functionpart)
#set($functionVariableName = $functionPart.variable.variable)
#set($functionVariableTypeName = $functionPart.variabletype.name)
#if($functionVariableName && $functionVariableTypeName)
$functionVariableName - $functionVariableTypeName
#else
ERROR: MISSING VARIABLE OR VARIABLE TYPE FOR FUNCTION $functionName
#end
#end)
#else
ERROR: FUNCTION $functionElement IS MISSING NAME OR PARTS
#end
#end
)
## Action Generation
#foreach ($actionElement in $pddlDomainElement.action)
#set($actionName = $actionElement.name)
## Check if action has a name and defined parameters, preconditions, and effects
#if($actionName && $actionElement.parameters && $actionElement.precondition && $actionElement.effect)
(:action $actionName
## Generate parameters with type checking
:parameters (#foreach($parameterElement in $actionElement.parameters)
#set($parameterName = $parameterElement.variablename.variable)
#set($parameterTypeName = $parameterElement.variable_is_of_type.name)
#if($parameterName && $parameterTypeName)
$parameterName - $parameterTypeName
#else
ERROR: MISSING PARAMETER NAME OR TYPE FOR ACTION $actionName
#end
#end)
## Generate preconditions
#set($preconditions = "")
#set($preconditionCount = 0)
#foreach($preconditionElement in $actionElement.precondition.predicates_have_to_be_true.predicates_are_switched)
#set($preconditionPredicateName = $preconditionElement.predicatename.predicatename)
#if($preconditionPredicateName)
#if($preconditionElement.inverse)
#set($preconditions = "$preconditions (not ($preconditionPredicateName #foreach($parameter in $preconditionElement.parameter) $parameter.variable #end))")
#else
#set($preconditions = "$preconditions ($preconditionPredicateName #foreach($parameter in $preconditionElement.parameter) $parameter.variable #end)")
#end
#set($preconditionCount = $preconditionCount + 1)
#else
ERROR: MISSING PREDICATE NAME FOR PRECONDITION IN ACTION $actionName
#end
#end
#if($preconditionCount > 1)
:precondition (and $preconditions)
#elseif($preconditionCount == 1)
:precondition $preconditions
#end
## Generate effects
#set($effects = "")
#set($effectCount = 0)
#foreach($effectElement in $actionElement.effect.logical_expression.predicates_are_switched)
#set($effectPredicateName = $effectElement.predicatename.predicatename)
#if($effectPredicateName)
#if($effectElement.inverse)
#set($effects = "$effects (not ($effectPredicateName #foreach($effectParameter in $effectElement.parameter) $effectParameter.variable #end))")
#else
#set($effects = "$effects ($effectPredicateName #foreach($effectParameter in $effectElement.parameter) $effectParameter.variable #end)")
#end
#set($effectCount = $effectCount + 1)
#else
ERROR: MISSING PREDICATE NAME FOR EFFECT IN ACTION $actionName
#end
#end
#if($effectCount > 1)
:effect (and $effects)
#elseif($effectCount == 1)
:effect $effects
#end
)
#else
ERROR: ACTION $actionElement IS MISSING NAME, PARAMETERS, PRECONDITIONS, OR EFFECTS
#end
#end
)
#end