Enforcing variables to have exactly (and not at most) one value.

This commit is contained in:
Patrick Lühne 2016-05-23 01:02:45 +02:00
parent 081b604c40
commit 401c4069bd
3 changed files with 35 additions and 0 deletions

View File

@ -39,6 +39,8 @@ struct Value
static const Value &referenceFromSAS(std::istream &istream, const Variable &variable);
public:
Value negated() const;
void printAsSAS(std::ostream &ostream) const;
void printAsASP(std::ostream &ostream) const;
void printAsASPPredicateBody(std::ostream &ostream) const;

View File

@ -62,6 +62,8 @@ void TranslatorASP::translate(std::ostream &ostream) const
{
checkSupport();
ostream << "#program base." << std::endl << std::endl;
std::vector<const std::string *> fluents;
const auto &variables = m_description.variables();
@ -164,6 +166,8 @@ void TranslatorASP::translate(std::ostream &ostream) const
ostream << std::endl;
});
ostream << "#program step(t)." << std::endl << std::endl;
ostream << "% constraints derived from SAS variables" << std::endl;
std::for_each(variables.cbegin(), variables.cend(),
@ -187,6 +191,22 @@ void TranslatorASP::translate(std::ostream &ostream) const
value2.printAsASPPredicateBody(ostream);
ostream << ")." << std::endl;
}
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;

View File

@ -39,6 +39,19 @@ Value::Value()
////////////////////////////////////////////////////////////////////////////////////////////////////
Value Value::negated() const
{
Value negated;
negated.m_sign = (m_sign == Sign::Positive ? Sign::Negative : Sign::Positive);
negated.m_name = m_name;
negated.m_hasArguments = m_hasArguments;
return negated;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Value Value::fromSAS(std::istream &istream)
{
Value value;