Made SAS translator output format contain less IDs.
This commit is contained in:
parent
3a2dfd97b8
commit
bf6300f36b
|
@ -19,26 +19,22 @@ holds(Var, Val, 0) :- initialState(Var, Val).
|
||||||
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
|
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
|
||||||
|
|
||||||
% Apply effects
|
% 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).
|
modified(Var, t) :- caused(Var, Val, t).
|
||||||
|
|
||||||
holds(Var, Val, 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).
|
holds(Var, Val, t) :- holds(Var, Val, t - 1), not modified(Var, t).
|
||||||
|
|
||||||
% Check that variables without <none of those> values are unique
|
% Check that variables have unique values
|
||||||
:- variable(X), Var = variable(X), not contains(Var, noneValue), not 1 {holds(Var, Val, t) : contains(Var, Val)} 1.
|
:- variable(X), Var = variable(X), not 1 {holds(Var, Val, t) : contains(Var, Val)} 1.
|
||||||
:- contains(Var, noneValue), not {holds(Var, Val, t) : contains(Var, Val)} 1.
|
|
||||||
|
|
||||||
% Check mutexes
|
% Check mutexes
|
||||||
:- mutexGroup(X), M = mutexGroup(X), not {holds(Var, Val, t) : contains(M, Var, Val)} 1.
|
:- 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).
|
#program check(t).
|
||||||
|
|
||||||
% Verify that goal is met
|
% Verify that goal is met
|
||||||
:- query(t), goal(Var, Val), not holds(Var, Val, t).
|
:- query(t), goal(Var, Val), not holds(Var, Val, t).
|
||||||
|
|
||||||
#show query/1.
|
#show query/1.
|
||||||
#show do/2.
|
#show occurs/2.
|
||||||
|
|
|
@ -24,8 +24,6 @@ class TranslatorASP
|
||||||
void translate(std::ostream &ostream) const;
|
void translate(std::ostream &ostream) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void checkSupport() const;
|
|
||||||
|
|
||||||
const Description &m_description;
|
const Description &m_description;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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
|
void TranslatorASP::translate(std::ostream &ostream) const
|
||||||
{
|
{
|
||||||
checkSupport();
|
|
||||||
|
|
||||||
const auto usesActionCosts = m_description.usesActionCosts();
|
const auto usesActionCosts = m_description.usesActionCosts();
|
||||||
const auto usesAxiomRules = m_description.usesAxiomRules();
|
const auto usesAxiomRules = m_description.usesAxiomRules();
|
||||||
const auto usesConditionalEffects = m_description.usesConditionalEffects();
|
const auto usesConditionalEffects = m_description.usesConditionalEffects();
|
||||||
|
@ -118,12 +96,7 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||||
ostream << "contains(";
|
ostream << "contains(";
|
||||||
variable.printNameAsASPPredicate(ostream);
|
variable.printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
|
value.printAsASPPredicate(ostream);
|
||||||
if (value == Value::None)
|
|
||||||
ostream << "noneValue";
|
|
||||||
else
|
|
||||||
value.printAsASPPredicate(ostream);
|
|
||||||
|
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -133,20 +106,12 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||||
|
|
||||||
const auto &operators = m_description.operators();
|
const auto &operators = m_description.operators();
|
||||||
|
|
||||||
size_t currentActionID = 0;
|
|
||||||
size_t currentEffectID = 0;
|
|
||||||
|
|
||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
const auto actionID = std::to_string(currentActionID);
|
ostream << std::endl;
|
||||||
currentActionID++;
|
|
||||||
|
|
||||||
ostream << std::endl << "action(" << actionID << ")." << std::endl;
|
|
||||||
|
|
||||||
ostream << "label(action(" << actionID << "), ";
|
|
||||||
operator_.printPredicateAsASP(ostream);
|
operator_.printPredicateAsASP(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << "." << std::endl;
|
||||||
|
|
||||||
const auto &preconditions = operator_.preconditions();
|
const auto &preconditions = operator_.preconditions();
|
||||||
|
|
||||||
|
@ -156,7 +121,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||||
if (precondition.value() == Value::None)
|
if (precondition.value() == Value::None)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "precondition(action(" << actionID << "), ";
|
ostream << "precondition(";
|
||||||
|
operator_.printPredicateAsASP(ostream);
|
||||||
|
ostream << ", ";
|
||||||
precondition.variable().printNameAsASPPredicate(ostream);
|
precondition.variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
precondition.value().printAsASPPredicate(ostream);
|
precondition.value().printAsASPPredicate(ostream);
|
||||||
|
@ -165,38 +132,34 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||||
|
|
||||||
const auto &effects = operator_.effects();
|
const auto &effects = operator_.effects();
|
||||||
|
|
||||||
|
size_t currentEffectID = 0;
|
||||||
|
|
||||||
std::for_each(effects.cbegin(), effects.cend(),
|
std::for_each(effects.cbegin(), effects.cend(),
|
||||||
[&](const auto &effect)
|
[&](const auto &effect)
|
||||||
{
|
{
|
||||||
if (effect.postcondition().value() == Value::None)
|
const auto &conditions = effect.conditions();
|
||||||
return;
|
|
||||||
|
|
||||||
const auto effectID = std::to_string(currentEffectID);
|
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||||
currentEffectID++;
|
[&](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 << "postcondition(";
|
||||||
ostream << "contains(action(" << actionID << "), effect(" << effectID << "))." << std::endl;
|
operator_.printPredicateAsASP(ostream);
|
||||||
|
ostream << ", effect(" << currentEffectID << "), ";
|
||||||
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 << "), ";
|
|
||||||
effect.postcondition().variable().printNameAsASPPredicate(ostream);
|
effect.postcondition().variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
effect.postcondition().value().printAsASPPredicate(ostream);
|
effect.postcondition().value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
|
|
||||||
|
currentEffectID++;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (usesActionCosts)
|
if (usesActionCosts)
|
||||||
|
|
|
@ -138,6 +138,13 @@ void Value::printAsASP(std::ostream &ostream) const
|
||||||
|
|
||||||
void Value::printAsASPPredicate(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) << ", "
|
ostream << "value(" << utils::escapeASP(m_name) << ", "
|
||||||
<< (m_sign == Sign::Positive ? "true" : "false") << ")";
|
<< (m_sign == Sign::Positive ? "true" : "false") << ")";
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue