21 #include "clips_pddl_parser_feature.h"
23 #include "effect_visitor.h"
24 #include "precondition_visitor.h"
26 #include <core/threading/mutex_locker.h>
27 #include <logging/logger.h>
28 #include <pddl_parser/pddl_parser.h>
34 using namespace pddl_parser;
64 envs_[env_name] = clips;
66 clips->add_function(
"parse-pddl-domain",
67 sigc::slot<void, string>(
68 sigc::bind<0>(sigc::mem_fun(*
this, &PDDLCLIPSFeature::parse_domain),
78 envs_.erase(env_name);
88 PDDLCLIPSFeature::parse_domain(std::string env_name, std::string domain_file)
91 CLIPS::Environment &env = **(envs_[env_name]);
94 ifstream df(domain_file);
97 domain = PddlParser::parseDomain(buffer.str());
99 logger_->
log_error((
"PDDLCLIPS|" + env_name).c_str(),
100 "Failed to parse domain: %s",
104 for (
auto &type : domain.
types) {
105 string super_type =
"";
106 if (!type.second.empty()) {
107 super_type =
"(super-type " + type.second +
")";
109 env.assert_fact(
"(domain-object-type "
111 + type.first +
")" + super_type +
")");
114 string param_string =
"";
115 string type_string =
"";
116 for (
auto ¶m : predicate.second) {
117 param_string +=
" " + param.first;
118 type_string +=
" " + param.second;
120 env.assert_fact(
"(domain-predicate"
133 for (
auto &action : domain.
actions) {
134 string params_string =
"(param-names";
135 for (
auto ¶m_pair : action.action_params) {
136 string param_name = param_pair.first;
137 string param_type = param_pair.second;
138 params_string +=
" " + param_name;
139 env.assert_fact(
"(domain-operator-parameter"
151 params_string +=
")";
152 env.assert_fact(
"(domain-operator (name " + action.name +
")" + params_string +
")");
153 vector<string> precondition_facts =
155 action.precondition.expression);
156 for (
auto &fact : precondition_facts) {
157 env.assert_fact(fact);
159 vector<string> effect_facts =
161 for (
auto &fact : effect_facts) {
162 env.assert_fact(fact);
Translate a PDDL effect into CLIPS facts.
PDDLCLIPSFeature()
Initialize the CLIPS feature.
virtual void clips_context_destroyed(const std::string &env_name)
Clean up a context.
void init_logger(fawkes::Logger *logger)
Initialize the looger to use.
virtual void clips_context_init(const std::string &env_name, fawkes::LockPtr< CLIPS::Environment > &clips)
Initialize the context and add a parse-pddl-domain CLIPS function.
Translate a PDDL precondition into CLIPS facts.
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
Exception thrown by the parser if an error occurs during parsing.
A structured representation of a PDDL domain.
std::vector< Action > actions
A list of actions defined in the domain.
pairs_type types
A list of types with their super types.
std::vector< predicate_type > predicates
A list of predicate names in the domain, including the types of their arguments.