Fixed bugs related in decomposition of expressions.
This commit is contained in:
parent
cb2db2cadf
commit
0b31d8d56c
@ -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);
|
||||
|
@ -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 expression’s arguments to the derived predicate
|
||||
derivedPredicate->setPreconditions({m_arguments});
|
||||
derivedPredicate->setPreconditions(std::move(preconditions));
|
||||
|
||||
return derivedPredicate;
|
||||
}
|
||||
|
@ -64,7 +64,10 @@ void DerivedPredicate::collectParameters(std::set<VariablePointer> ¶meters)
|
||||
{
|
||||
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> ¶meters)
|
||||
|
||||
void DerivedPredicate::print(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "(:derived <no name>";
|
||||
ostream << "(:derived " << m_id << " ";
|
||||
|
||||
BOOST_ASSERT(m_preconditions.size() > 0);
|
||||
|
||||
|
@ -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 expression’s arguments to the derived predicate
|
||||
derivedPredicate->setPreconditions({{this}});
|
||||
|
@ -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 expression’s arguments to the derived predicate
|
||||
preconditions.emplace_back(std::move(conjunction));
|
||||
|
@ -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)
|
||||
for (auto &variable : variables)
|
||||
{
|
||||
if (!variable->isDirty())
|
||||
return;
|
||||
|
||||
variable->setType(type);
|
||||
variable->setDirty(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
Reference in New Issue
Block a user