Started implementing PDDL normalization.
This commit is contained in:
parent
c528626fe9
commit
56ce55677f
@ -30,7 +30,7 @@ class Action
|
|||||||
const Expression *precondition() const;
|
const Expression *precondition() const;
|
||||||
const Expression *effect() const;
|
const Expression *effect() const;
|
||||||
|
|
||||||
void normalizeParameterNames();
|
void normalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Action() = default;
|
Action() = default;
|
||||||
|
@ -58,6 +58,11 @@ class Context
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr static const char *auxiliaryPrefix()
|
||||||
|
{
|
||||||
|
return "__plasp_";
|
||||||
|
}
|
||||||
|
|
||||||
Parser parser;
|
Parser parser;
|
||||||
utils::Logger logger;
|
utils::Logger logger;
|
||||||
};
|
};
|
||||||
|
@ -67,8 +67,6 @@ class Domain
|
|||||||
|
|
||||||
void parseActionSection();
|
void parseActionSection();
|
||||||
|
|
||||||
void normalizeParameterNames();
|
|
||||||
|
|
||||||
Context &m_context;
|
Context &m_context;
|
||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
@ -96,6 +96,13 @@ class Expression
|
|||||||
virtual ~Expression() = default;
|
virtual ~Expression() = default;
|
||||||
|
|
||||||
virtual Type expressionType() const = 0;
|
virtual Type expressionType() const = 0;
|
||||||
|
|
||||||
|
// Normalizes the expression dependent on its type, recursing through all child expressions
|
||||||
|
//
|
||||||
|
// Result:
|
||||||
|
// * a new expression pointer to replace this one if required; this object is then empty
|
||||||
|
// * nullptr otherwise; the object may or may not have changed
|
||||||
|
virtual ExpressionPointer normalize() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -34,12 +34,13 @@ class At: public ExpressionCRTP<At>
|
|||||||
|
|
||||||
size_t timePoint() const;
|
size_t timePoint() const;
|
||||||
|
|
||||||
const Expression *argument() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setArgument(const Expression *argument);
|
void setArgument(const Expression *argument);
|
||||||
void setArgument(ExpressionPointer &&argument);
|
void setArgument(ExpressionPointer &&argument);
|
||||||
|
const Expression *argument() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
size_t m_timePoint;
|
size_t m_timePoint;
|
||||||
|
|
||||||
const Expression *m_argument;
|
const Expression *m_argument;
|
||||||
|
@ -28,14 +28,15 @@ class Binary: public ExpressionCRTP<Derived>
|
|||||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::array<const Expression *, 2> &arguments() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
template<size_t i>
|
template<size_t i>
|
||||||
void setArgument(const Expression *argument);
|
void setArgument(const Expression *argument);
|
||||||
template<size_t i>
|
template<size_t i>
|
||||||
void setArgument(ExpressionPointer &&argument);
|
void setArgument(ExpressionPointer &&argument);
|
||||||
|
const std::array<const Expression *, 2> &arguments() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
std::array<const Expression *, 2> m_arguments;
|
std::array<const Expression *, 2> m_arguments;
|
||||||
std::array<ExpressionPointer, 2> m_argumentStorage;
|
std::array<ExpressionPointer, 2> m_argumentStorage;
|
||||||
};
|
};
|
||||||
@ -104,6 +105,28 @@ const std::array<const Expression *, 2> &Binary<Derived>::arguments() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class Derived>
|
||||||
|
inline ExpressionPointer Binary<Derived>::normalize()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_argumentStorage.size(); i++)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(m_argumentStorage[i]);
|
||||||
|
|
||||||
|
auto normalizedArgument = m_argumentStorage[i]->normalize();
|
||||||
|
|
||||||
|
// Replace argument if changed by normalization
|
||||||
|
if (!normalizedArgument)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
m_argumentStorage[i] = std::move(normalizedArgument);
|
||||||
|
m_arguments[i] = m_argumentStorage[i].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ class Constant: public ExpressionCRTP<Constant>
|
|||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
const PrimitiveType *type() const;
|
const PrimitiveType *type() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ConstantPointer parseDeclaration(Context &context);
|
static ConstantPointer parseDeclaration(Context &context);
|
||||||
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
|
static void parseTypedDeclaration(Context &context, Domain &domain, Constants &constants);
|
||||||
|
@ -22,6 +22,9 @@ class Either: public NAry<Either>
|
|||||||
static const Expression::Type ExpressionType = Expression::Type::Either;
|
static const Expression::Type ExpressionType = Expression::Type::Either;
|
||||||
|
|
||||||
static const std::string Identifier;
|
static const std::string Identifier;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -22,6 +22,9 @@ class Imply: public Binary<Imply>
|
|||||||
static const Expression::Type ExpressionType = Expression::Type::Imply;
|
static const Expression::Type ExpressionType = Expression::Type::Imply;
|
||||||
|
|
||||||
static const std::string Identifier;
|
static const std::string Identifier;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -28,12 +28,13 @@ class NAry: public ExpressionCRTP<Derived>
|
|||||||
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
ExpressionContext &expressionContext, ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::vector<const Expression *> &arguments() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void addArgument(const Expression *argument);
|
void addArgument(const Expression *argument);
|
||||||
void addArgument(ExpressionPointer &&argument);
|
void addArgument(ExpressionPointer &&argument);
|
||||||
|
const std::vector<const Expression *> &arguments() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
std::vector<const Expression *> m_arguments;
|
std::vector<const Expression *> m_arguments;
|
||||||
Expressions m_argumentStorage;
|
Expressions m_argumentStorage;
|
||||||
};
|
};
|
||||||
@ -110,6 +111,28 @@ const std::vector<const Expression *> &NAry<Derived>::arguments() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class Derived>
|
||||||
|
inline ExpressionPointer NAry<Derived>::normalize()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < m_argumentStorage.size(); i++)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(m_argumentStorage[i]);
|
||||||
|
|
||||||
|
auto normalizedArgument = m_argumentStorage[i]->normalize();
|
||||||
|
|
||||||
|
// Replace argument if changed by normalization
|
||||||
|
if (!normalizedArgument)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
m_argumentStorage[i] = std::move(normalizedArgument);
|
||||||
|
m_arguments[i] = m_argumentStorage[i].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,13 @@ class Not: public ExpressionCRTP<Not>
|
|||||||
public:
|
public:
|
||||||
Not();
|
Not();
|
||||||
|
|
||||||
const Expression *argument() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void setArgument(const Expression *argument);
|
void setArgument(const Expression *argument);
|
||||||
void setArgument(ExpressionPointer &&argument);
|
void setArgument(ExpressionPointer &&argument);
|
||||||
|
const Expression *argument() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
const Expression *m_argument;
|
const Expression *m_argument;
|
||||||
ExpressionPointer m_argumentStorage;
|
ExpressionPointer m_argumentStorage;
|
||||||
};
|
};
|
||||||
|
@ -30,6 +30,8 @@ class Predicate: public ExpressionCRTP<Predicate>
|
|||||||
|
|
||||||
bool isDeclared() const;
|
bool isDeclared() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Predicate();
|
Predicate();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class PredicateDeclaration: public ExpressionCRTP<PredicateDeclaration>
|
|||||||
|
|
||||||
bool isDeclared() const;
|
bool isDeclared() const;
|
||||||
|
|
||||||
void normalizeParameterNames();
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PredicateDeclaration();
|
PredicateDeclaration();
|
||||||
|
@ -35,6 +35,8 @@ class PrimitiveType: public ExpressionCRTP<PrimitiveType>
|
|||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
const std::vector<const PrimitiveType *> &parentTypes() const;
|
const std::vector<const PrimitiveType *> &parentTypes() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setDirty(bool isDirty = true);
|
void setDirty(bool isDirty = true);
|
||||||
bool isDirty() const;
|
bool isDirty() const;
|
||||||
|
@ -27,6 +27,8 @@ class Unsupported: public ExpressionCRTP<Unsupported>
|
|||||||
public:
|
public:
|
||||||
const std::string &type() const;
|
const std::string &type() const;
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type;
|
std::string m_type;
|
||||||
};
|
};
|
||||||
|
@ -38,6 +38,8 @@ class Variable: public ExpressionCRTP<Variable>
|
|||||||
|
|
||||||
void setType(const Expression *type);
|
void setType(const Expression *type);
|
||||||
|
|
||||||
|
ExpressionPointer normalize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void parseDeclaration(Context &context, Variables ¶meters);
|
static void parseDeclaration(Context &context, Variables ¶meters);
|
||||||
|
|
||||||
|
@ -87,8 +87,13 @@ const Expression *Action::effect() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Action::normalizeParameterNames()
|
void Action::normalize()
|
||||||
{
|
{
|
||||||
|
// Normalize preconditions and effects
|
||||||
|
m_precondition->normalize();
|
||||||
|
m_effect->normalize();
|
||||||
|
|
||||||
|
// Normalize parameter names
|
||||||
for (size_t i = 0; i < m_parameters.size(); i++)
|
for (size_t i = 0; i < m_parameters.size(); i++)
|
||||||
m_parameters[i]->setName("X" + std::to_string(i));
|
m_parameters[i]->setName("X" + std::to_string(i));
|
||||||
}
|
}
|
||||||
|
@ -416,24 +416,17 @@ void Domain::checkConsistency()
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Domain::normalize()
|
void Domain::normalize()
|
||||||
{
|
|
||||||
normalizeParameterNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void Domain::normalizeParameterNames()
|
|
||||||
{
|
{
|
||||||
std::for_each(m_predicates.begin(), m_predicates.end(),
|
std::for_each(m_predicates.begin(), m_predicates.end(),
|
||||||
[](auto &predicate)
|
[](auto &predicate)
|
||||||
{
|
{
|
||||||
predicate->normalizeParameterNames();
|
predicate->normalize();
|
||||||
});
|
});
|
||||||
|
|
||||||
std::for_each(m_actions.begin(), m_actions.end(),
|
std::for_each(m_actions.begin(), m_actions.end(),
|
||||||
[](auto &action)
|
[](auto &action)
|
||||||
{
|
{
|
||||||
action->normalizeParameterNames();
|
action->normalize();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,21 @@ const Expression *At::argument() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer At::normalize()
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(m_argumentStorage);
|
||||||
|
|
||||||
|
auto normalizedArgument = m_argumentStorage->normalize();
|
||||||
|
|
||||||
|
// Replace argument if changed by normalization
|
||||||
|
if (normalizedArgument)
|
||||||
|
setArgument(std::move(normalizedArgument));
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,6 +239,13 @@ const PrimitiveType *Constant::type() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Constant::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,13 @@ const std::string Either::Identifier = "either";
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Either::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include <plasp/pddl/expressions/Imply.h>
|
#include <plasp/pddl/expressions/Imply.h>
|
||||||
|
|
||||||
|
#include <plasp/pddl/expressions/Not.h>
|
||||||
|
#include <plasp/pddl/expressions/Or.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -18,6 +21,23 @@ const std::string Imply::Identifier = "imply";
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Imply::normalize()
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(m_argumentStorage[0]);
|
||||||
|
BOOST_ASSERT(m_argumentStorage[1]);
|
||||||
|
|
||||||
|
auto notArgument0 = std::make_unique<Not>();
|
||||||
|
notArgument0->setArgument(std::move(m_argumentStorage[0]));
|
||||||
|
|
||||||
|
auto orExpression = std::make_unique<Or>();
|
||||||
|
orExpression->addArgument(std::move(notArgument0));
|
||||||
|
orExpression->addArgument(std::move(m_argumentStorage[1]));
|
||||||
|
|
||||||
|
return std::move(orExpression);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,21 @@ const Expression *Not::argument() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Not::normalize()
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(m_argumentStorage);
|
||||||
|
|
||||||
|
auto normalizedArgument = m_argumentStorage->normalize();
|
||||||
|
|
||||||
|
// Replace argument if changed by normalization
|
||||||
|
if (normalizedArgument)
|
||||||
|
setArgument(std::move(normalizedArgument));
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,13 @@ const std::vector<const Expression *> &Predicate::arguments() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Predicate::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,12 @@ const Variables &PredicateDeclaration::arguments() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void PredicateDeclaration::normalizeParameterNames()
|
ExpressionPointer PredicateDeclaration::normalize()
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_parameters.size(); i++)
|
for (size_t i = 0; i < m_parameters.size(); i++)
|
||||||
m_parameters[i]->setName("X" + std::to_string(i));
|
m_parameters[i]->setName("X" + std::to_string(i));
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -169,6 +169,13 @@ const std::vector<const PrimitiveType *> &PrimitiveType::parentTypes() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer PrimitiveType::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,13 @@ const std::string &Unsupported::type() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Unsupported::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,13 @@ void Variable::setType(const Expression *type)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ExpressionPointer Variable::normalize()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user