Started implementing PDDL normalization.

This commit is contained in:
2016-09-02 17:58:00 +02:00
parent c528626fe9
commit 56ce55677f
28 changed files with 193 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@@ -239,6 +239,13 @@ const PrimitiveType *Constant::type() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Constant::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -17,6 +17,13 @@ const std::string Either::Identifier = "either";
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Either::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

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

View File

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

View File

@@ -170,6 +170,13 @@ const std::vector<const Expression *> &Predicate::arguments() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Predicate::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

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

View File

@@ -169,6 +169,13 @@ const std::vector<const PrimitiveType *> &PrimitiveType::parentTypes() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer PrimitiveType::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -41,6 +41,13 @@ const std::string &Unsupported::type() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Unsupported::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -206,6 +206,13 @@ void Variable::setType(const Expression *type)
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Variable::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}