Implemented translation of PDDL domain types.

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

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;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}