Enforcing variables to have exactly (and not at most) one value.
This commit is contained in:
parent
081b604c40
commit
401c4069bd
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user