diff --git a/include/plasp/sas/Value.h b/include/plasp/sas/Value.h index eb9321c..f7e61c2 100644 --- a/include/plasp/sas/Value.h +++ b/include/plasp/sas/Value.h @@ -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; diff --git a/src/plasp/sas/TranslatorASP.cpp b/src/plasp/sas/TranslatorASP.cpp index f3ceb8e..717d525 100644 --- a/src/plasp/sas/TranslatorASP.cpp +++ b/src/plasp/sas/TranslatorASP.cpp @@ -62,6 +62,8 @@ void TranslatorASP::translate(std::ostream &ostream) const { checkSupport(); + ostream << "#program base." << std::endl << std::endl; + std::vector 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; diff --git a/src/plasp/sas/Value.cpp b/src/plasp/sas/Value.cpp index bd008a0..92bf136 100644 --- a/src/plasp/sas/Value.cpp +++ b/src/plasp/sas/Value.cpp @@ -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;