Changed SAS translator output format once more to make it even closer to the SAS format.
This commit is contained in:
parent
02a5b11884
commit
4c6c739060
@ -3,33 +3,27 @@
|
||||
#program base.
|
||||
|
||||
% Establish initial state
|
||||
holds(F, 0) :- initialState(F).
|
||||
holds(Var, Val, 0) :- initialState(Var, Val).
|
||||
|
||||
#program step(t).
|
||||
|
||||
% Perform actions
|
||||
1 {occurs(A, t) : action(A)} 1.
|
||||
1 {occurs(action(A), t) : action(A)} 1.
|
||||
|
||||
% Check preconditions
|
||||
:- occurs(A, t), precondition(A, F, true), not holds(F, t - 1).
|
||||
:- occurs(A, t), precondition(A, F, false), holds(F, t - 1).
|
||||
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
|
||||
|
||||
% Apply effects
|
||||
holds(F, t) :- occurs(A, t), postcondition(A, F, true), action(A).
|
||||
deleted(F, t) :- occurs(A, t), postcondition(A, F, false), action(A).
|
||||
holds(F, t) :- holds(F, t - 1), not deleted(F, t).
|
||||
caused(Var, Val, t) :- occurs(A, t), postcondition(A, Var, Val).
|
||||
modified(Var, t) :- caused(Var, Val, t).
|
||||
|
||||
% Enforce mutexes
|
||||
deleted(F2, t) :- mutex(F1, true, F2, true), holds(F1, t).
|
||||
holds(F2, t) :- mutex(F1, true, F2, false), holds(F1, t).
|
||||
deleted(F2, t) :- mutex(F1, false, F2, true), not holds(F1, t).
|
||||
holds(F2, t) :- mutex(F1, false, F2, false), not holds(F1, t).
|
||||
holds(Var, Val, t) :- caused(Var, Val, t).
|
||||
holds(Var, Val, t) :- holds(Var, Val, t - 1), not modified(Var, t).
|
||||
|
||||
#program check(t).
|
||||
|
||||
% Verify that goal is met
|
||||
:- query(t), goal(F, true), not holds(F, t).
|
||||
:- query(t), goal(F, false), holds(F, t).
|
||||
:- query(t), goal(Var, Val), not holds(Var, Val, t).
|
||||
|
||||
#show query/1.
|
||||
#show occurs/2.
|
||||
|
@ -34,6 +34,8 @@ class Operator
|
||||
static Operator fromSAS(std::istream &istream, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printPredicateAsASP(std::ostream &ostream) const;
|
||||
|
||||
const Predicate &predicate() const;
|
||||
const Conditions &preconditions() const;
|
||||
const Effects &effects() const;
|
||||
|
@ -44,7 +44,7 @@ struct Value
|
||||
|
||||
void printAsSAS(std::ostream &ostream) const;
|
||||
void printAsASP(std::ostream &ostream) const;
|
||||
void printAsASPPredicateBody(std::ostream &ostream) const;
|
||||
void printAsASPPredicate(std::ostream &ostream) const;
|
||||
|
||||
Sign sign() const;
|
||||
const std::string &name() const;
|
||||
|
@ -30,7 +30,7 @@ class Variable
|
||||
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables);
|
||||
|
||||
public:
|
||||
void printNameAsASP(std::ostream &ostream) const;
|
||||
void printNameAsASPPredicate(std::ostream &ostream) const;
|
||||
|
||||
const std::string &name() const;
|
||||
int axiomLayer() const;
|
||||
|
@ -46,6 +46,15 @@ Operator Operator::fromSAS(std::istream &istream, const Variables &variables)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Operator::printPredicateAsASP(std::ostream &ostream) const
|
||||
{
|
||||
ostream << "action(";
|
||||
m_predicate.printAsASP(ostream);
|
||||
ostream << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const Predicate &Operator::predicate() const
|
||||
{
|
||||
return m_predicate;
|
||||
|
@ -74,9 +74,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
return;
|
||||
|
||||
ostream << "initialState(";
|
||||
fact.variable().printNameAsASP(ostream);
|
||||
fact.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
fact.value().printAsASPPredicateBody(ostream);
|
||||
fact.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
|
||||
@ -92,9 +92,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
return;
|
||||
|
||||
ostream << "goal(";
|
||||
fact.variable().printNameAsASP(ostream);
|
||||
fact.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
fact.value().printAsASPPredicateBody(ostream);
|
||||
fact.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
|
||||
@ -110,20 +110,22 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
|
||||
BOOST_ASSERT(!values.empty());
|
||||
|
||||
ostream << std::endl << "variable(";
|
||||
variable.printNameAsASP(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
ostream << std::endl;
|
||||
variable.printNameAsASPPredicate(ostream);
|
||||
ostream << "." << std::endl;
|
||||
|
||||
std::for_each(values.cbegin(), values.cend(),
|
||||
[&](const auto &value)
|
||||
{
|
||||
ostream << "variableValue(";
|
||||
variable.printNameAsASP(ostream);
|
||||
ostream << "contains(";
|
||||
variable.printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
|
||||
if (value == Value::None)
|
||||
ostream << "noneValue";
|
||||
else
|
||||
value.printAsASPPredicateBody(ostream);
|
||||
value.printAsASPPredicate(ostream);
|
||||
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
});
|
||||
@ -136,9 +138,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
std::for_each(operators.cbegin(), operators.cend(),
|
||||
[&](const auto &operator_)
|
||||
{
|
||||
ostream << std::endl << "action(";
|
||||
operator_.predicate().printAsASP(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
ostream << std::endl;
|
||||
operator_.printPredicateAsASP(ostream);
|
||||
ostream << "." << std::endl;
|
||||
|
||||
const auto &preconditions = operator_.preconditions();
|
||||
|
||||
@ -149,11 +151,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
return;
|
||||
|
||||
ostream << "precondition(";
|
||||
operator_.predicate().printAsASP(ostream);
|
||||
operator_.printPredicateAsASP(ostream);
|
||||
ostream << ", ";
|
||||
precondition.variable().printNameAsASP(ostream);
|
||||
precondition.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
precondition.value().printAsASPPredicateBody(ostream);
|
||||
precondition.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
|
||||
@ -166,11 +168,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
return;
|
||||
|
||||
ostream << "postcondition(";
|
||||
operator_.predicate().printAsASP(ostream);
|
||||
operator_.printPredicateAsASP(ostream);
|
||||
ostream << ", ";
|
||||
effect.postcondition().variable().printNameAsASP(ostream);
|
||||
effect.postcondition().variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
effect.postcondition().value().printAsASPPredicateBody(ostream);
|
||||
effect.postcondition().value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
});
|
||||
@ -191,10 +193,10 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
||||
std::for_each(facts.cbegin(), facts.cend(),
|
||||
[&](const auto &fact)
|
||||
{
|
||||
ostream << "mutexGroupFact(mutexGroup" << i << ", ";
|
||||
fact.variable().printNameAsASP(ostream);
|
||||
ostream << "contains(mutexGroup(mutexGroup" << i << "), ";
|
||||
fact.variable().printNameAsASPPredicate(ostream);
|
||||
ostream << ", ";
|
||||
fact.value().printAsASPPredicateBody(ostream);
|
||||
fact.value().printAsASPPredicate(ostream);
|
||||
ostream << ")." << std::endl;
|
||||
});
|
||||
}
|
||||
|
@ -136,9 +136,10 @@ void Value::printAsASP(std::ostream &ostream) const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Value::printAsASPPredicateBody(std::ostream &ostream) const
|
||||
void Value::printAsASPPredicate(std::ostream &ostream) const
|
||||
{
|
||||
ostream << utils::escapeASP(m_name) << ", " << (m_sign == Sign::Positive ? "true" : "false");
|
||||
ostream << "value(" << utils::escapeASP(m_name) << ", "
|
||||
<< (m_sign == Sign::Positive ? "true" : "false") << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -50,9 +50,9 @@ Variable Variable::fromSAS(std::istream &istream)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::printNameAsASP(std::ostream &ostream) const
|
||||
void Variable::printNameAsASPPredicate(std::ostream &ostream) const
|
||||
{
|
||||
ostream << utils::escapeASP(m_name);
|
||||
ostream << "variable(" << utils::escapeASP(m_name) << ")";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user