Handling untyped variables as variables of type »object« in PDDL translator for simplicity.

This commit is contained in:
Patrick Lühne 2016-06-14 13:53:09 +02:00
parent 39a32a6e0a
commit c62f3f88f1

View File

@ -50,11 +50,8 @@ void TranslatorASP::translateDomain() const
const auto &domain = m_description.domain(); const auto &domain = m_description.domain();
// Types // Types
if (!domain.types().empty())
{
m_ostream << std::endl; m_ostream << std::endl;
translateTypes(); translateTypes();
}
// Constants // Constants
if (!domain.constants().empty()) if (!domain.constants().empty())
@ -82,11 +79,16 @@ void TranslatorASP::translateDomain() const
void TranslatorASP::translateTypes() const void TranslatorASP::translateTypes() const
{ {
// TODO: escape ASP identifiers
m_ostream << "% types"; m_ostream << "% types";
const auto &types = m_description.domain().types(); const auto &types = m_description.domain().types();
if (types.empty())
{
m_ostream << std::endl << "type(object)." << std::endl;
return;
}
std::for_each(types.cbegin(), types.cend(), std::for_each(types.cbegin(), types.cend(),
[&](const auto &type) [&](const auto &type)
{ {
@ -245,21 +247,21 @@ void TranslatorASP::translateActions() const
void TranslatorASP::translateConstants(const std::string &header, const expressions::Constants &constants) const void TranslatorASP::translateConstants(const std::string &header, const expressions::Constants &constants) const
{ {
m_ostream << "% " << header << std::endl; m_ostream << "% " << header;
std::for_each(constants.cbegin(), constants.cend(), std::for_each(constants.cbegin(), constants.cend(),
[&](const auto &constant) [&](const auto &constant)
{ {
const auto constantName = utils::escapeASP(constant->name()); const auto constantName = utils::escapeASP(constant->name());
m_ostream << "constant(" << constantName << ")." << std::endl; m_ostream << std::endl << "constant(" << constantName << ")." << std::endl;
const auto *type = constant->type(); const auto *type = constant->type();
if (type == nullptr) if (type != nullptr)
return;
m_ostream << "hasType(constant(" << constantName << "), type(" << utils::escapeASP(type->name()) << "))." << std::endl; m_ostream << "hasType(constant(" << constantName << "), type(" << utils::escapeASP(type->name()) << "))." << std::endl;
else
m_ostream << "hasType(constant(" << constantName << "), type(object))." << std::endl;
}); });
} }
@ -279,12 +281,7 @@ void TranslatorASP::translateVariablesHead(const expressions::Variables &variabl
const auto &variable = **i; const auto &variable = **i;
// Handle typed variables
if (variable.type() != nullptr)
m_ostream << utils::escapeASPVariable(variable.name()); m_ostream << utils::escapeASPVariable(variable.name());
// Allow any constant if typing is disabled
else
m_ostream << "constant(" << utils::escapeASPVariable(variable.name()) << ")";
} }
m_ostream << ")"; m_ostream << ")";
@ -306,7 +303,6 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl
if (i != variables.cbegin()) if (i != variables.cbegin())
m_ostream << ", "; m_ostream << ", ";
// Handle typed variables
if (variable.type() != nullptr) if (variable.type() != nullptr)
{ {
if (variable.type()->expressionType() != Expression::Type::PrimitiveType) if (variable.type()->expressionType() != Expression::Type::PrimitiveType)
@ -316,9 +312,8 @@ void TranslatorASP::translateVariablesBody(const expressions::Variables &variabl
m_ostream << "hasType(" << utils::escapeASPVariable(variable.name()) << ", type(" << type.name() << "))"; m_ostream << "hasType(" << utils::escapeASPVariable(variable.name()) << ", type(" << type.name() << "))";
} }
// Allow any constant if typing is disabled
else else
m_ostream << "constant(" << utils::escapeASPVariable(variable.name()) << ")"; m_ostream << "hasType(" << utils::escapeASPVariable(variable.name()) << ", type(object))";
} }
} }