Ensuring that input contains only predicates, negations, and conjunctions for the time being.
This commit is contained in:
parent
30cfa1b45e
commit
46351b2fe7
@ -1,5 +1,7 @@
|
||||
#include <plasp/pddl/TranslatorASP.h>
|
||||
|
||||
#include <plasp/pddl/expressions/And.h>
|
||||
#include <plasp/pddl/expressions/Not.h>
|
||||
#include <plasp/utils/IO.h>
|
||||
#include <plasp/utils/TranslatorException.h>
|
||||
|
||||
@ -24,7 +26,7 @@ TranslatorASP::TranslatorASP(const Description &description, std::ostream &ostre
|
||||
|
||||
void TranslatorASP::checkSupport() const
|
||||
{
|
||||
// Check for "either" types
|
||||
// Check for "either" types in predicate declarations
|
||||
const auto &predicates = m_description.domain().predicates();
|
||||
|
||||
std::for_each(predicates.cbegin(), predicates.cend(),
|
||||
@ -47,12 +49,63 @@ void TranslatorASP::checkSupport() const
|
||||
{
|
||||
const auto ¶meters = action->parameters();
|
||||
|
||||
// Check for "either" types in action parameters
|
||||
std::for_each(parameters.cbegin(), parameters.cend(),
|
||||
[&](const auto ¶meter)
|
||||
{
|
||||
if (parameter->type()->expressionType() != Expression::Type::PrimitiveType)
|
||||
throw utils::TranslatorException("Only primitive types supported currently");
|
||||
});
|
||||
|
||||
// Check that all preconditions are "and" expressions or single predicates
|
||||
if (action->precondition().expressionType() != Expression::Type::And
|
||||
&& action->precondition().expressionType() != Expression::Type::Predicate)
|
||||
{
|
||||
throw utils::TranslatorException("Only \"and\" expressions and single predicates supported as action preconditions currently");
|
||||
}
|
||||
|
||||
// Check that "and" expression in preconditions contains single predicates only
|
||||
if (action->precondition().expressionType() == Expression::Type::And)
|
||||
{
|
||||
const auto &precondition = dynamic_cast<const expressions::And &>(action->precondition());
|
||||
const auto &preconditionArguments = precondition.arguments();
|
||||
|
||||
std::for_each(preconditionArguments.cbegin(), preconditionArguments.cend(),
|
||||
[&](const auto &argument)
|
||||
{
|
||||
if (argument->expressionType() != Expression::Type::Predicate)
|
||||
throw utils::TranslatorException("Only predicates supported in preconditions currently");
|
||||
});
|
||||
}
|
||||
|
||||
// Check that all effects are "and" expressions
|
||||
if (action->effect().expressionType() != Expression::Type::And
|
||||
&& action->effect().expressionType() != Expression::Type::Predicate)
|
||||
{
|
||||
throw utils::TranslatorException("Only \"and\" expressions and single predicates supported as action effects currently");
|
||||
}
|
||||
|
||||
// Check that "and" expression in effect contains single predicates or negated predicates only
|
||||
if (action->effect().expressionType() == Expression::Type::And)
|
||||
{
|
||||
const auto &effect = dynamic_cast<const expressions::And &>(action->effect());
|
||||
const auto &effectArguments = effect.arguments();
|
||||
|
||||
std::for_each(effectArguments.cbegin(), effectArguments.cend(),
|
||||
[&](const auto &argument)
|
||||
{
|
||||
const Expression *expression = argument.get();
|
||||
|
||||
if (expression->expressionType() == Expression::Type::Not)
|
||||
{
|
||||
const auto ¬Expression = dynamic_cast<const expressions::Not &>(*expression);
|
||||
expression = ¬Expression.argument();
|
||||
}
|
||||
|
||||
if (expression->expressionType() != Expression::Type::Predicate)
|
||||
throw utils::TranslatorException("Only predicates and negated predicates supported in effects currently");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user