Fixed bugs related in decomposition of expressions.

This commit is contained in:
Patrick Lühne 2016-12-08 02:54:28 +01:00
parent cb2db2cadf
commit 0b31d8d56c
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
6 changed files with 25 additions and 19 deletions

View File

@ -93,6 +93,8 @@ void Action::normalize(expressions::DerivedPredicates &derivedPredicates)
// Normalize preconditions and effects
m_precondition = m_precondition->normalized()->decomposed(derivedPredicates);
{
m_precondition->print(std::cout);
// TODO: refactor
std::set<expressions::VariablePointer> parameters;
m_precondition->collectParameters(parameters);

View File

@ -25,14 +25,19 @@ const std::string And::Identifier = "and";
ExpressionPointer And::decomposed(DerivedPredicates &derivedPredicates)
{
BOOST_ASSERT(!m_arguments.empty());
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
auto &derivedPredicate = derivedPredicates.back();
auto derivedPredicate = derivedPredicates.back();
for (auto &argument : m_arguments)
argument = argument->decomposed(derivedPredicates);
std::vector<Expressions> preconditions;
preconditions.emplace_back(std::move(m_arguments));
// Move this expressions arguments to the derived predicate
derivedPredicate->setPreconditions({m_arguments});
derivedPredicate->setPreconditions(std::move(preconditions));
return derivedPredicate;
}

View File

@ -64,7 +64,10 @@ void DerivedPredicate::collectParameters(std::set<VariablePointer> &parameters)
{
for (auto &conjunction : m_preconditions)
for (auto &precondition : conjunction)
{
BOOST_ASSERT(precondition.get() != this);
precondition->collectParameters(m_parameters);
}
// Copy in order not to interfere with potentially bound variables in parent expressions
parameters = m_parameters;
@ -74,7 +77,7 @@ void DerivedPredicate::collectParameters(std::set<VariablePointer> &parameters)
void DerivedPredicate::print(std::ostream &ostream) const
{
ostream << "(:derived <no name>";
ostream << "(:derived " << m_id << " ";
BOOST_ASSERT(m_preconditions.size() > 0);

View File

@ -108,7 +108,7 @@ ExpressionPointer Not::decomposed(DerivedPredicates &derivedPredicates)
return this;
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
auto &derivedPredicate = derivedPredicates.back();
auto derivedPredicate = derivedPredicates.back();
// Move this expressions arguments to the derived predicate
derivedPredicate->setPreconditions({{this}});

View File

@ -23,8 +23,10 @@ const std::string Or::Identifier = "or";
ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
{
BOOST_ASSERT(!m_arguments.empty());
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
auto &derivedPredicate = derivedPredicates.back();
auto derivedPredicate = derivedPredicates.back();
std::vector<Expressions> preconditions;
@ -39,14 +41,9 @@ ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
for (auto &argument : conjunction)
argument = argument->decomposed(derivedPredicates);
break;
}
else
{
conjunction.emplace_back(argument->decomposed(derivedPredicates));
break;
}
// Move this expressions arguments to the derived predicate
preconditions.emplace_back(std::move(conjunction));

View File

@ -78,7 +78,7 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
// Parse and store variable itself
parseDeclaration(context, variables);
auto &variable = variables.back();
auto variable = variables.back();
parser.skipWhiteSpace();
@ -90,15 +90,14 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
[&](ExpressionPointer type)
{
// Set the argument type for all previously flagged arguments
std::for_each(variables.begin(), variables.end(),
[&](auto &variable)
{
if (!variable->isDirty())
return;
for (auto &variable : variables)
{
if (!variable->isDirty())
return;
variable->setType(type);
variable->setDirty(false);
});
variable->setType(type);
variable->setDirty(false);
}
};
parser.skipWhiteSpace();