From 046f80353814780e82c3a52395657e10a8c14f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Sun, 12 Jun 2016 22:25:12 +0200 Subject: [PATCH] Implemented translation of PDDL predicates (with primitive types only). --- src/plasp/pddl/TranslatorASP.cpp | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp index 82f8f41..09527c2 100644 --- a/src/plasp/pddl/TranslatorASP.cpp +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -1,5 +1,6 @@ #include +#include #include namespace plasp @@ -48,7 +49,11 @@ void TranslatorASP::translate(std::ostream &ostream) const translateDomain(ostream); if (m_description.containsProblem()) + { + ostream << std::endl; + translateProblem(ostream); + } } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -110,6 +115,54 @@ void TranslatorASP::translateDomain(std::ostream &ostream) const ostream << "hasType(constant(" << constant->name() << "), type(" << type->name() << "))." << std::endl; }); } + + // Predicates + if (!domain.predicates().empty()) + { + ostream << std::endl; + ostream << "% predicates"; + + const auto &predicates = domain.predicates(); + + std::for_each(predicates.cbegin(), predicates.cend(), + [&](const auto &predicate) + { + ostream << std::endl; + + ostream << "predicate(" << predicate->name(); + + const auto &arguments = predicate->arguments(); + + if (arguments.empty()) + { + ostream << ")."; + return; + } + + ostream << "("; + + for (auto i = arguments.cbegin(); i != arguments.cend(); i++) + { + if (i != arguments.cbegin()) + ostream << ", "; + + ostream << utils::escapeASPVariable((*i)->name()); + } + + ostream << ")) :- "; + + for (auto i = arguments.cbegin(); i != arguments.cend(); i++) + { + if (i != arguments.cbegin()) + ostream << ", "; + + const auto &type = *dynamic_cast((*i)->type()); + ostream << "hasType(" << utils::escapeASPVariable((*i)->name()) << ", type(" << type.name() << "))"; + } + + ostream << "."; + }); + } } ////////////////////////////////////////////////////////////////////////////////////////////////////