Finished SAS-to-ASP translation with limited support.
This commit is contained in:
parent
eed215871a
commit
d8b87c7bfa
@ -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;
|
||||||
|
@ -112,11 +112,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
|
|
||||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||||
[&](const auto &precondition)
|
[&](const auto &precondition)
|
||||||
{
|
{
|
||||||
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;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -175,14 +178,14 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
for (auto i = values.cbegin(); i != values.cend(); i++)
|
for (auto i = values.cbegin(); i != values.cend(); i++)
|
||||||
for (auto j = i + 1; j != values.cend(); j++)
|
for (auto j = i + 1; j != values.cend(); j++)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,14 +202,14 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
for (auto i = facts.cbegin(); i != facts.cend(); i++)
|
for (auto i = facts.cbegin(); i != facts.cend(); i++)
|
||||||
for (auto j = i + 1; j != facts.cend(); j++)
|
for (auto j = i + 1; j != facts.cend(); j++)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
Reference in New Issue
Block a user