From 8f0f4bfa6554df040a813e5ae0c47dcd1e642f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Fri, 10 Jun 2016 17:40:32 +0200 Subject: [PATCH] Implemented translation of PDDL domain types. --- apps/plasp-app/main.cpp | 13 +++-- include/plasp/pddl/TranslatorASP.h | 39 ++++++++++++++ src/plasp/pddl/TranslatorASP.cpp | 82 ++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 include/plasp/pddl/TranslatorASP.h create mode 100644 src/plasp/pddl/TranslatorASP.cpp diff --git a/apps/plasp-app/main.cpp b/apps/plasp-app/main.cpp index 09f892a..bd6eee7 100644 --- a/apps/plasp-app/main.cpp +++ b/apps/plasp-app/main.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -102,12 +103,16 @@ int main(int argc, char **argv) } if (language == plasp::Language::Type::PDDL) - plasp::pddl::Description::fromParser(std::move(parser)); + { + const auto description = plasp::pddl::Description::fromParser(std::move(parser)); + const auto translator = plasp::pddl::TranslatorASP(description); + translator.translate(std::cout); + } else if (language == plasp::Language::Type::SAS) { - const auto sasDescription = plasp::sas::Description::fromParser(std::move(parser)); - const auto sasTranslator = plasp::sas::TranslatorASP(sasDescription); - sasTranslator.translate(std::cout); + const auto description = plasp::sas::Description::fromParser(std::move(parser)); + const auto translator = plasp::sas::TranslatorASP(description); + translator.translate(std::cout); } } catch (const std::exception &e) diff --git a/include/plasp/pddl/TranslatorASP.h b/include/plasp/pddl/TranslatorASP.h new file mode 100644 index 0000000..06205d8 --- /dev/null +++ b/include/plasp/pddl/TranslatorASP.h @@ -0,0 +1,39 @@ +#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H +#define __PLASP__PDDL__TRANSLATOR_ASP_H + +#include + +#include + +namespace plasp +{ +namespace pddl +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TranslatorASP +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +class TranslatorASP +{ + public: + explicit TranslatorASP(const Description &description); + + void translate(std::ostream &ostream) const; + + void translateDomain(std::ostream &ostream) const; + + + void translateProblem(std::ostream &ostream) const; + + const Description &m_description; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/src/plasp/pddl/TranslatorASP.cpp b/src/plasp/pddl/TranslatorASP.cpp new file mode 100644 index 0000000..200bb7e --- /dev/null +++ b/src/plasp/pddl/TranslatorASP.cpp @@ -0,0 +1,82 @@ +#include + +#include + +namespace plasp +{ +namespace pddl +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// TranslatorASP +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +TranslatorASP::TranslatorASP(const Description &description) +: m_description(description) +{ +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void TranslatorASP::translate(std::ostream &ostream) const +{ + translateDomain(ostream); + + if (m_description.containsProblem()) + translateProblem(ostream); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void TranslatorASP::translateDomain(std::ostream &ostream) const +{ + ostream + << "%---------------------------------------" << std::endl + << "% domain" << std::endl + << "%---------------------------------------" << std::endl << std::endl; + + const auto &domain = m_description.domain(); + + // Types + ostream << "% types" << std::endl; + + const auto &types = domain.types(); + + std::for_each(types.cbegin(), types.cend(), + [&](const auto &type) + { + ostream << "type(" << type->name() << ")." << std::endl; + }); + + // Type inheritance + ostream << std::endl << "% type inheritance" << std::endl; + + std::for_each(types.cbegin(), types.cend(), + [&](const auto &type) + { + const auto &parentTypes = type->parentTypes(); + + std::for_each(parentTypes.cbegin(), parentTypes.cend(), + [&](const auto &parentType) + { + ostream << "inheritsFrom(type(" << type->name() << "), type(" << parentType->name() << "))." << std::endl; + }); + }); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +void TranslatorASP::translateProblem(std::ostream &ostream) const +{ + ostream << std::endl + << "%---------------------------------------" << std::endl + << "% problem" << std::endl + << "%---------------------------------------" << std::endl << std::endl; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}