Implemented translation of PDDL domain types.

This commit is contained in:
Patrick Lühne 2016-06-10 17:40:32 +02:00
parent da71d4947b
commit 8f0f4bfa65
3 changed files with 130 additions and 4 deletions

View File

@ -6,6 +6,7 @@
#include <plasp/LanguageDetection.h>
#include <plasp/pddl/Description.h>
#include <plasp/pddl/TranslatorASP.h>
#include <plasp/sas/Description.h>
#include <plasp/sas/TranslatorASP.h>
@ -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)

View File

@ -0,0 +1,39 @@
#ifndef __PLASP__PDDL__TRANSLATOR_ASP_H
#define __PLASP__PDDL__TRANSLATOR_ASP_H
#include <plasp/pddl/Description.h>
#include <iosfwd>
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

View File

@ -0,0 +1,82 @@
#include <plasp/pddl/TranslatorASP.h>
#include <plasp/utils/TranslatorException.h>
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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}