Made SAS translator output format contain less IDs.

This commit is contained in:
Patrick Lühne 2016-05-24 01:42:15 +02:00
parent 3a2dfd97b8
commit bf6300f36b
4 changed files with 36 additions and 72 deletions

View File

@ -19,26 +19,22 @@ holds(Var, Val, 0) :- initialState(Var, Val).
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
% Apply effects
caused(Var, Val, t) :- occurs(A, t), contains(A, E), postcondition(E, Var, Val).
caused(Var, Val, t) :- occurs(A, t), postcondition(A, _, Var, Val).
modified(Var, t) :- caused(Var, Val, t).
holds(Var, Val, t) :- caused(Var, Val, t).
holds(Var, Val, t) :- holds(Var, Val, t - 1), not modified(Var, t).
% Check that variables without <none of those> values are unique
:- variable(X), Var = variable(X), not contains(Var, noneValue), not 1 {holds(Var, Val, t) : contains(Var, Val)} 1.
:- contains(Var, noneValue), not {holds(Var, Val, t) : contains(Var, Val)} 1.
% Check that variables have unique values
:- variable(X), Var = variable(X), not 1 {holds(Var, Val, t) : contains(Var, Val)} 1.
% Check mutexes
:- mutexGroup(X), M = mutexGroup(X), not {holds(Var, Val, t) : contains(M, Var, Val)} 1.
% Output predicate
do(L, t) :- occurs(A, t), label(A, action(L)).
#program check(t).
% Verify that goal is met
:- query(t), goal(Var, Val), not holds(Var, Val, t).
#show query/1.
#show do/2.
#show occurs/2.

View File

@ -24,8 +24,6 @@ class TranslatorASP
void translate(std::ostream &ostream) const;
private:
void checkSupport() const;
const Description &m_description;
};

View File

@ -21,30 +21,8 @@ TranslatorASP::TranslatorASP(const Description &description)
////////////////////////////////////////////////////////////////////////////////////////////////////
void TranslatorASP::checkSupport() const
{
const auto &operators = m_description.operators();
std::for_each(operators.cbegin(), operators.cend(),
[&](const auto &operator_)
{
const auto &effects = operator_.effects();
std::for_each(effects.cbegin(), effects.cend(),
[&](const auto &effect)
{
if (!effect.conditions().empty())
throw TranslatorException("Conditional effects are currently unsupported");
});
});
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void TranslatorASP::translate(std::ostream &ostream) const
{
checkSupport();
const auto usesActionCosts = m_description.usesActionCosts();
const auto usesAxiomRules = m_description.usesAxiomRules();
const auto usesConditionalEffects = m_description.usesConditionalEffects();
@ -118,12 +96,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
ostream << "contains(";
variable.printNameAsASPPredicate(ostream);
ostream << ", ";
if (value == Value::None)
ostream << "noneValue";
else
value.printAsASPPredicate(ostream);
value.printAsASPPredicate(ostream);
ostream << ")." << std::endl;
});
});
@ -133,20 +106,12 @@ void TranslatorASP::translate(std::ostream &ostream) const
const auto &operators = m_description.operators();
size_t currentActionID = 0;
size_t currentEffectID = 0;
std::for_each(operators.cbegin(), operators.cend(),
[&](const auto &operator_)
{
const auto actionID = std::to_string(currentActionID);
currentActionID++;
ostream << std::endl << "action(" << actionID << ")." << std::endl;
ostream << "label(action(" << actionID << "), ";
ostream << std::endl;
operator_.printPredicateAsASP(ostream);
ostream << ")." << std::endl;
ostream << "." << std::endl;
const auto &preconditions = operator_.preconditions();
@ -156,7 +121,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
if (precondition.value() == Value::None)
return;
ostream << "precondition(action(" << actionID << "), ";
ostream << "precondition(";
operator_.printPredicateAsASP(ostream);
ostream << ", ";
precondition.variable().printNameAsASPPredicate(ostream);
ostream << ", ";
precondition.value().printAsASPPredicate(ostream);
@ -165,38 +132,34 @@ void TranslatorASP::translate(std::ostream &ostream) const
const auto &effects = operator_.effects();
size_t currentEffectID = 0;
std::for_each(effects.cbegin(), effects.cend(),
[&](const auto &effect)
{
if (effect.postcondition().value() == Value::None)
return;
const auto &conditions = effect.conditions();
const auto effectID = std::to_string(currentEffectID);
currentEffectID++;
std::for_each(conditions.cbegin(), conditions.cend(),
[&](const auto &condition)
{
ostream << "effectCondition(";
operator_.printPredicateAsASP(ostream);
ostream << ", effect(" << currentEffectID << "), ";
condition.variable().printNameAsASPPredicate(ostream);
ostream << ", ";
condition.value().printAsASPPredicate(ostream);
ostream << ")." << std::endl;
});
ostream << "effect(" << effectID << ")." << std::endl;
ostream << "contains(action(" << actionID << "), effect(" << effectID << "))." << std::endl;
if (usesConditionalEffects)
{
const auto &conditions = effect.conditions();
std::for_each(conditions.cbegin(), conditions.cend(),
[&](const auto &condition)
{
ostream << "condition(effect(" << effectID << "), ";
condition.variable().printNameAsASPPredicate(ostream);
ostream << ", ";
condition.value().printAsASPPredicate(ostream);
ostream << ")." << std::endl;
});
}
ostream << "postcondition(effect(" << effectID << "), ";
ostream << "postcondition(";
operator_.printPredicateAsASP(ostream);
ostream << ", effect(" << currentEffectID << "), ";
effect.postcondition().variable().printNameAsASPPredicate(ostream);
ostream << ", ";
effect.postcondition().value().printAsASPPredicate(ostream);
ostream << ")." << std::endl;
currentEffectID++;
});
if (usesActionCosts)

View File

@ -138,6 +138,13 @@ void Value::printAsASP(std::ostream &ostream) const
void Value::printAsASPPredicate(std::ostream &ostream) const
{
// TODO: do not compare by value
if (*this == Value::None)
{
ostream << "value(none)";
return;
}
ostream << "value(" << utils::escapeASP(m_name) << ", "
<< (m_sign == Sign::Positive ? "true" : "false") << ")";
}