Added axiom rule support for SAS translator output.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <plasp/sas/Description.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@@ -111,6 +112,22 @@ const AxiomRules &Description::axiomRules() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Description::usesAxiomRules() const
|
||||
{
|
||||
if (!m_axiomRules.empty())
|
||||
return true;
|
||||
|
||||
const auto match = std::find_if(m_variables.cbegin(), m_variables.cend(),
|
||||
[&](const auto &variable)
|
||||
{
|
||||
return variable.axiomLayer() != -1;
|
||||
});
|
||||
|
||||
return match != m_variables.cend();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Description::parseVersionSection(std::istream &istream) const
|
||||
{
|
||||
utils::parseExpected<std::string>(istream, "begin_version");
|
||||
|
@@ -23,15 +23,6 @@ TranslatorASP::TranslatorASP(const Description &description)
|
||||
|
||||
void TranslatorASP::checkSupport() const
|
||||
{
|
||||
const auto &variables = m_description.variables();
|
||||
|
||||
std::for_each(variables.cbegin(), variables.cend(),
|
||||
[&](const auto &variable)
|
||||
{
|
||||
if (variable.axiomLayer() != -1)
|
||||
throw TranslatorException("Axiom layers are currently unsupported");
|
||||
});
|
||||
|
||||
const auto &operators = m_description.operators();
|
||||
|
||||
std::for_each(operators.cbegin(), operators.cend(),
|
||||
@@ -46,9 +37,6 @@ void TranslatorASP::checkSupport() const
|
||||
throw TranslatorException("Conditional effects are currently unsupported");
|
||||
});
|
||||
});
|
||||
|
||||
if (!m_description.axiomRules().empty())
|
||||
throw TranslatorException("Axiom rules are currently unsupported");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -57,11 +45,17 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
{
|
||||
checkSupport();
|
||||
|
||||
const auto usesActionCosts = m_description.usesActionCosts();
|
||||
const auto usesAxiomRules = m_description.usesAxiomRules();
|
||||
|
||||
ostream << "% feature requirements" << std::endl;
|
||||
|
||||
if (m_description.usesActionCosts())
|
||||
if (usesActionCosts)
|
||||
ostream << "requiresFeature(actionCosts)." << std::endl;
|
||||
|
||||
if (usesAxiomRules)
|
||||
ostream << "requiresFeature(axiomRules)." << std::endl;
|
||||
|
||||
ostream << std::endl;
|
||||
ostream << "% initial state" << std::endl;
|
||||
|
||||
@@ -204,6 +198,41 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
if (usesAxiomRules)
|
||||
{
|
||||
ostream << std::endl;
|
||||
ostream << "% axiom rules";
|
||||
|
||||
const auto &axiomRules = m_description.axiomRules();
|
||||
|
||||
for (size_t i = 0; i < axiomRules.size(); i++)
|
||||
{
|
||||
const auto &axiomRule = axiomRules[i];
|
||||
|
||||
ostream << std::endl << "axiomRule(axiomRule" << i << ")." << std::endl;
|
||||
|
||||
const auto &conditions = axiomRule.conditions();
|
||||
|
||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||
[&](const auto &condition)
|
||||
{
|
||||
ostream << "condition(axiomRule(axiomRule" << i << "), ";
|
||||
condition.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
condition.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
|
||||
const auto &postcondition = axiomRule.postcondition();
|
||||
|
||||
ostream << "postcondition(axiomRule(axiomRule" << i << "), ";
|
||||
postcondition.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
postcondition.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user