Implemented parameter name normalization for PDDL to avoid escaping the names.

This commit is contained in:
Patrick Lühne 2016-08-18 00:24:10 +02:00
parent 5e28dd046b
commit 8251652445
12 changed files with 61 additions and 3 deletions

View File

@ -30,6 +30,8 @@ class Action
const Expression *precondition() const;
const Expression *effect() const;
void normalizeParameterNames();
private:
Action() = default;

View File

@ -35,6 +35,8 @@ class Description
bool containsProblem() const;
const Problem &problem() const;
void normalizeParameterNames();
private:
Description();

View File

@ -51,6 +51,8 @@ class Domain
void checkConsistency();
void normalizeParameterNames();
private:
void parseSection();

View File

@ -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;
};

View File

@ -29,6 +29,8 @@ class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
bool isDeclared() const;
void normalizeParameterNames();
private:
PredicateDeclaration();

View File

@ -28,7 +28,9 @@ class Variable: public ExpressionCRTP<Variable>
const ExpressionContext &expressionContext);
public:
void setName(std::string name);
const std::string &name() const;
const Expression *type() const;
void setDirty(bool isDirty = true);

View File

@ -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));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -204,5 +204,12 @@ void Description::checkConsistency()
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::normalizeParameterNames()
{
m_domain->normalizeParameterNames();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -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();
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -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();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@ -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;