Changed SAS translator output format to be closer to the SAS representation.
This commit is contained in:
parent
2ef710642b
commit
03ae0dc301
@ -30,6 +30,8 @@ class Variable
|
|||||||
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables);
|
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void printNameAsASP(std::ostream &ostream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
int axiomLayer() const;
|
int axiomLayer() const;
|
||||||
const Values &values() const;
|
const Values &values() const;
|
||||||
|
@ -63,8 +63,6 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
{
|
{
|
||||||
checkSupport();
|
checkSupport();
|
||||||
|
|
||||||
ostream << "#program base." << std::endl << std::endl;
|
|
||||||
|
|
||||||
std::vector<const Value *> fluents;
|
std::vector<const Value *> fluents;
|
||||||
|
|
||||||
const auto &variables = m_description.variables();
|
const auto &variables = m_description.variables();
|
||||||
@ -137,14 +135,14 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
});
|
});
|
||||||
|
|
||||||
ostream << std::endl;
|
ostream << std::endl;
|
||||||
ostream << "% actions" << std::endl;
|
ostream << "% actions";
|
||||||
|
|
||||||
const auto &operators = m_description.operators();
|
const auto &operators = m_description.operators();
|
||||||
|
|
||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
ostream << "action(";
|
ostream << std::endl << "action(";
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.predicate().printAsASP(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
|
|
||||||
@ -177,13 +175,10 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
effect.postcondition().value().printAsASPPredicateBody(ostream);
|
effect.postcondition().value().printAsASPPredicateBody(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << std::endl;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << "#program step(t)." << std::endl << std::endl;
|
ostream << std::endl;
|
||||||
|
ostream << "% variables";
|
||||||
ostream << "% constraints derived from SAS variables" << std::endl;
|
|
||||||
|
|
||||||
std::for_each(variables.cbegin(), variables.cend(),
|
std::for_each(variables.cbegin(), variables.cend(),
|
||||||
[&](const auto &variable)
|
[&](const auto &variable)
|
||||||
@ -192,76 +187,45 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
|
|
||||||
BOOST_ASSERT(!values.empty());
|
BOOST_ASSERT(!values.empty());
|
||||||
|
|
||||||
// Skip trivial constraints of the form :- x, not x.
|
ostream << std::endl << "variable(";
|
||||||
if (values.size() == 2 && values[0].name() == values[1].name())
|
variable.printNameAsASP(ostream);
|
||||||
return;
|
ostream << ")." << std::endl;
|
||||||
|
|
||||||
for (auto i = values.cbegin(); i != values.cend(); i++)
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
{
|
[&](const auto &value)
|
||||||
const auto &value1 = *i;
|
|
||||||
|
|
||||||
if (value1 == Value::None)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (auto j = i + 1; j != values.cend(); j++)
|
|
||||||
{
|
{
|
||||||
const auto &value2 = *j;
|
ostream << "variableValue(";
|
||||||
|
variable.printNameAsASP(ostream);
|
||||||
if (value2 == Value::None)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ostream << "mutex(";
|
|
||||||
value1.printAsASPPredicateBody(ostream);
|
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
value2.printAsASPPredicateBody(ostream);
|
if (value == Value::None)
|
||||||
|
ostream << "noneValue";
|
||||||
|
else
|
||||||
|
value.printAsASPPredicateBody(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// No further constraint with <none of those> values (the variable need not be assigned at all)
|
|
||||||
if (values.back() == Value::None)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ostream << ":- ";
|
|
||||||
|
|
||||||
for (auto i = values.cbegin(); i != values.cend(); i++)
|
|
||||||
{
|
|
||||||
const auto &value = *i;
|
|
||||||
|
|
||||||
if (i != values.cbegin())
|
|
||||||
ostream << ", ";
|
|
||||||
|
|
||||||
ostream << "holds(";
|
|
||||||
value.negated().printAsASPPredicateBody(ostream);
|
|
||||||
ostream << ", t)";
|
|
||||||
}
|
|
||||||
|
|
||||||
ostream << "." << std::endl;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ostream << std::endl;
|
ostream << std::endl;
|
||||||
ostream << "% constraints derived from SAS mutex groups" << std::endl;
|
ostream << "% mutex groups";
|
||||||
|
|
||||||
const auto &mutexGroups = m_description.mutexGroups();
|
const auto &mutexGroups = m_description.mutexGroups();
|
||||||
|
|
||||||
std::for_each(mutexGroups.cbegin(), mutexGroups.cend(),
|
for (size_t i = 0; i < mutexGroups.size(); i++)
|
||||||
[&](const auto &mutexGroup)
|
{
|
||||||
{
|
const auto &mutexGroup = mutexGroups[i];
|
||||||
const auto &facts = mutexGroup.facts();
|
|
||||||
|
|
||||||
for (auto i = facts.cbegin(); i != facts.cend(); i++)
|
ostream << std::endl << "mutexGroup(mutexGroup" << i << ").";
|
||||||
for (auto j = i + 1; j != facts.cend(); j++)
|
|
||||||
{
|
|
||||||
const auto &value1 = i->value();
|
|
||||||
const auto &value2 = j->value();
|
|
||||||
|
|
||||||
ostream << "mutex(";
|
const auto &facts = mutexGroup.facts();
|
||||||
value1.printAsASPPredicateBody(ostream);
|
|
||||||
ostream << ", ";
|
std::for_each(facts.cbegin(), facts.cend(),
|
||||||
value2.printAsASPPredicateBody(ostream);
|
[&](const auto &fact)
|
||||||
ostream << ")." << std::endl;
|
{
|
||||||
}
|
ostream << "mutexGroupFact(mutexGroup" << i << ", ";
|
||||||
});
|
fact.value().printAsASPPredicateBody(ostream);
|
||||||
|
ostream << ")." << std::endl;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -50,6 +50,13 @@ Variable Variable::fromSAS(std::istream &istream)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void Variable::printNameAsASP(std::ostream &ostream) const
|
||||||
|
{
|
||||||
|
ostream << utils::escapeASP(m_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const Variable &Variable::referenceFromSAS(std::istream &istream, const Variables &variables)
|
const Variable &Variable::referenceFromSAS(std::istream &istream, const Variables &variables)
|
||||||
{
|
{
|
||||||
const auto variableID = utils::parse<size_t>(istream);
|
const auto variableID = utils::parse<size_t>(istream);
|
||||||
|
Reference in New Issue
Block a user