Fawkes API Fawkes Development Version
pddl_ast.h
1
2/***************************************************************************
3 * pddlast.h
4 *
5 * Created: Fri 19 May 2017 14:07:13 CEST
6 * Copyright 2017 Matthias Loebach
7 * Till Hofmann
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#ifndef PLUGINS_PDDL_AST_H_
24#define PLUGINS_PDDL_AST_H_
25
26#include <boost/fusion/include/adapt_struct.hpp>
27#include <boost/fusion/include/std_pair.hpp>
28#include <boost/spirit/include/qi.hpp>
29#include <boost/spirit/include/support_line_pos_iterator.hpp>
30#include <string>
31#include <vector>
32
33namespace pddl_parser {
34namespace qi = boost::spirit::qi;
35namespace ascii = boost::spirit::ascii;
36
37typedef std::pair<std::string, std::string> pair_type;
38typedef std::vector<pair_type> pairs_type;
39
40typedef std::vector<std::string> type_list;
41typedef std::pair<type_list, std::string> pair_multi_const;
42typedef std::vector<pair_multi_const> pairs_multi_consts;
43typedef std::pair<std::vector<std::string>, std::vector<std::string>> pair_strings_type;
44
45typedef std::pair<std::string, std::string> string_pair_type;
46typedef std::vector<string_pair_type> string_pairs_type;
47typedef std::pair<std::string, string_pairs_type> predicate_type;
48
49typedef boost::spirit::line_pos_iterator<std::string::const_iterator> iterator_type;
50
51using Atom = std::string;
52
53struct Predicate;
54struct QuantifiedFormula;
55
56enum ExpressionType {
57 BOOL,
58 NUMERIC_COMP,
59 PREDICATE,
60 NUMERIC,
61 NUMERIC_CHANGE,
62 VALUE,
63 ATOM,
64 DURATIVE,
65 QUANTIFIED,
66 COND_EFFECT,
67 UNKNOWN
68};
69
70typedef boost::
71 variant<Atom, boost::recursive_wrapper<Predicate>, boost::recursive_wrapper<QuantifiedFormula>>
72 expression_t;
73
74/** @class Expression
75 * A PDDL Expression.
76 */
78{
79 /** The type of the expression, determined at parsing time. */
80 ExpressionType type;
81 /** The expression formula */
82 expression_t expression;
83};
84
85/** @class QuantifiedFormula
86 * A PDDL quantified formula.
87 */
89{
90 /** The name of the quantifier ('exists' or 'forall') */
92
93 /** args that are bound by the quantifier */
94 string_pairs_type args;
95
96 /** Sub-expression that is quantified over */
98};
99
100/** @class Predicate
101 * A PDDL formula (either part of a precondition or an effect(.
102 * Note that this is NOT necesarily a PDDL predicate, but may also be a
103 * compound formula. For a conjunction, the function would be 'and', and the
104 * arguments would be the subformulae.
105 */
107{
108 /** The name of the predicate for atomic formulae, 'and' for a conjunction,
109 * 'or' for a disjunction, 'not' for a negation.
110 */
112 /** The arguments of the predicate or the subformulae of the compound
113 * formula.
114 */
115 std::vector<Expression> arguments;
116};
117
118/** @class Function
119 * A structured representation of a PDDL function.
120 */
122{
123 /** The name of the function. */
124 std::string name;
125 /** A typed list of function parameters. */
126 string_pairs_type object_params;
127};
128
129/** @class Action
130 * A structured representation of a PDDL action.
131 */
132struct Action
133{
134 /** The name of the action. */
135 std::string name;
136 /** A typed list of action parameters. */
137 string_pairs_type action_params;
138 /** The action duration in temporal domains. */
140 /** The precondition of an action. May be a compound. */
142 /** The effect of an action. May be a compound. */
144 /** Used by the STN generator to determine conditional break points in the
145 * STN.
146 */
148 /** Used by the STN generator to determine temporal break points in the STN.
149 */
151};
152
153/** @class Domain
154 * A structured representation of a PDDL domain.
155 */
156struct Domain
157{
158 /** The name of the domain. */
159 std::string name;
160 /** A list of PDDL features required by the domain. */
161 std::vector<std::string> requirements;
162 /** A list of types with their super types. */
163 pairs_type types;
164 /** A typed list of constants defined in the domain. */
165 pairs_multi_consts constants;
166 /** A list of predicate names in the domain, including the types of their
167 * arguments.
168 */
169 std::vector<predicate_type> predicates;
170 /** A list of numeric functions in the domain. */
171 std::vector<Function> functions;
172 /** A list of actions defined in the domain. */
173 std::vector<Action> actions;
174};
175
176/** @class Problem
177 * A structured representation of a PDDL problem.
178 */
180{
181 /** The name of the problem. */
182 std::string name;
183 /** The name of the domain this problem belongs to. */
184 std::string domain_name;
185 /** A typed list of objects in the domain. */
186 pairs_multi_consts objects;
187 /** A list of facts that are initially true. */
188 std::vector<Expression> init;
189 /** The goal of the problem. */
191};
192
193} // namespace pddl_parser
194
195BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Domain,
196 name,
197 requirements,
198 types,
199 constants,
200 predicates,
201 functions,
202 actions)
203
204BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Problem, name, domain_name, objects, init, goal)
205
206BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Action,
207 name,
208 action_params,
209 duration,
210 precondition,
211 effect,
212 cond_breakup,
213 temp_breakup)
214
215BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Predicate, function, arguments)
216BOOST_FUSION_ADAPT_STRUCT(pddl_parser::QuantifiedFormula, quantifier, args, sub_expr)
217
218BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Function, name, object_params)
219BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Expression, type, expression)
220
221#endif
A structured representation of a PDDL action.
Definition: pddl_ast.h:133
Expression duration
The action duration in temporal domains.
Definition: pddl_ast.h:139
Expression cond_breakup
Used by the STN generator to determine conditional break points in the STN.
Definition: pddl_ast.h:147
string_pairs_type action_params
A typed list of action parameters.
Definition: pddl_ast.h:137
std::string name
The name of the action.
Definition: pddl_ast.h:135
Expression effect
The effect of an action.
Definition: pddl_ast.h:143
Expression temp_breakup
Used by the STN generator to determine temporal break points in the STN.
Definition: pddl_ast.h:150
Expression precondition
The precondition of an action.
Definition: pddl_ast.h:141
A structured representation of a PDDL domain.
Definition: pddl_ast.h:157
std::vector< Action > actions
A list of actions defined in the domain.
Definition: pddl_ast.h:173
std::string name
The name of the domain.
Definition: pddl_ast.h:159
pairs_multi_consts constants
A typed list of constants defined in the domain.
Definition: pddl_ast.h:165
pairs_type types
A list of types with their super types.
Definition: pddl_ast.h:163
std::vector< predicate_type > predicates
A list of predicate names in the domain, including the types of their arguments.
Definition: pddl_ast.h:169
std::vector< std::string > requirements
A list of PDDL features required by the domain.
Definition: pddl_ast.h:161
std::vector< Function > functions
A list of numeric functions in the domain.
Definition: pddl_ast.h:171
A PDDL Expression.
Definition: pddl_ast.h:78
expression_t expression
The expression formula.
Definition: pddl_ast.h:82
ExpressionType type
The type of the expression, determined at parsing time.
Definition: pddl_ast.h:80
A structured representation of a PDDL function.
Definition: pddl_ast.h:122
std::string name
The name of the function.
Definition: pddl_ast.h:124
string_pairs_type object_params
A typed list of function parameters.
Definition: pddl_ast.h:126
A PDDL formula (either part of a precondition or an effect(.
Definition: pddl_ast.h:107
std::vector< Expression > arguments
The arguments of the predicate or the subformulae of the compound formula.
Definition: pddl_ast.h:115
Atom function
The name of the predicate for atomic formulae, 'and' for a conjunction, 'or' for a disjunction,...
Definition: pddl_ast.h:111
A structured representation of a PDDL problem.
Definition: pddl_ast.h:180
std::string name
The name of the problem.
Definition: pddl_ast.h:182
pairs_multi_consts objects
A typed list of objects in the domain.
Definition: pddl_ast.h:186
Expression goal
The goal of the problem.
Definition: pddl_ast.h:190
std::vector< Expression > init
A list of facts that are initially true.
Definition: pddl_ast.h:188
std::string domain_name
The name of the domain this problem belongs to.
Definition: pddl_ast.h:184
A PDDL quantified formula.
Definition: pddl_ast.h:89
Expression sub_expr
Sub-expression that is quantified over.
Definition: pddl_ast.h:97
Atom quantifier
The name of the quantifier ('exists' or 'forall')
Definition: pddl_ast.h:91
string_pairs_type args
args that are bound by the quantifier
Definition: pddl_ast.h:94