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.
|
#program base.
|
||||||
|
|
||||||
% Establish initial state
|
% Establish initial state
|
||||||
holds(F, 0) :- initialState(F).
|
holds(Var, Val, 0) :- initialState(Var, Val).
|
||||||
|
|
||||||
#program step(t).
|
#program step(t).
|
||||||
|
|
||||||
% Perform actions
|
% Perform actions
|
||||||
1 {occurs(A, t) : action(A)} 1.
|
1 {occurs(action(A), t) : action(A)} 1.
|
||||||
|
|
||||||
% Check preconditions
|
% Check preconditions
|
||||||
:- occurs(A, t), precondition(A, F, true), not holds(F, t - 1).
|
:- occurs(A, t), precondition(A, Var, Val), not holds(Var, Val, t - 1).
|
||||||
:- occurs(A, t), precondition(A, F, false), holds(F, t - 1).
|
|
||||||
|
|
||||||
% Apply effects
|
% Apply effects
|
||||||
holds(F, t) :- occurs(A, t), postcondition(A, F, true), action(A).
|
caused(Var, Val, t) :- occurs(A, t), postcondition(A, Var, Val).
|
||||||
deleted(F, t) :- occurs(A, t), postcondition(A, F, false), action(A).
|
modified(Var, t) :- caused(Var, Val, t).
|
||||||
holds(F, t) :- holds(F, t - 1), not deleted(F, t).
|
|
||||||
|
|
||||||
% Enforce mutexes
|
holds(Var, Val, t) :- caused(Var, Val, t).
|
||||||
deleted(F2, t) :- mutex(F1, true, F2, true), holds(F1, t).
|
holds(Var, Val, t) :- holds(Var, Val, t - 1), not modified(Var, 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).
|
|
||||||
|
|
||||||
#program check(t).
|
#program check(t).
|
||||||
|
|
||||||
% Verify that goal is met
|
% Verify that goal is met
|
||||||
:- query(t), goal(F, true), not holds(F, t).
|
:- query(t), goal(Var, Val), not holds(Var, Val, t).
|
||||||
:- query(t), goal(F, false), holds(F, t).
|
|
||||||
|
|
||||||
#show query/1.
|
#show query/1.
|
||||||
#show occurs/2.
|
#show occurs/2.
|
||||||
|
@ -34,6 +34,8 @@ class Operator
|
|||||||
static Operator fromSAS(std::istream &istream, const Variables &variables);
|
static Operator fromSAS(std::istream &istream, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void printPredicateAsASP(std::ostream &ostream) const;
|
||||||
|
|
||||||
const Predicate &predicate() const;
|
const Predicate &predicate() const;
|
||||||
const Conditions &preconditions() const;
|
const Conditions &preconditions() const;
|
||||||
const Effects &effects() const;
|
const Effects &effects() const;
|
||||||
|
@ -44,7 +44,7 @@ struct Value
|
|||||||
|
|
||||||
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 printAsASPPredicateBody(std::ostream &ostream) const;
|
void printAsASPPredicate(std::ostream &ostream) const;
|
||||||
|
|
||||||
Sign sign() const;
|
Sign sign() const;
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
|
@ -30,7 +30,7 @@ class Variable
|
|||||||
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables);
|
static const Variable &referenceFromSAS(std::istream &istream, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printNameAsASP(std::ostream &ostream) const;
|
void printNameAsASPPredicate(std::ostream &ostream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
int axiomLayer() 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
|
const Predicate &Operator::predicate() const
|
||||||
{
|
{
|
||||||
return m_predicate;
|
return m_predicate;
|
||||||
|
@ -74,9 +74,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "initialState(";
|
ostream << "initialState(";
|
||||||
fact.variable().printNameAsASP(ostream);
|
fact.variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
fact.value().printAsASPPredicateBody(ostream);
|
fact.value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "goal(";
|
ostream << "goal(";
|
||||||
fact.variable().printNameAsASP(ostream);
|
fact.variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
fact.value().printAsASPPredicateBody(ostream);
|
fact.value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -110,20 +110,22 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
|
|
||||||
BOOST_ASSERT(!values.empty());
|
BOOST_ASSERT(!values.empty());
|
||||||
|
|
||||||
ostream << std::endl << "variable(";
|
ostream << std::endl;
|
||||||
variable.printNameAsASP(ostream);
|
variable.printNameAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << "." << std::endl;
|
||||||
|
|
||||||
std::for_each(values.cbegin(), values.cend(),
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
[&](const auto &value)
|
[&](const auto &value)
|
||||||
{
|
{
|
||||||
ostream << "variableValue(";
|
ostream << "contains(";
|
||||||
variable.printNameAsASP(ostream);
|
variable.printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
|
|
||||||
if (value == Value::None)
|
if (value == Value::None)
|
||||||
ostream << "noneValue";
|
ostream << "noneValue";
|
||||||
else
|
else
|
||||||
value.printAsASPPredicateBody(ostream);
|
value.printAsASPPredicate(ostream);
|
||||||
|
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -136,9 +138,9 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
ostream << std::endl << "action(";
|
ostream << std::endl;
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.printPredicateAsASP(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << "." << std::endl;
|
||||||
|
|
||||||
const auto &preconditions = operator_.preconditions();
|
const auto &preconditions = operator_.preconditions();
|
||||||
|
|
||||||
@ -149,11 +151,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "precondition(";
|
ostream << "precondition(";
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.printPredicateAsASP(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
precondition.variable().printNameAsASP(ostream);
|
precondition.variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
precondition.value().printAsASPPredicateBody(ostream);
|
precondition.value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -166,11 +168,11 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ostream << "postcondition(";
|
ostream << "postcondition(";
|
||||||
operator_.predicate().printAsASP(ostream);
|
operator_.printPredicateAsASP(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
effect.postcondition().variable().printNameAsASP(ostream);
|
effect.postcondition().variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
effect.postcondition().value().printAsASPPredicateBody(ostream);
|
effect.postcondition().value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
ostream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -191,10 +193,10 @@ void TranslatorASP::translate(std::ostream &ostream) const
|
|||||||
std::for_each(facts.cbegin(), facts.cend(),
|
std::for_each(facts.cbegin(), facts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
ostream << "mutexGroupFact(mutexGroup" << i << ", ";
|
ostream << "contains(mutexGroup(mutexGroup" << i << "), ";
|
||||||
fact.variable().printNameAsASP(ostream);
|
fact.variable().printNameAsASPPredicate(ostream);
|
||||||
ostream << ", ";
|
ostream << ", ";
|
||||||
fact.value().printAsASPPredicateBody(ostream);
|
fact.value().printAsASPPredicate(ostream);
|
||||||
ostream << ")." << std::endl;
|
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