From b30cecd297cfeeb10cb64d74077ff5910860fa9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sat, 13 Aug 2016 03:08:05 +0200 Subject: [PATCH] Turning translated PDDL predicates into unified variable format in rest of output format. --- src/plasp/pddl/TranslatorASP.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 2d5a798..de56de9 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -202,6 +202,7 @@ void TranslatorASP::translateActions() const std::for_each(actions.cbegin(), actions.cend(), [&](const auto &action) { + // TODO: rename const auto translateLiteral = [&](const auto &ruleHead, const auto &literal) { @@ -381,8 +382,13 @@ void TranslatorASP::translateLiteral(const Expression &literal) const // Translate single predicate if (literal.expressionType() == Expression::Type::Predicate) { - this->translatePredicate(dynamic_cast(literal)); - m_outputStream << ", " << utils::Keyword("true"); + const auto &predicate = dynamic_cast(literal); + + m_outputStream << utils::Keyword("variable") << "("; + this->translatePredicate(predicate); + m_outputStream << "), " << utils::Keyword("value") << "("; + this->translatePredicate(predicate); + m_outputStream << ", " << utils::Keyword("true") << ")"; } // Assuming that "not" expression may only contain a predicate else if (literal.expressionType() == Expression::Type::Not) @@ -390,8 +396,11 @@ void TranslatorASP::translateLiteral(const Expression &literal) const const auto ¬Expression = dynamic_cast(literal); const auto &predicate = dynamic_cast(*notExpression.argument()); + m_outputStream << utils::Keyword("variable") << "("; this->translatePredicate(predicate); - m_outputStream << ", " << utils::Keyword("false"); + m_outputStream << "), " << utils::Keyword("value") << "("; + this->translatePredicate(predicate); + m_outputStream << ", " << utils::Keyword("false") << ")"; } else throw utils::TranslatorException("only primitive predicates and their negations supported as literals currently"); @@ -401,13 +410,12 @@ void TranslatorASP::translateLiteral(const Expression &literal) const void TranslatorASP::translatePredicate(const expressions::Predicate &predicate) const { - m_outputStream << utils::Keyword("predicate") << "(" << utils::escapeASP(predicate.name()); + m_outputStream << utils::escapeASP(predicate.name()); const auto &arguments = predicate.arguments(); if (arguments.empty()) { - m_outputStream << ")"; return; } @@ -434,7 +442,7 @@ void TranslatorASP::translatePredicate(const expressions::Predicate &predicate) throw utils::TranslatorException("only variables and constants supported in predicates currently"); } - m_outputStream << "))"; + m_outputStream << ")"; } ////////////////////////////////////////////////////////////////////////////////////////////////////