From e9c464b319646963b0107070ccaa1481147c41fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 13 Jun 2016 02:59:43 +0200 Subject: [PATCH] =?UTF-8?q?Added=20translation=20of=20a=20PDDL=20problem?= =?UTF-8?q?=E2=80=99s=20initial=20state.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/plasp/pddl/TranslatorASP.h | 1 + src/plasp/pddl/TranslatorASP.cpp | 37 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/plasp/pddl/TranslatorASP.h b/include/plasp/pddl/TranslatorASP.h index a8b2037..32da5a9 100644 --- a/include/plasp/pddl/TranslatorASP.h +++ b/include/plasp/pddl/TranslatorASP.h @@ -34,6 +34,7 @@ class TranslatorASP void translateProblem() const; void translateObjects() const; + void translateInitialState() const; void translateVariablesHead(const expressions::Variables &variables) const; void translateVariablesBody(const expressions::Variables &variables) const; diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index f6cc81d..66e0166 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -464,6 +464,10 @@ void TranslatorASP::translateProblem() const m_ostream << std::endl; translateObjects(); } + + // Initial State + m_ostream << std::endl; + translateInitialState(); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -492,5 +496,38 @@ void TranslatorASP::translateObjects() const //////////////////////////////////////////////////////////////////////////////////////////////////// +void TranslatorASP::translateInitialState() const +{ + m_ostream << "% initial state"; + + const auto &initialStateFacts = m_description.problem().initialState().facts(); + + std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(), + [&](const auto &fact) + { + m_ostream << std::endl << "initialState("; + + // Translate single predicate + if (fact->expressionType() == Expression::Type::Predicate) + this->translatePredicate(dynamic_cast(*fact)); + // Assuming that "not" expression may only contain a predicate + else if (fact->expressionType() == Expression::Type::Not) + { + const auto ¬Expression = dynamic_cast(*fact); + + if (notExpression.argument()->expressionType() != Expression::Type::Predicate) + throw utils::TranslatorException("Only negations of simple predicates supported in initial state currently"); + } + else + throw utils::TranslatorException("Only predicates and their negations supported in initial state currently"); + + m_ostream << ")."; + }); + + m_ostream << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + } }