Finished SAS-to-ASP translation with limited support.
This commit is contained in:
parent
eed215871a
commit
d8b87c7bfa
@ -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;
|
||||
|
@ -116,7 +116,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
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;
|
||||
});
|
||||
|
||||
@ -178,11 +181,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
@ -202,11 +205,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user