Started implementing PDDL normalization.
This commit is contained in:
@@ -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++)
|
||||
m_parameters[i]->setName("X" + std::to_string(i));
|
||||
}
|
||||
|
@@ -416,24 +416,17 @@ void Domain::checkConsistency()
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Domain::normalize()
|
||||
{
|
||||
normalizeParameterNames();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Domain::normalizeParameterNames()
|
||||
{
|
||||
std::for_each(m_predicates.begin(), m_predicates.end(),
|
||||
[](auto &predicate)
|
||||
{
|
||||
predicate->normalizeParameterNames();
|
||||
predicate->normalize();
|
||||
});
|
||||
|
||||
std::for_each(m_actions.begin(), m_actions.end(),
|
||||
[](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/Not.h>
|
||||
#include <plasp/pddl/expressions/Or.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
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++)
|
||||
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