Colorized output for SAS translator.
This commit is contained in:
parent
1e21457efb
commit
f7cd24b67a
@ -10,6 +10,11 @@ Features:
|
|||||||
* automatic language detection for PDDL and SAS
|
* automatic language detection for PDDL and SAS
|
||||||
* new command-line option `--language` to explicitly specify input language
|
* new command-line option `--language` to explicitly specify input language
|
||||||
* new command-line option `--warning-level` to treat warnings as errors or to ignore warnings
|
* new command-line option `--warning-level` to treat warnings as errors or to ignore warnings
|
||||||
|
* supports colorized output
|
||||||
|
|
||||||
|
Bug Fixes:
|
||||||
|
|
||||||
|
* fixes bug in translation of SAS axiom rules
|
||||||
|
|
||||||
## 3.0.0 (2016-05-24)
|
## 3.0.0 (2016-05-24)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <plasp/pddl/TranslatorASP.h>
|
#include <plasp/pddl/TranslatorASP.h>
|
||||||
#include <plasp/sas/Description.h>
|
#include <plasp/sas/Description.h>
|
||||||
#include <plasp/sas/TranslatorASP.h>
|
#include <plasp/sas/TranslatorASP.h>
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
#include <plasp/utils/TranslatorException.h>
|
#include <plasp/utils/TranslatorException.h>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -123,8 +124,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else if (language == plasp::Language::Type::SAS)
|
else if (language == plasp::Language::Type::SAS)
|
||||||
{
|
{
|
||||||
|
plasp::utils::LogStream logStream(plasp::utils::StandardStream::Out);
|
||||||
const auto description = plasp::sas::Description::fromParser(std::move(parser));
|
const auto description = plasp::sas::Description::fromParser(std::move(parser));
|
||||||
const auto translator = plasp::sas::TranslatorASP(description, std::cout);
|
const auto translator = plasp::sas::TranslatorASP(description, logStream);
|
||||||
translator.translate();
|
translator.translate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::ostream &operator <<(std::ostream &ostream, const Description &description);
|
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <plasp/sas/Effect.h>
|
#include <plasp/sas/Effect.h>
|
||||||
#include <plasp/sas/Predicate.h>
|
#include <plasp/sas/Predicate.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/utils/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -35,7 +36,7 @@ class Operator
|
|||||||
static Operator fromSAS(utils::Parser &parser, const Variables &variables);
|
static Operator fromSAS(utils::Parser &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printPredicateAsASP(std::ostream &ostream) const;
|
void printPredicateAsASP(utils::LogStream &ostream) const;
|
||||||
|
|
||||||
const Predicate &predicate() const;
|
const Predicate &predicate() const;
|
||||||
const Conditions &preconditions() const;
|
const Conditions &preconditions() const;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/utils/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -26,8 +27,8 @@ class Predicate
|
|||||||
using Arguments = std::vector<std::string>;
|
using Arguments = std::vector<std::string>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printAsSAS(std::ostream &ostream) const;
|
void printAsSAS(utils::LogStream &outputStream) const;
|
||||||
void printAsASP(std::ostream &ostream) const;
|
void printAsASP(utils::LogStream &outputStream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
const Arguments &arguments() const;
|
const Arguments &arguments() const;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
||||||
|
|
||||||
#include <plasp/sas/Description.h>
|
#include <plasp/sas/Description.h>
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ namespace sas
|
|||||||
class TranslatorASP
|
class TranslatorASP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TranslatorASP(const Description &description, std::ostream &ostream);
|
explicit TranslatorASP(const Description &description, utils::LogStream &outputStream);
|
||||||
|
|
||||||
void translate() const;
|
void translate() const;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ class TranslatorASP
|
|||||||
void translateAxiomRules() const;
|
void translateAxiomRules() const;
|
||||||
|
|
||||||
const Description &m_description;
|
const Description &m_description;
|
||||||
std::ostream &m_ostream;
|
utils::LogStream &m_outputStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/utils/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -44,9 +45,9 @@ struct Value
|
|||||||
public:
|
public:
|
||||||
Value negated() const;
|
Value negated() const;
|
||||||
|
|
||||||
void printAsSAS(std::ostream &ostream) const;
|
void printAsSAS(utils::LogStream &outputStream) const;
|
||||||
void printAsASP(std::ostream &ostream) const;
|
void printAsASP(utils::LogStream &outputStream) const;
|
||||||
void printAsASPPredicate(std::ostream &ostream) const;
|
void printAsASPPredicate(utils::LogStream &outputStream) const;
|
||||||
|
|
||||||
Sign sign() const;
|
Sign sign() const;
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
|
#include <plasp/utils/LogStream.h>
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/utils/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -31,7 +32,7 @@ class Variable
|
|||||||
static const Variable &referenceFromSAS(utils::Parser &parser, const Variables &variables);
|
static const Variable &referenceFromSAS(utils::Parser &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printNameAsASPPredicate(std::ostream &ostream) const;
|
void printNameAsASPPredicate(utils::LogStream &outputStream) const;
|
||||||
|
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
int axiomLayer() const;
|
int axiomLayer() const;
|
||||||
|
@ -13,7 +13,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::ostream &operator <<(std::ostream &ostream, const Description &description)
|
utils::LogStream &operator<<(utils::LogStream &ostream, const Description &description)
|
||||||
{
|
{
|
||||||
// Metric section
|
// Metric section
|
||||||
ostream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
ostream << "uses action costs: " << (description.usesActionCosts() ? "yes" : "no") << std::endl;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <plasp/sas/VariableTransition.h>
|
#include <plasp/sas/VariableTransition.h>
|
||||||
|
#include <plasp/utils/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -45,11 +46,11 @@ Operator Operator::fromSAS(utils::Parser &parser, const Variables &variables)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Operator::printPredicateAsASP(std::ostream &ostream) const
|
void Operator::printPredicateAsASP(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
ostream << "action(";
|
outputStream << utils::Keyword("action") << "(";
|
||||||
m_predicate.printAsASP(ostream);
|
m_predicate.printAsASP(outputStream);
|
||||||
ostream << ")";
|
outputStream << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -68,43 +68,43 @@ const Predicate::Arguments &Predicate::arguments() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Predicate::printAsSAS(std::ostream &ostream) const
|
void Predicate::printAsSAS(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
if (m_arguments.empty())
|
if (m_arguments.empty())
|
||||||
{
|
{
|
||||||
ostream << m_name;
|
outputStream << m_name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
ostream << " ";
|
outputStream << " ";
|
||||||
|
|
||||||
ostream << m_arguments[i];
|
outputStream << m_arguments[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Predicate::printAsASP(std::ostream &ostream) const
|
void Predicate::printAsASP(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
if (m_arguments.empty())
|
if (m_arguments.empty())
|
||||||
{
|
{
|
||||||
ostream << utils::escapeASP(m_name);
|
outputStream << utils::escapeASP(m_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream << utils::escapeASP(m_name) << "(";
|
outputStream << utils::escapeASP(m_name) << "(";
|
||||||
|
|
||||||
for (size_t i = 0; i < m_arguments.size(); i++)
|
for (size_t i = 0; i < m_arguments.size(); i++)
|
||||||
{
|
{
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
ostream << ", ";
|
outputStream << ", ";
|
||||||
|
|
||||||
ostream << utils::escapeASP(m_arguments[i]);
|
outputStream << utils::escapeASP(m_arguments[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream << ")";
|
outputStream << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <plasp/sas/TranslatorASP.h>
|
#include <plasp/sas/TranslatorASP.h>
|
||||||
|
|
||||||
|
#include <plasp/utils/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -11,9 +13,9 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TranslatorASP::TranslatorASP(const Description &description, std::ostream &ostream)
|
TranslatorASP::TranslatorASP(const Description &description, utils::LogStream &ostream)
|
||||||
: m_description(description),
|
: m_description(description),
|
||||||
m_ostream(ostream)
|
m_outputStream(ostream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,67 +36,67 @@ void TranslatorASP::translate() const
|
|||||||
|
|
||||||
void TranslatorASP::translateRequirements() const
|
void TranslatorASP::translateRequirements() const
|
||||||
{
|
{
|
||||||
m_ostream << "% feature requirements" << std::endl;
|
m_outputStream << utils::Heading2("feature requirements") << std::endl;
|
||||||
|
|
||||||
if (m_description.usesActionCosts())
|
if (m_description.usesActionCosts())
|
||||||
m_ostream << "requiresFeature(actionCosts)." << std::endl;
|
m_outputStream << utils::Keyword("requiresFeature") << "(actionCosts)." << std::endl;
|
||||||
|
|
||||||
if (m_description.usesAxiomRules())
|
if (m_description.usesAxiomRules())
|
||||||
m_ostream << "requiresFeature(axiomRules)." << std::endl;
|
m_outputStream << utils::Keyword("requiresFeature") << "(axiomRules)." << std::endl;
|
||||||
|
|
||||||
if (m_description.usesConditionalEffects())
|
if (m_description.usesConditionalEffects())
|
||||||
m_ostream << "requiresFeature(conditionalEffects)." << std::endl;
|
m_outputStream << utils::Keyword("requiresFeature") << "(conditionalEffects)." << std::endl;
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateInitialState() const
|
void TranslatorASP::translateInitialState() const
|
||||||
{
|
{
|
||||||
m_ostream << "% initial state" << std::endl;
|
m_outputStream << utils::Heading2("initial state") << std::endl;
|
||||||
|
|
||||||
const auto &initialStateFacts = m_description.initialState().facts();
|
const auto &initialStateFacts = m_description.initialState().facts();
|
||||||
|
|
||||||
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_ostream << "initialState(";
|
m_outputStream << utils::Keyword("initialState") << "(";
|
||||||
fact.variable().printNameAsASPPredicate(m_ostream);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_ostream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateGoal() const
|
void TranslatorASP::translateGoal() const
|
||||||
{
|
{
|
||||||
m_ostream << "% goal" << std::endl;
|
m_outputStream << utils::Heading2("goal") << std::endl;
|
||||||
|
|
||||||
const auto &goalFacts = m_description.goal().facts();
|
const auto &goalFacts = m_description.goal().facts();
|
||||||
|
|
||||||
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
std::for_each(goalFacts.cbegin(), goalFacts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_ostream << "goal(";
|
m_outputStream << utils::Keyword("goal") << "(";
|
||||||
fact.variable().printNameAsASPPredicate(m_ostream);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_ostream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateVariables() const
|
void TranslatorASP::translateVariables() const
|
||||||
{
|
{
|
||||||
m_ostream << "% variables";
|
m_outputStream << utils::Heading2("variables");
|
||||||
|
|
||||||
const auto &variables = m_description.variables();
|
const auto &variables = m_description.variables();
|
||||||
|
|
||||||
@ -105,51 +107,51 @@ void TranslatorASP::translateVariables() const
|
|||||||
|
|
||||||
BOOST_ASSERT(!values.empty());
|
BOOST_ASSERT(!values.empty());
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
variable.printNameAsASPPredicate(m_ostream);
|
variable.printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << "." << std::endl;
|
m_outputStream << "." << std::endl;
|
||||||
|
|
||||||
std::for_each(values.cbegin(), values.cend(),
|
std::for_each(values.cbegin(), values.cend(),
|
||||||
[&](const auto &value)
|
[&](const auto &value)
|
||||||
{
|
{
|
||||||
m_ostream << "contains(";
|
m_outputStream << utils::Keyword("contains") << "(";
|
||||||
variable.printNameAsASPPredicate(m_ostream);
|
variable.printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
value.printAsASPPredicate(m_ostream);
|
value.printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateActions() const
|
void TranslatorASP::translateActions() const
|
||||||
{
|
{
|
||||||
m_ostream << "% actions";
|
m_outputStream << utils::Heading2("actions");
|
||||||
|
|
||||||
const auto &operators = m_description.operators();
|
const auto &operators = m_description.operators();
|
||||||
|
|
||||||
std::for_each(operators.cbegin(), operators.cend(),
|
std::for_each(operators.cbegin(), operators.cend(),
|
||||||
[&](const auto &operator_)
|
[&](const auto &operator_)
|
||||||
{
|
{
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
operator_.printPredicateAsASP(m_ostream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_ostream << "." << std::endl;
|
m_outputStream << "." << std::endl;
|
||||||
|
|
||||||
const auto &preconditions = operator_.preconditions();
|
const auto &preconditions = operator_.preconditions();
|
||||||
|
|
||||||
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
std::for_each(preconditions.cbegin(), preconditions.cend(),
|
||||||
[&](const auto &precondition)
|
[&](const auto &precondition)
|
||||||
{
|
{
|
||||||
m_ostream << "precondition(";
|
m_outputStream << utils::Keyword("precondition") << "(";
|
||||||
operator_.printPredicateAsASP(m_ostream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
precondition.variable().printNameAsASPPredicate(m_ostream);
|
precondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
precondition.value().printAsASPPredicate(m_ostream);
|
precondition.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto &effects = operator_.effects();
|
const auto &effects = operator_.effects();
|
||||||
@ -164,39 +166,39 @@ void TranslatorASP::translateActions() const
|
|||||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||||
[&](const auto &condition)
|
[&](const auto &condition)
|
||||||
{
|
{
|
||||||
m_ostream << "effectCondition(";
|
m_outputStream << utils::Keyword("effectCondition") << "(";
|
||||||
operator_.printPredicateAsASP(m_ostream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_ostream << ", effect(" << currentEffectID << "), ";
|
m_outputStream << ", " << utils::Keyword("effect") << "(" << currentEffectID << "), ";
|
||||||
condition.variable().printNameAsASPPredicate(m_ostream);
|
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
condition.value().printAsASPPredicate(m_ostream);
|
condition.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << "postcondition(";
|
m_outputStream << utils::Keyword("postcondition") << "(";
|
||||||
operator_.printPredicateAsASP(m_ostream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_ostream << ", effect(" << currentEffectID << "), ";
|
m_outputStream << ", " << utils::Keyword("effect") << "(" << currentEffectID << "), ";
|
||||||
effect.postcondition().variable().printNameAsASPPredicate(m_ostream);
|
effect.postcondition().variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
effect.postcondition().value().printAsASPPredicate(m_ostream);
|
effect.postcondition().value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
|
|
||||||
currentEffectID++;
|
currentEffectID++;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << "costs(";
|
m_outputStream << utils::Keyword("costs") << "(";
|
||||||
operator_.printPredicateAsASP(m_ostream);
|
operator_.printPredicateAsASP(m_outputStream);
|
||||||
m_ostream << ", " << operator_.costs() << ")." << std::endl;
|
m_outputStream << ", " << operator_.costs() << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateMutexes() const
|
void TranslatorASP::translateMutexes() const
|
||||||
{
|
{
|
||||||
m_ostream << "% mutex groups";
|
m_outputStream << utils::Heading2("mutex groups");
|
||||||
|
|
||||||
const auto &mutexGroups = m_description.mutexGroups();
|
const auto &mutexGroups = m_description.mutexGroups();
|
||||||
|
|
||||||
@ -208,18 +210,18 @@ void TranslatorASP::translateMutexes() const
|
|||||||
const auto mutexGroupID = std::to_string(currentMutexGroupID);
|
const auto mutexGroupID = std::to_string(currentMutexGroupID);
|
||||||
currentMutexGroupID++;
|
currentMutexGroupID++;
|
||||||
|
|
||||||
m_ostream << std::endl << "mutexGroup(" << mutexGroupID << ")." << std::endl;
|
m_outputStream << std::endl << utils::Keyword("mutexGroup") << "(" << mutexGroupID << ")." << std::endl;
|
||||||
|
|
||||||
const auto &facts = mutexGroup.facts();
|
const auto &facts = mutexGroup.facts();
|
||||||
|
|
||||||
std::for_each(facts.cbegin(), facts.cend(),
|
std::for_each(facts.cbegin(), facts.cend(),
|
||||||
[&](const auto &fact)
|
[&](const auto &fact)
|
||||||
{
|
{
|
||||||
m_ostream << "contains(mutexGroup(" << mutexGroupID << "), ";
|
m_outputStream << utils::Keyword("contains") << "(" << utils::Keyword("mutexGroup") << "(" << mutexGroupID << "), ";
|
||||||
fact.variable().printNameAsASPPredicate(m_ostream);
|
fact.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
fact.value().printAsASPPredicate(m_ostream);
|
fact.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -231,8 +233,8 @@ void TranslatorASP::translateAxiomRules() const
|
|||||||
if (!m_description.usesActionCosts())
|
if (!m_description.usesActionCosts())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_ostream << std::endl;
|
m_outputStream << std::endl;
|
||||||
m_ostream << "% axiom rules";
|
m_outputStream << utils::Heading2("axiom rules");
|
||||||
|
|
||||||
const auto &axiomRules = m_description.axiomRules();
|
const auto &axiomRules = m_description.axiomRules();
|
||||||
|
|
||||||
@ -244,27 +246,27 @@ void TranslatorASP::translateAxiomRules() const
|
|||||||
const auto axiomRuleID = std::to_string(currentAxiomRuleID);
|
const auto axiomRuleID = std::to_string(currentAxiomRuleID);
|
||||||
currentAxiomRuleID++;
|
currentAxiomRuleID++;
|
||||||
|
|
||||||
m_ostream << std::endl << "axiomRule(" << axiomRuleID << ")." << std::endl;
|
m_outputStream << std::endl << utils::Keyword("axiomRule") << "(" << axiomRuleID << ")." << std::endl;
|
||||||
|
|
||||||
const auto &conditions = axiomRule.conditions();
|
const auto &conditions = axiomRule.conditions();
|
||||||
|
|
||||||
std::for_each(conditions.cbegin(), conditions.cend(),
|
std::for_each(conditions.cbegin(), conditions.cend(),
|
||||||
[&](const auto &condition)
|
[&](const auto &condition)
|
||||||
{
|
{
|
||||||
m_ostream << "condition(axiomRule(" << axiomRuleID << "), ";
|
m_outputStream << utils::Keyword("condition") << "(" << utils::Keyword("axiomRule") << "(" << axiomRuleID << "), ";
|
||||||
condition.variable().printNameAsASPPredicate(m_ostream);
|
condition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
condition.value().printAsASPPredicate(m_ostream);
|
condition.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto &postcondition = axiomRule.postcondition();
|
const auto &postcondition = axiomRule.postcondition();
|
||||||
|
|
||||||
m_ostream << "postcondition(axiomRule(axiomRule" << axiomRuleID << "), ";
|
m_outputStream << utils::Keyword("postcondition") << "(" << utils::Keyword("axiomRule") << "(" << axiomRuleID << "), ";
|
||||||
postcondition.variable().printNameAsASPPredicate(m_ostream);
|
postcondition.variable().printNameAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ", ";
|
m_outputStream << ", ";
|
||||||
postcondition.value().printAsASPPredicate(m_ostream);
|
postcondition.value().printAsASPPredicate(m_outputStream);
|
||||||
m_ostream << ")." << std::endl;
|
m_outputStream << ")." << std::endl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
#include <plasp/utils/Formatting.h>
|
||||||
#include <plasp/utils/IO.h>
|
#include <plasp/utils/IO.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/utils/ParserException.h>
|
||||||
|
|
||||||
@ -127,42 +128,42 @@ const std::string &Value::name() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Value::printAsASP(std::ostream &ostream) const
|
void Value::printAsASP(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
if (m_sign == Value::Sign::Negative)
|
if (m_sign == Value::Sign::Negative)
|
||||||
ostream << "not ";
|
outputStream << utils::Keyword("not") << " ";
|
||||||
|
|
||||||
ostream << utils::escapeASP(m_name);
|
outputStream << utils::escapeASP(m_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Value::printAsASPPredicate(std::ostream &ostream) const
|
void Value::printAsASPPredicate(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
// TODO: do not compare by value
|
// TODO: do not compare by value
|
||||||
if (*this == Value::None)
|
if (*this == Value::None)
|
||||||
{
|
{
|
||||||
ostream << "value(none)";
|
outputStream << utils::Keyword("value") << "(" << utils::Keyword("none") << ")";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream << "value(" << utils::escapeASP(m_name) << ", "
|
outputStream << utils::Keyword("value") << "(" << utils::escapeASP(m_name) << ", "
|
||||||
<< (m_sign == Sign::Positive ? "true" : "false") << ")";
|
<< (m_sign == Sign::Positive ? utils::Keyword("true") : utils::Keyword("false")) << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Value::printAsSAS(std::ostream &ostream) const
|
void Value::printAsSAS(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
if (m_sign == Value::Sign::Positive)
|
if (m_sign == Value::Sign::Positive)
|
||||||
ostream << "Atom ";
|
outputStream << "Atom ";
|
||||||
else
|
else
|
||||||
ostream << "NegatedAtom ";
|
outputStream << "NegatedAtom ";
|
||||||
|
|
||||||
ostream << m_name;
|
outputStream << m_name;
|
||||||
|
|
||||||
if (!m_hasArguments)
|
if (!m_hasArguments)
|
||||||
ostream << "()";
|
outputStream << "()";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <plasp/utils/Formatting.h>
|
||||||
#include <plasp/utils/IO.h>
|
#include <plasp/utils/IO.h>
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/utils/ParserException.h>
|
||||||
|
|
||||||
@ -51,9 +52,9 @@ Variable Variable::fromSAS(utils::Parser &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Variable::printNameAsASPPredicate(std::ostream &ostream) const
|
void Variable::printNameAsASPPredicate(utils::LogStream &outputStream) const
|
||||||
{
|
{
|
||||||
ostream << "variable(" << utils::escapeASP(m_name) << ")";
|
outputStream << utils::Keyword("variable") << "(" << utils::escapeASP(m_name) << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user