Refactored normalization because of recent changes to the pointer usage.
This commit is contained in:
@@ -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++)
|
||||
|
@@ -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(),
|
||||
|
@@ -24,6 +24,30 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Expression::normalized()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Expression::negated()
|
||||
{
|
||||
if (expressionType() == Type::Not)
|
||||
{
|
||||
auto ¬Expression = 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);
|
||||
|
||||
|
@@ -401,7 +401,7 @@ void Problem::normalize()
|
||||
|
||||
// TODO: normalize objects and initial state
|
||||
|
||||
m_goal->normalize();
|
||||
m_goal = m_goal->normalized();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -239,13 +239,6 @@ PrimitiveTypePointer Constant::type() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Constant::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,11 +22,11 @@ bool Dummy::isNormalized() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Dummy::normalize()
|
||||
ExpressionPointer Dummy::normalized()
|
||||
{
|
||||
m_isNormalized = true;
|
||||
|
||||
return nullptr;
|
||||
return this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -17,13 +17,6 @@ const std::string Either::Identifier = "either";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Either::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -170,13 +170,6 @@ const Expressions &Predicate::arguments() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Predicate::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@@ -169,13 +169,6 @@ const PrimitiveTypes &PrimitiveType::parentTypes() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer PrimitiveType::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,13 +41,6 @@ const std::string &Unsupported::type() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Unsupported::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -203,13 +203,6 @@ bool Variable::isDirty() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ExpressionPointer Variable::normalize()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user