Implemented prenex normalization.

This commit is contained in:
2016-09-07 00:34:26 +02:00
parent 2e52357dd2
commit e0ed145716
10 changed files with 203 additions and 9 deletions

View File

@@ -28,7 +28,7 @@ namespace pddl
ExpressionPointer Expression::normalized()
{
return reduced()->negationNormalized()->simplified();
return reduced()->negationNormalized()->prenex()->simplified();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -47,6 +47,57 @@ ExpressionPointer Expression::negationNormalized()
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Expression::prenex()
{
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Expression::prenex(ExpressionPointer parent, ExpressionPointer &child)
{
BOOST_ASSERT(child);
child = child->prenex();
if (child->expressionType() == Expression::Type::Exists)
{
auto quantifiedExpression = expressions::ExistsPointer(dynamic_cast<expressions::Exists *>(child.get()));
// Move argument up
child = quantifiedExpression->argument();
// Recursively build prenex form on new child
parent = Expression::prenex(parent, child);
// Move quantifier up
quantifiedExpression->setArgument(parent);
// Make parent point to the quantifier that has been moved up
return quantifiedExpression;
}
else if (child->expressionType() == Expression::Type::ForAll)
{
auto quantifiedExpression = expressions::ForAllPointer(dynamic_cast<expressions::ForAll *>(child.get()));
// Move argument up
child = quantifiedExpression->argument();
// Recursively build prenex form on new child
parent = Expression::prenex(parent, child);
// Move quantifier up
quantifiedExpression->setArgument(parent);
// Make parent point to the quantifier that has been moved up
return quantifiedExpression;
}
return parent;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Expression::simplified()
{
return this;

View File

@@ -54,6 +54,26 @@ ExpressionPointer At::negationNormalized()
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer At::prenex()
{
BOOST_ASSERT(m_argument);
return Expression::prenex(this, m_argument);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer At::simplified()
{
BOOST_ASSERT(m_argument);
m_argument = m_argument->simplified();
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void At::print(std::ostream &ostream) const
{
ostream << "(at " << m_timePoint << " ";

View File

@@ -128,6 +128,26 @@ ExpressionPointer Not::negationNormalized()
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Not::prenex()
{
BOOST_ASSERT(m_argument);
return Expression::prenex(this, m_argument);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ExpressionPointer Not::simplified()
{
BOOST_ASSERT(m_argument);
m_argument = m_argument->simplified();
return this;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Not::print(std::ostream &ostream) const
{
ostream << "(not ";