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 <string>
30 #include <vector>
31 
32 namespace pddl_parser {
33 namespace qi = boost::spirit::qi;
34 namespace ascii = boost::spirit::ascii;
35 
36 typedef std::pair<std::string, std::string> pair_type;
37 typedef std::vector<pair_type> pairs_type;
38 
39 typedef std::vector<std::string> type_list;
40 typedef std::pair<type_list, std::string> pair_multi_const;
41 typedef std::vector<pair_multi_const> pairs_multi_consts;
42 
43 typedef std::pair<std::string, std::string> string_pair_type;
44 typedef std::vector<string_pair_type> string_pairs_type;
45 typedef std::pair<std::string, string_pairs_type> predicate_type;
46 
47 using Atom = std::string;
48 
49 struct Predicate;
50 
51 using Expression = boost::variant<Atom, Predicate>;
52 
53 /** @class Predicate
54  * A PDDL formula (either part of a precondition or an effect(.
55  * Note that this is NOT necesarily a PDDL predicate, but may also be a
56  * compound formula. For a conjunction, the function would be 'and', and the
57  * arguments would be the subformulae.
58  */
59 struct Predicate
60 {
61  /** The name of the predicate for atomic formulae, 'and' for a conjunction,
62  * 'or' for a disjunction, 'not' for a negation.
63  */
64  Atom function;
65  /** The arguments of the predicate or the subformulae of the compound
66  * formula.
67  */
68  std::vector<Expression> arguments;
69 };
70 
71 /** @class Action
72  * A structured representation of a PDDL action.
73  */
74 struct Action
75 {
76  /** The name of the action. */
77  std::string name;
78  /** A typed list of action parameters. */
79  string_pairs_type action_params;
80  /** The action duration in temporal domains. */
81  int duration;
82  /** The precondition of an action. May be a compound. */
83  Expression precondition;
84  /** The effect of an action. May be a compound. */
85  Expression effect;
86  /** Used by the STN generator to determine conditional break points in the
87  * STN.
88  */
89  Expression cond_breakup;
90  /** Used by the STN generator to determine temporal break points in the STN.
91  */
92  Expression temp_breakup;
93 };
94 
95 /** @class Domain
96  * A structured representation of a PDDL domain.
97  */
98 struct Domain
99 {
100  /** The name of the domain. */
101  std::string name;
102  /** A list of PDDL features required by the domain. */
103  std::vector<std::string> requirements;
104  /** A list of types with their super types. */
105  pairs_type types;
106  /** A typed list of constants defined in the domain. */
107  pairs_multi_consts constants;
108  /** A list of predicate names in the domain, including the types of their
109  * arguments.
110  */
111  std::vector<predicate_type> predicates;
112  /** A list of actions defined in the domain. */
113  std::vector<Action> actions;
114 };
115 
116 /** @class Problem
117  * A structured representation of a PDDL problem.
118  */
119 struct Problem
120 {
121  /** The name of the problem. */
122  std::string name;
123  /** The name of the domain this problem belongs to. */
124  std::string domain_name;
125  /** A typed list of objects in the domain. */
126  pairs_multi_consts objects;
127  /** A list of facts that are initially true. */
128  std::vector<Expression> init;
129  /** The goal of the problem. */
130  Expression goal;
131 };
132 
133 } // namespace pddl_parser
134 
135 BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Domain,
136  name,
137  requirements,
138  types,
139  constants,
140  predicates,
141  actions)
142 
143 BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Problem, name, domain_name, objects, init, goal)
144 
145 BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Action,
146  name,
147  action_params,
148  duration,
149  precondition,
150  effect,
151  cond_breakup,
152  temp_breakup)
153 
154 BOOST_FUSION_ADAPT_STRUCT(pddl_parser::Predicate, function, arguments)
155 
156 #endif
pddl_parser::Domain
A structured representation of a PDDL domain.
Definition: pddl_ast.h:99
pddl_parser::Action::temp_breakup
Expression temp_breakup
Used by the STN generator to determine temporal break points in the STN.
Definition: pddl_ast.h:92
pddl_parser::Predicate::arguments
std::vector< Expression > arguments
The arguments of the predicate or the subformulae of the compound formula.
Definition: pddl_ast.h:68
pddl_parser::Problem
A structured representation of a PDDL problem.
Definition: pddl_ast.h:120
pddl_parser::Domain::name
std::string name
The name of the domain.
Definition: pddl_ast.h:101
pddl_parser::Problem::domain_name
std::string domain_name
The name of the domain this problem belongs to.
Definition: pddl_ast.h:124
pddl_parser::Problem::objects
pairs_multi_consts objects
A typed list of objects in the domain.
Definition: pddl_ast.h:126
pddl_parser::Predicate
A PDDL formula (either part of a precondition or an effect(.
Definition: pddl_ast.h:60
pddl_parser::Action::precondition
Expression precondition
The precondition of an action.
Definition: pddl_ast.h:83
pddl_parser::Domain::types
pairs_type types
A list of types with their super types.
Definition: pddl_ast.h:105
pddl_parser::Problem::name
std::string name
The name of the problem.
Definition: pddl_ast.h:122
pddl_parser::Domain::constants
pairs_multi_consts constants
A typed list of constants defined in the domain.
Definition: pddl_ast.h:107
pddl_parser::Domain::predicates
std::vector< predicate_type > predicates
A list of predicate names in the domain, including the types of their arguments.
Definition: pddl_ast.h:111
pddl_parser::Action::effect
Expression effect
The effect of an action.
Definition: pddl_ast.h:85
pddl_parser::Action::duration
int duration
The action duration in temporal domains.
Definition: pddl_ast.h:81
pddl_parser::Action::name
std::string name
The name of the action.
Definition: pddl_ast.h:77
pddl_parser::Domain::actions
std::vector< Action > actions
A list of actions defined in the domain.
Definition: pddl_ast.h:113
pddl_parser::Action
A structured representation of a PDDL action.
Definition: pddl_ast.h:75
pddl_parser::Domain::requirements
std::vector< std::string > requirements
A list of PDDL features required by the domain.
Definition: pddl_ast.h:103
pddl_parser::Action::action_params
string_pairs_type action_params
A typed list of action parameters.
Definition: pddl_ast.h:79
pddl_parser::Problem::init
std::vector< Expression > init
A list of facts that are initially true.
Definition: pddl_ast.h:128
pddl_parser::Action::cond_breakup
Expression cond_breakup
Used by the STN generator to determine conditional break points in the STN.
Definition: pddl_ast.h:89
pddl_parser::Problem::goal
Expression goal
The goal of the problem.
Definition: pddl_ast.h:130