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
|
// Normalize preconditions and effects
|
||||||
m_precondition = m_precondition->normalized()->decomposed(derivedPredicates);
|
m_precondition = m_precondition->normalized()->decomposed(derivedPredicates);
|
||||||
{
|
{
|
||||||
|
m_precondition->print(std::cout);
|
||||||
|
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
std::set<expressions::VariablePointer> parameters;
|
std::set<expressions::VariablePointer> parameters;
|
||||||
m_precondition->collectParameters(parameters);
|
m_precondition->collectParameters(parameters);
|
||||||
|
@ -25,14 +25,19 @@ const std::string And::Identifier = "and";
|
|||||||
|
|
||||||
ExpressionPointer And::decomposed(DerivedPredicates &derivedPredicates)
|
ExpressionPointer And::decomposed(DerivedPredicates &derivedPredicates)
|
||||||
{
|
{
|
||||||
|
BOOST_ASSERT(!m_arguments.empty());
|
||||||
|
|
||||||
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
||||||
auto &derivedPredicate = derivedPredicates.back();
|
auto derivedPredicate = derivedPredicates.back();
|
||||||
|
|
||||||
for (auto &argument : m_arguments)
|
for (auto &argument : m_arguments)
|
||||||
argument = argument->decomposed(derivedPredicates);
|
argument = argument->decomposed(derivedPredicates);
|
||||||
|
|
||||||
|
std::vector<Expressions> preconditions;
|
||||||
|
preconditions.emplace_back(std::move(m_arguments));
|
||||||
|
|
||||||
// Move this expression’s arguments to the derived predicate
|
// Move this expression’s arguments to the derived predicate
|
||||||
derivedPredicate->setPreconditions({m_arguments});
|
derivedPredicate->setPreconditions(std::move(preconditions));
|
||||||
|
|
||||||
return derivedPredicate;
|
return derivedPredicate;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,10 @@ void DerivedPredicate::collectParameters(std::set<VariablePointer> ¶meters)
|
|||||||
{
|
{
|
||||||
for (auto &conjunction : m_preconditions)
|
for (auto &conjunction : m_preconditions)
|
||||||
for (auto &precondition : conjunction)
|
for (auto &precondition : conjunction)
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(precondition.get() != this);
|
||||||
precondition->collectParameters(m_parameters);
|
precondition->collectParameters(m_parameters);
|
||||||
|
}
|
||||||
|
|
||||||
// Copy in order not to interfere with potentially bound variables in parent expressions
|
// Copy in order not to interfere with potentially bound variables in parent expressions
|
||||||
parameters = m_parameters;
|
parameters = m_parameters;
|
||||||
@ -74,7 +77,7 @@ void DerivedPredicate::collectParameters(std::set<VariablePointer> ¶meters)
|
|||||||
|
|
||||||
void DerivedPredicate::print(std::ostream &ostream) const
|
void DerivedPredicate::print(std::ostream &ostream) const
|
||||||
{
|
{
|
||||||
ostream << "(:derived <no name>";
|
ostream << "(:derived " << m_id << " ";
|
||||||
|
|
||||||
BOOST_ASSERT(m_preconditions.size() > 0);
|
BOOST_ASSERT(m_preconditions.size() > 0);
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ ExpressionPointer Not::decomposed(DerivedPredicates &derivedPredicates)
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
||||||
auto &derivedPredicate = derivedPredicates.back();
|
auto derivedPredicate = derivedPredicates.back();
|
||||||
|
|
||||||
// Move this expression’s arguments to the derived predicate
|
// Move this expression’s arguments to the derived predicate
|
||||||
derivedPredicate->setPreconditions({{this}});
|
derivedPredicate->setPreconditions({{this}});
|
||||||
|
@ -23,8 +23,10 @@ const std::string Or::Identifier = "or";
|
|||||||
|
|
||||||
ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
|
ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
|
||||||
{
|
{
|
||||||
|
BOOST_ASSERT(!m_arguments.empty());
|
||||||
|
|
||||||
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
derivedPredicates.emplace_back(new DerivedPredicate(derivedPredicates.size()));
|
||||||
auto &derivedPredicate = derivedPredicates.back();
|
auto derivedPredicate = derivedPredicates.back();
|
||||||
|
|
||||||
std::vector<Expressions> preconditions;
|
std::vector<Expressions> preconditions;
|
||||||
|
|
||||||
@ -39,14 +41,9 @@ ExpressionPointer Or::decomposed(DerivedPredicates &derivedPredicates)
|
|||||||
|
|
||||||
for (auto &argument : conjunction)
|
for (auto &argument : conjunction)
|
||||||
argument = argument->decomposed(derivedPredicates);
|
argument = argument->decomposed(derivedPredicates);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
conjunction.emplace_back(argument->decomposed(derivedPredicates));
|
conjunction.emplace_back(argument->decomposed(derivedPredicates));
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move this expression’s arguments to the derived predicate
|
// Move this expression’s arguments to the derived predicate
|
||||||
preconditions.emplace_back(std::move(conjunction));
|
preconditions.emplace_back(std::move(conjunction));
|
||||||
|
@ -78,7 +78,7 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
|||||||
// Parse and store variable itself
|
// Parse and store variable itself
|
||||||
parseDeclaration(context, variables);
|
parseDeclaration(context, variables);
|
||||||
|
|
||||||
auto &variable = variables.back();
|
auto variable = variables.back();
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
|
||||||
@ -90,15 +90,14 @@ void Variable::parseTypedDeclaration(Context &context, ExpressionContext &expres
|
|||||||
[&](ExpressionPointer type)
|
[&](ExpressionPointer type)
|
||||||
{
|
{
|
||||||
// Set the argument type for all previously flagged arguments
|
// Set the argument type for all previously flagged arguments
|
||||||
std::for_each(variables.begin(), variables.end(),
|
for (auto &variable : variables)
|
||||||
[&](auto &variable)
|
|
||||||
{
|
{
|
||||||
if (!variable->isDirty())
|
if (!variable->isDirty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
variable->setType(type);
|
variable->setType(type);
|
||||||
variable->setDirty(false);
|
variable->setDirty(false);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
Reference in New Issue
Block a user