From 46351b2fe7da5e8d73d3c4b297a1f7af59bdda03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 12 Jun 2016 23:38:44 +0200 Subject: [PATCH] Ensuring that input contains only predicates, negations, and conjunctions for the time being. --- src/plasp/pddl/TranslatorASP.cpp | 55 +++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 59d842f..305f6cc 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include @@ -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(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(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(*expression); + expression = ¬Expression.argument(); + } + + if (expression->expressionType() != Expression::Type::Predicate) + throw utils::TranslatorException("Only predicates and negated predicates supported in effects currently"); + }); + } }); }