Finished SAS-to-ASP translation with limited support.

This commit is contained in:
Patrick Lühne 2016-05-22 22:45:33 +02:00
parent eed215871a
commit d8b87c7bfa
3 changed files with 36 additions and 22 deletions

View File

@ -41,7 +41,8 @@ struct Value
public: public:
void printAsSAS(std::ostream &ostream) const; void printAsSAS(std::ostream &ostream) const;
void printAsASP(std::ostream &ostream) const; void printAsASP(std::ostream &ostream) const;
void printAsASPCommaSeparated(std::ostream &ostream) const; void printAsASPPredicateBody(std::ostream &ostream) const;
void printAsASPHoldsPredicate(std::ostream &ostream) const;
Sign sign() const; Sign sign() const;
const std::string &name() const; const std::string &name() const;

View File

@ -116,7 +116,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
ostream << "precondition("; ostream << "precondition(";
operator_.predicate().printAsASP(ostream); operator_.predicate().printAsASP(ostream);
ostream << ", "; ostream << ", ";
precondition.value().printAsASPCommaSeparated(ostream); precondition.value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl; ostream << ")." << std::endl;
}); });
@ -128,7 +128,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
ostream << "postcondition("; ostream << "postcondition(";
operator_.predicate().printAsASP(ostream); operator_.predicate().printAsASP(ostream);
ostream << ", "; ostream << ", ";
effect.postcondition().value().printAsASPCommaSeparated(ostream); effect.postcondition().value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl; ostream << ")." << std::endl;
}); });
@ -142,8 +142,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(), std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
[&](const auto &fact) [&](const auto &fact)
{ {
ostream << "init("; if (fact.value().sign() == Value::Sign::Negative)
fact.value().printAsASPCommaSeparated(ostream); return;
ostream << "initialState(";
fact.value().printAsASP(ostream);
ostream << ")." << std::endl; ostream << ")." << std::endl;
}); });
@ -156,7 +159,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
[&](const auto &fact) [&](const auto &fact)
{ {
ostream << "goal("; ostream << "goal(";
fact.value().printAsASPCommaSeparated(ostream); fact.value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl; ostream << ")." << std::endl;
}); });
@ -178,11 +181,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
const auto &value1 = *i; const auto &value1 = *i;
const auto &value2 = *j; const auto &value2 = *j;
ostream << ":- time(T), holds("; ostream << ":- ";
value1.printAsASPCommaSeparated(ostream); value1.printAsASPHoldsPredicate(ostream);
ostream << ", T), holds("; ostream << ", ";
value2.printAsASPCommaSeparated(ostream); value2.printAsASPHoldsPredicate(ostream);
ostream << ", T)." << std::endl; ostream << "." << std::endl;
} }
}); });
@ -202,11 +205,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
const auto &value1 = i->value(); const auto &value1 = i->value();
const auto &value2 = j->value(); const auto &value2 = j->value();
ostream << ":- time(T), holds("; ostream << ":- ";
value1.printAsASPCommaSeparated(ostream); value1.printAsASPHoldsPredicate(ostream);
ostream << ", T), holds("; ostream << ", ";
value2.printAsASPCommaSeparated(ostream); value2.printAsASPHoldsPredicate(ostream);
ostream << ", T)." << std::endl; ostream << "." << std::endl;
} }
}); });
} }

View File

@ -113,13 +113,23 @@ void Value::printAsASP(std::ostream &ostream) const
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void Value::printAsASPCommaSeparated(std::ostream &ostream) const void Value::printAsASPPredicateBody(std::ostream &ostream) const
{ {
ostream << utils::escapeASP(m_name) << ", " << (m_sign == Sign::Positive ? "true" : "false"); ostream << utils::escapeASP(m_name) << ", " << (m_sign == Sign::Positive ? "true" : "false");
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void Value::printAsASPHoldsPredicate(std::ostream &ostream) const
{
if (m_sign == Value::Sign::Negative)
ostream << "not ";
ostream << "holds(" << utils::escapeASP(m_name) << ", t)";
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Value::printAsSAS(std::ostream &ostream) const void Value::printAsSAS(std::ostream &ostream) const
{ {
if (m_sign == Value::Sign::Positive) if (m_sign == Value::Sign::Positive)