Refactored normalization because of recent changes to the pointer usage.

This commit is contained in:
2016-09-04 19:29:05 +02:00
parent 7aa20a5820
commit 6aaf7c039d
30 changed files with 75 additions and 124 deletions

View File

@@ -90,8 +90,8 @@ const Expression *Action::effect() const
void Action::normalize()
{
// Normalize preconditions and effects
m_precondition->normalize();
m_effect->normalize();
m_precondition = m_precondition->normalized();
m_effect = m_effect->normalized();
// Normalize parameter names
for (size_t i = 0; i < m_parameters.size(); i++)

View File

@@ -420,7 +420,7 @@ void Domain::normalize()
std::for_each(m_predicates.begin(), m_predicates.end(),
[](auto &predicate)
{
predicate->normalize();
predicate->normalizeParameterNames();
});
std::for_each(m_actions.begin(), m_actions.end(),

View File

@@ -24,6 +24,30 @@ namespace pddl
//
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Expression::normalized()
{
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Expression::negated()
{
if (expressionType() == Type::Not)
{
auto &notExpression = dynamic_cast<expressions::Not &>(*this);
return notExpression.argument();
}
auto notExpression = expressions::NotPointer(new expressions::Not);
notExpression->setArgument(this);
return notExpression;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext &expressionContext);
ExpressionPointer parsePredicate(Context &context, ExpressionContext &expressionContext);

View File

@@ -401,7 +401,7 @@ void Problem::normalize()
// TODO: normalize objects and initial state
m_goal->normalize();
m_goal = m_goal->normalized();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -34,17 +34,13 @@ ExpressionPointer At::argument() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer At::normalize()
ExpressionPointer At::normalized()
{
BOOST_ASSERT(m_argument);
auto normalizedArgument = m_argument->normalize();
m_argument = m_argument->normalized();
// Replace argument if changed by normalization
if (normalizedArgument)
setArgument(std::move(normalizedArgument));
return nullptr;
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

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

View File

@@ -22,11 +22,11 @@ bool Dummy::isNormalized() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Dummy::normalize()
ExpressionPointer Dummy::normalized()
{
m_isNormalized = true;
return nullptr;
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

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

View File

@@ -21,19 +21,22 @@ const std::string Imply::Identifier = "imply";
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Imply::normalize()
ExpressionPointer Imply::normalized()
{
BOOST_ASSERT(m_arguments[0]);
BOOST_ASSERT(m_arguments[1]);
m_arguments[0] = m_arguments[0]->normalized();
m_arguments[1] = m_arguments[1]->normalized();
auto notArgument0 = NotPointer(new Not);
notArgument0->setArgument(std::move(m_arguments[0]));
notArgument0->setArgument(m_arguments[0]);
auto orExpression = OrPointer(new Or);
orExpression->addArgument(std::move(notArgument0));
orExpression->addArgument(std::move(m_arguments[1]));
orExpression->addArgument(notArgument0);
orExpression->addArgument(m_arguments[1]);
auto normalizedOrExpression = orExpression->normalize();
auto normalizedOrExpression = orExpression->normalized();
if (normalizedOrExpression)
return normalizedOrExpression;

View File

@@ -34,7 +34,7 @@ ExpressionPointer Not::argument() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Not::normalize()
ExpressionPointer Not::normalized()
{
BOOST_ASSERT(m_argument);
@@ -43,22 +43,12 @@ ExpressionPointer Not::normalize()
{
auto &argument = dynamic_cast<Not &>(*m_argument);
auto normalized = std::move(argument.m_argument);
auto normalizedInner = normalized->normalize();
if (normalizedInner)
return normalizedInner;
return normalized;
return argument.m_argument->normalized();
}
auto normalizedArgument = m_argument->normalize();
m_argument = m_argument->normalized();
// Replace argument if changed by normalization
if (normalizedArgument)
setArgument(std::move(normalizedArgument));
return nullptr;
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -170,13 +170,6 @@ const Expressions &Predicate::arguments() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Predicate::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

@@ -79,12 +79,10 @@ const Variables &PredicateDeclaration::arguments() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer PredicateDeclaration::normalize()
void PredicateDeclaration::normalizeParameterNames()
{
for (size_t i = 0; i < m_parameters.size(); i++)
m_parameters[i]->setName("X" + std::to_string(i));
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -169,13 +169,6 @@ const PrimitiveTypes &PrimitiveType::parentTypes() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer PrimitiveType::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}

View File

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

View File

@@ -203,13 +203,6 @@ bool Variable::isDirty() const
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Variable::normalize()
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}