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:
void printAsSAS(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;
const std::string &name() const;

View File

@ -112,11 +112,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(preconditions.cbegin(), preconditions.cend(),
[&](const auto &precondition)
{
{
ostream << "precondition(";
operator_.predicate().printAsASP(ostream);
ostream << ", ";
precondition.value().printAsASPCommaSeparated(ostream);
precondition.value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl;
});
@ -128,7 +128,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
ostream << "postcondition(";
operator_.predicate().printAsASP(ostream);
ostream << ", ";
effect.postcondition().value().printAsASPCommaSeparated(ostream);
effect.postcondition().value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl;
});
@ -142,8 +142,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
[&](const auto &fact)
{
ostream << "init(";
fact.value().printAsASPCommaSeparated(ostream);
if (fact.value().sign() == Value::Sign::Negative)
return;
ostream << "initialState(";
fact.value().printAsASP(ostream);
ostream << ")." << std::endl;
});
@ -156,7 +159,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
[&](const auto &fact)
{
ostream << "goal(";
fact.value().printAsASPCommaSeparated(ostream);
fact.value().printAsASPPredicateBody(ostream);
ostream << ")." << std::endl;
});
@ -175,14 +178,14 @@ void TranslatorASP::translate(std::ostream &ostream) const
for (auto i = values.cbegin(); i != values.cend(); i++)
for (auto j = i + 1; j != values.cend(); j++)
{
const auto &value1 = *i;
const auto &value2 = *j;
const auto &value1 = *i;
const auto &value2 = *j;
ostream << ":- time(T), holds(";
value1.printAsASPCommaSeparated(ostream);
ostream << ", T), holds(";
value2.printAsASPCommaSeparated(ostream);
ostream << ", T)." << std::endl;
ostream << ":- ";
value1.printAsASPHoldsPredicate(ostream);
ostream << ", ";
value2.printAsASPHoldsPredicate(ostream);
ostream << "." << std::endl;
}
});
@ -199,14 +202,14 @@ void TranslatorASP::translate(std::ostream &ostream) const
for (auto i = facts.cbegin(); i != facts.cend(); i++)
for (auto j = i + 1; j != facts.cend(); j++)
{
const auto &value1 = i->value();
const auto &value2 = j->value();
const auto &value1 = i->value();
const auto &value2 = j->value();
ostream << ":- time(T), holds(";
value1.printAsASPCommaSeparated(ostream);
ostream << ", T), holds(";
value2.printAsASPCommaSeparated(ostream);
ostream << ", T)." << std::endl;
ostream << ":- ";
value1.printAsASPHoldsPredicate(ostream);
ostream << ", ";
value2.printAsASPHoldsPredicate(ostream);
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");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
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
{
if (m_sign == Value::Sign::Positive)