From 82516524458d20a5ca5400b4177f1f68055f74bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Thu, 18 Aug 2016 00:24:10 +0200 Subject: [PATCH] Implemented parameter name normalization for PDDL to avoid escaping the names. --- include/plasp/pddl/Action.h | 2 ++ include/plasp/pddl/Description.h | 2 ++ include/plasp/pddl/Domain.h | 2 ++ include/plasp/pddl/TranslatorASP.h | 4 ++-- .../pddl/expressions/PredicateDeclaration.h | 2 ++ include/plasp/pddl/expressions/Variable.h | 2 ++ src/plasp/pddl/Action.cpp | 8 ++++++++ src/plasp/pddl/Description.cpp | 7 +++++++ src/plasp/pddl/Domain.cpp | 17 +++++++++++++++++ src/plasp/pddl/TranslatorASP.cpp | 3 ++- .../pddl/expressions/PredicateDeclaration.cpp | 8 ++++++++ src/plasp/pddl/expressions/Variable.cpp | 7 +++++++ 12 files changed, 61 insertions(+), 3 deletions(-) diff --git a/include/plasp/pddl/Action.h b/include/plasp/pddl/Action.h index d582074..ff96c56 100644 --- a/include/plasp/pddl/Action.h +++ b/include/plasp/pddl/Action.h @@ -30,6 +30,8 @@ class Action const Expression *precondition() const; const Expression *effect() const; + void normalizeParameterNames(); + private: Action() = default; diff --git a/include/plasp/pddl/Description.h b/include/plasp/pddl/Description.h index fb22c5d..db03e69 100644 --- a/include/plasp/pddl/Description.h +++ b/include/plasp/pddl/Description.h @@ -35,6 +35,8 @@ class Description bool containsProblem() const; const Problem &problem() const; + void normalizeParameterNames(); + private: Description(); diff --git a/include/plasp/pddl/Domain.h b/include/plasp/pddl/Domain.h index 7d8b75b..c68a0ae 100644 --- a/include/plasp/pddl/Domain.h +++ b/include/plasp/pddl/Domain.h @@ -51,6 +51,8 @@ class Domain void checkConsistency(); + void normalizeParameterNames(); + private: void parseSection(); diff --git a/include/plasp/pddl/TranslatorASP.h b/include/plasp/pddl/TranslatorASP.h index d572feb..da33689 100644 --- a/include/plasp/pddl/TranslatorASP.h +++ b/include/plasp/pddl/TranslatorASP.h @@ -19,7 +19,7 @@ namespace pddl class TranslatorASP { public: - explicit TranslatorASP(const Description &description, utils::LogStream &outputStream); + explicit TranslatorASP(Description &description, utils::LogStream &outputStream); void translate() const; @@ -39,7 +39,7 @@ class TranslatorASP void translateLiteral(const Expression &literal) const; void translatePredicate(const expressions::Predicate &predicate) const; - const Description &m_description; + Description &m_description; utils::LogStream &m_outputStream; }; diff --git a/include/plasp/pddl/expressions/PredicateDeclaration.h b/include/plasp/pddl/expressions/PredicateDeclaration.h index 210f2da..b14622a 100644 --- a/include/plasp/pddl/expressions/PredicateDeclaration.h +++ b/include/plasp/pddl/expressions/PredicateDeclaration.h @@ -29,6 +29,8 @@ class PredicateDeclaration: public ExpressionCRTP bool isDeclared() const; + void normalizeParameterNames(); + private: PredicateDeclaration(); diff --git a/include/plasp/pddl/expressions/Variable.h b/include/plasp/pddl/expressions/Variable.h index 16c10e4..a5869d2 100644 --- a/include/plasp/pddl/expressions/Variable.h +++ b/include/plasp/pddl/expressions/Variable.h @@ -28,7 +28,9 @@ class Variable: public ExpressionCRTP const ExpressionContext &expressionContext); public: + void setName(std::string name); const std::string &name() const; + const Expression *type() const; void setDirty(bool isDirty = true); diff --git a/src/plasp/pddl/Action.cpp b/src/plasp/pddl/Action.cpp index 5e46380..506745d 100644 --- a/src/plasp/pddl/Action.cpp +++ b/src/plasp/pddl/Action.cpp @@ -87,5 +87,13 @@ const Expression *Action::effect() const //////////////////////////////////////////////////////////////////////////////////////////////////// +void Action::normalizeParameterNames() +{ + for (size_t i = 0; i < m_parameters.size(); i++) + m_parameters[i]->setName("X" + std::to_string(i)); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } } diff --git a/src/plasp/pddl/Description.cpp b/src/plasp/pddl/Description.cpp index 8d2cd1e..b7b3b16 100644 --- a/src/plasp/pddl/Description.cpp +++ b/src/plasp/pddl/Description.cpp @@ -204,5 +204,12 @@ void Description::checkConsistency() //////////////////////////////////////////////////////////////////////////////////////////////////// +void Description::normalizeParameterNames() +{ + m_domain->normalizeParameterNames(); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } } diff --git a/src/plasp/pddl/Domain.cpp b/src/plasp/pddl/Domain.cpp index 98427af..a4e93c7 100644 --- a/src/plasp/pddl/Domain.cpp +++ b/src/plasp/pddl/Domain.cpp @@ -413,5 +413,22 @@ void Domain::checkConsistency() //////////////////////////////////////////////////////////////////////////////////////////////////// +void Domain::normalizeParameterNames() +{ + std::for_each(m_predicates.begin(), m_predicates.end(), + [](auto &predicate) + { + predicate->normalizeParameterNames(); + }); + + std::for_each(m_actions.begin(), m_actions.end(), + [](auto &action) + { + action->normalizeParameterNames(); + }); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } } diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index a159dca..85ef17c 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -19,10 +19,11 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -TranslatorASP::TranslatorASP(const Description &description, utils::LogStream &outputStream) +TranslatorASP::TranslatorASP(Description &description, utils::LogStream &outputStream) : m_description(description), m_outputStream(outputStream) { + m_description.normalizeParameterNames(); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/expressions/PredicateDeclaration.cpp b/src/plasp/pddl/expressions/PredicateDeclaration.cpp index f87873c..5e15449 100644 --- a/src/plasp/pddl/expressions/PredicateDeclaration.cpp +++ b/src/plasp/pddl/expressions/PredicateDeclaration.cpp @@ -79,6 +79,14 @@ const Variables &PredicateDeclaration::arguments() const //////////////////////////////////////////////////////////////////////////////////////////////////// +void PredicateDeclaration::normalizeParameterNames() +{ + for (size_t i = 0; i < m_parameters.size(); i++) + m_parameters[i]->setName("X" + std::to_string(i)); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } } } diff --git a/src/plasp/pddl/expressions/Variable.cpp b/src/plasp/pddl/expressions/Variable.cpp index 115e08d..783eb6e 100644 --- a/src/plasp/pddl/expressions/Variable.cpp +++ b/src/plasp/pddl/expressions/Variable.cpp @@ -164,6 +164,13 @@ const Variable *Variable::parseAndFind(Context &context, const ExpressionContext //////////////////////////////////////////////////////////////////////////////////////////////////// +void Variable::setName(std::string name) +{ + m_name = name; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + const std::string &Variable::name() const { return m_name;