Started implementing PDDL normalization.
This commit is contained in:
parent
e4f4b5e066
commit
9d1a8f4c0f
@ -11,6 +11,8 @@
|
|||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/AST.h>
|
||||||
#include <pddlparse/Exception.h>
|
#include <pddlparse/Exception.h>
|
||||||
#include <pddlparse/Mode.h>
|
#include <pddlparse/Mode.h>
|
||||||
|
#include <pddlparse/Normalize.h>
|
||||||
|
#include <pddlparse/NormalizedASTOutput.h>
|
||||||
#include <pddlparse/Parse.h>
|
#include <pddlparse/Parse.h>
|
||||||
|
|
||||||
#include <plasp/LanguageDetection.h>
|
#include <plasp/LanguageDetection.h>
|
||||||
@ -187,7 +189,8 @@ int main(int argc, char **argv)
|
|||||||
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
auto context = pddl::Context(std::move(tokenizer), logWarning);
|
||||||
context.mode = parsingMode;
|
context.mode = parsingMode;
|
||||||
auto description = pddl::parseDescription(context);
|
auto description = pddl::parseDescription(context);
|
||||||
const auto translator = plasp::pddl::TranslatorASP(std::move(description), logger.outputStream());
|
auto normalizedDescription = pddl::normalize(std::move(description));
|
||||||
|
const auto translator = plasp::pddl::TranslatorASP(std::move(normalizedDescription), logger.outputStream());
|
||||||
translator.translate();
|
translator.translate();
|
||||||
}
|
}
|
||||||
else if (language == plasp::Language::Type::SAS)
|
else if (language == plasp::Language::Type::SAS)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/ColorStream.h>
|
#include <colorlog/ColorStream.h>
|
||||||
|
|
||||||
#include <pddlparse/ASTForward.h>
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
#include <pddlparse/Parse.h>
|
#include <pddlparse/Parse.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
@ -20,7 +20,7 @@ namespace pddl
|
|||||||
class TranslatorASP
|
class TranslatorASP
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TranslatorASP(const ::pddl::ast::Description &description, colorlog::ColorStream &outputStream);
|
explicit TranslatorASP(const ::pddl::normalizedAST::Description &description, colorlog::ColorStream &outputStream);
|
||||||
|
|
||||||
void translate() const;
|
void translate() const;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ class TranslatorASP
|
|||||||
void translateGoal() const;
|
void translateGoal() const;
|
||||||
void translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const;
|
void translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const;
|
||||||
|
|
||||||
const ::pddl::ast::Description &m_description;
|
const ::pddl::normalizedAST::Description &m_description;
|
||||||
colorlog::ColorStream &m_outputStream;
|
colorlog::ColorStream &m_outputStream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ namespace pddl
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename PrintObjectName>
|
template<typename PrintObjectName>
|
||||||
inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::ast::Effect &effect, const std::string &objectType, PrintObjectName printObjectName)
|
inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Effect &effect, const std::string &objectType, PrintObjectName printObjectName)
|
||||||
{
|
{
|
||||||
const auto handleUnsupported =
|
const auto handleUnsupported =
|
||||||
[](const auto &)
|
[](const auto &)
|
||||||
@ -31,7 +31,7 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::a
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto handlePredicate =
|
const auto handlePredicate =
|
||||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||||
{
|
{
|
||||||
outputStream << std::endl << colorlog::Function("postcondition") << "(";
|
outputStream << std::endl << colorlog::Function("postcondition") << "(";
|
||||||
printObjectName();
|
printObjectName();
|
||||||
@ -46,24 +46,24 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::a
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAtomicFormula =
|
const auto handleAtomicFormula =
|
||||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||||
{
|
{
|
||||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
atomicFormula.match(handlePredicate, handleUnsupported);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleNot =
|
const auto handleNot =
|
||||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Effect> ¬_)
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::Effect> ¬_)
|
||||||
{
|
{
|
||||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
if (!not_->argument.is<::pddl::normalizedAST::AtomicFormula>() || !not_->argument.get<::pddl::normalizedAST::AtomicFormula>().is<::pddl::normalizedAST::PredicatePointer>())
|
||||||
handleUnsupported(not_);
|
handleUnsupported(not_);
|
||||||
|
|
||||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
const auto &predicate = not_->argument.get<::pddl::normalizedAST::AtomicFormula>().get<::pddl::normalizedAST::PredicatePointer>();
|
||||||
|
|
||||||
handlePredicate(predicate, false);
|
handlePredicate(predicate, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAnd =
|
const auto handleAnd =
|
||||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Effect> &and_)
|
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Effect> &and_)
|
||||||
{
|
{
|
||||||
for (const auto &argument : and_->arguments)
|
for (const auto &argument : and_->arguments)
|
||||||
translateEffect(outputStream, argument, objectType, printObjectName);
|
translateEffect(outputStream, argument, objectType, printObjectName);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
|
|
||||||
@ -21,16 +21,10 @@ namespace pddl
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::ast::Goal &goal)
|
inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Goal &goal)
|
||||||
{
|
{
|
||||||
const auto handleUnsupported =
|
|
||||||
[](const auto &)
|
|
||||||
{
|
|
||||||
throw TranslatorException("only “and” expressions and (negated) predicates supported as goals currently");
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto handlePredicate =
|
const auto handlePredicate =
|
||||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||||
{
|
{
|
||||||
outputStream << std::endl << colorlog::Function("goal") << "(";
|
outputStream << std::endl << colorlog::Function("goal") << "(";
|
||||||
// TODO: assert that goal is variable-free
|
// TODO: assert that goal is variable-free
|
||||||
@ -38,31 +32,54 @@ inline void translateGoal(colorlog::ColorStream &outputStream, const ::pddl::ast
|
|||||||
outputStream << ").";
|
outputStream << ").";
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAtomicFormula =
|
const auto handleNegatedPredicate =
|
||||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||||
{
|
{
|
||||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto handleNot =
|
|
||||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Goal> ¬_)
|
|
||||||
{
|
|
||||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
|
||||||
handleUnsupported(not_);
|
|
||||||
|
|
||||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
|
||||||
|
|
||||||
handlePredicate(predicate, false);
|
handlePredicate(predicate, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAnd =
|
const auto handleDerivedPredicate =
|
||||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Goal> &and_)
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||||
{
|
{
|
||||||
for (const auto &argument : and_->arguments)
|
outputStream << std::endl << colorlog::Function("goal") << "(";
|
||||||
translateGoal(outputStream, argument);
|
// TODO: assert that goal is variable-free
|
||||||
|
// TODO: implement
|
||||||
|
//translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||||
|
outputStream << ").";
|
||||||
};
|
};
|
||||||
|
|
||||||
goal.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
const auto handleNegatedDerivedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||||
|
{
|
||||||
|
handleDerivedPredicate(derivedPredicate, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||||
|
{
|
||||||
|
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNot =
|
||||||
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||||
|
{
|
||||||
|
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleLiteral =
|
||||||
|
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||||
|
{
|
||||||
|
literal.match(handleAtomicFormula, handleNot);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAnd =
|
||||||
|
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||||
|
{
|
||||||
|
for (const auto &argument : and_->arguments)
|
||||||
|
handleLiteral(argument);
|
||||||
|
};
|
||||||
|
|
||||||
|
goal.match(handleLiteral, handleAnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
|
|
||||||
@ -22,16 +22,10 @@ namespace pddl
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename PrintObjectName>
|
template<typename PrintObjectName>
|
||||||
inline void translatePrecondition(colorlog::ColorStream &outputStream, const ::pddl::ast::Precondition &precondition, const std::string &objectType, PrintObjectName printObjectName)
|
inline void translatePrecondition(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Precondition &precondition, const std::string &objectType, PrintObjectName printObjectName)
|
||||||
{
|
{
|
||||||
const auto handleUnsupported =
|
|
||||||
[](const auto &)
|
|
||||||
{
|
|
||||||
throw TranslatorException("only “and” expressions and (negated) predicates supported as action preconditions currently");
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto handlePredicate =
|
const auto handlePredicate =
|
||||||
[&](const ::pddl::ast::PredicatePointer &predicate, bool isPositive = true)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||||
{
|
{
|
||||||
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||||
printObjectName();
|
printObjectName();
|
||||||
@ -42,31 +36,57 @@ inline void translatePrecondition(colorlog::ColorStream &outputStream, const ::p
|
|||||||
outputStream << ").";
|
outputStream << ").";
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAtomicFormula =
|
const auto handleNegatedPredicate =
|
||||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||||
{
|
{
|
||||||
atomicFormula.match(handlePredicate, handleUnsupported);
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto handleNot =
|
|
||||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::Precondition> ¬_)
|
|
||||||
{
|
|
||||||
if (!not_->argument.is<::pddl::ast::AtomicFormula>() || !not_->argument.get<::pddl::ast::AtomicFormula>().is<::pddl::ast::PredicatePointer>())
|
|
||||||
handleUnsupported(not_);
|
|
||||||
|
|
||||||
const auto &predicate = not_->argument.get<::pddl::ast::AtomicFormula>().get<::pddl::ast::PredicatePointer>();
|
|
||||||
|
|
||||||
handlePredicate(predicate, false);
|
handlePredicate(predicate, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAnd =
|
const auto handleDerivedPredicate =
|
||||||
[&](const ::pddl::ast::AndPointer<::pddl::ast::Precondition> &and_)
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||||
{
|
{
|
||||||
for (const auto &argument : and_->arguments)
|
outputStream << std::endl << colorlog::Function("precondition") << "(";
|
||||||
translatePrecondition(outputStream, argument, objectType, printObjectName);
|
printObjectName();
|
||||||
|
outputStream << ", ";
|
||||||
|
// TODO: implement
|
||||||
|
/*translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||||
|
outputStream << ") :- " << output::Function(objectType.c_str()) << "(";
|
||||||
|
printObjectName();
|
||||||
|
outputStream << ").";*/
|
||||||
};
|
};
|
||||||
|
|
||||||
precondition.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
const auto handleNegatedDerivedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||||
|
{
|
||||||
|
handleDerivedPredicate(derivedPredicate, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||||
|
{
|
||||||
|
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNot =
|
||||||
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||||
|
{
|
||||||
|
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleLiteral =
|
||||||
|
[&](const ::pddl::normalizedAST::Literal &literal)
|
||||||
|
{
|
||||||
|
literal.match(handleAtomicFormula, handleNot);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAnd =
|
||||||
|
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Literal> &and_)
|
||||||
|
{
|
||||||
|
for (const auto &argument : and_->arguments)
|
||||||
|
handleLiteral(argument);
|
||||||
|
};
|
||||||
|
|
||||||
|
precondition.match(handleLiteral, handleAnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
#include <pddlparse/Parse.h>
|
#include <pddlparse/Parse.h>
|
||||||
|
|
||||||
#include <plasp/pddl/translation/Primitives.h>
|
#include <plasp/pddl/translation/Primitives.h>
|
||||||
@ -20,12 +20,12 @@ namespace pddl
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate);
|
void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate);
|
||||||
void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration);
|
void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate)
|
inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate)
|
||||||
{
|
{
|
||||||
const auto &arguments = predicate.arguments;
|
const auto &arguments = predicate.arguments;
|
||||||
|
|
||||||
@ -42,13 +42,13 @@ inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl
|
|||||||
outputStream << ", ";
|
outputStream << ", ";
|
||||||
|
|
||||||
const auto handleConstant =
|
const auto handleConstant =
|
||||||
[&](const ::pddl::ast::ConstantPointer &constant)
|
[&](const ::pddl::normalizedAST::ConstantPointer &constant)
|
||||||
{
|
{
|
||||||
outputStream << colorlog::Keyword("constant") << "(" << *constant << ")";
|
outputStream << colorlog::Keyword("constant") << "(" << *constant << ")";
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleVariable =
|
const auto handleVariable =
|
||||||
[&](const ::pddl::ast::VariablePointer &variable)
|
[&](const ::pddl::normalizedAST::VariablePointer &variable)
|
||||||
{
|
{
|
||||||
outputStream << *variable;
|
outputStream << *variable;
|
||||||
};
|
};
|
||||||
@ -67,7 +67,7 @@ inline void translatePredicate(colorlog::ColorStream &outputStream, const ::pddl
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration)
|
inline void translatePredicateDeclaration(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration)
|
||||||
{
|
{
|
||||||
outputStream << colorlog::Keyword("variable") << "(";
|
outputStream << colorlog::Keyword("variable") << "(";
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ inline void translatePredicateDeclaration(colorlog::ColorStream &outputStream, c
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void translatePredicateToVariable(colorlog::ColorStream &outputStream, const ::pddl::ast::Predicate &predicate, bool isPositive = true)
|
void translatePredicateToVariable(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Predicate &predicate, bool isPositive = true)
|
||||||
{
|
{
|
||||||
outputStream << colorlog::Keyword("variable") << "(";
|
outputStream << colorlog::Keyword("variable") << "(";
|
||||||
translatePredicate(outputStream, predicate);
|
translatePredicate(outputStream, predicate);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ namespace pddl
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::ConstantDeclaration &constantDeclaration)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::ConstantDeclaration &constantDeclaration)
|
||||||
{
|
{
|
||||||
assert(!constantDeclaration.name.empty());
|
assert(!constantDeclaration.name.empty());
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Constant &constant)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Constant &constant)
|
||||||
{
|
{
|
||||||
assert(constant.declaration != nullptr);
|
assert(constant.declaration != nullptr);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PrimitiveTypeDeclaration &primitiveTypeDeclaration)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PrimitiveTypeDeclaration &primitiveTypeDeclaration)
|
||||||
{
|
{
|
||||||
assert(!primitiveTypeDeclaration.name.empty());
|
assert(!primitiveTypeDeclaration.name.empty());
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PrimitiveType &primitiveType)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PrimitiveType &primitiveType)
|
||||||
{
|
{
|
||||||
assert(primitiveType.declaration != nullptr);
|
assert(primitiveType.declaration != nullptr);
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::ast::VariableDeclaration &variableDeclaration)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::normalizedAST::VariableDeclaration &variableDeclaration)
|
||||||
{
|
{
|
||||||
assert(!variableDeclaration.name.empty());
|
assert(!variableDeclaration.name.empty());
|
||||||
assert(std::isalpha(variableDeclaration.name[0]));
|
assert(std::isalpha(variableDeclaration.name[0]));
|
||||||
@ -70,7 +70,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::ast::Variable &variable)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::normalizedAST::Variable &variable)
|
||||||
{
|
{
|
||||||
assert(variable.declaration != nullptr);
|
assert(variable.declaration != nullptr);
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, ::pddl::
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// TODO: move to appropriate header
|
// TODO: move to appropriate header
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Action &action)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Action &action)
|
||||||
{
|
{
|
||||||
return (stream << colorlog::String(action.name.c_str()));
|
return (stream << colorlog::String(action.name.c_str()));
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// TODO: move to appropriate header
|
// TODO: move to appropriate header
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::PredicateDeclaration &predicateDeclaration)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::PredicateDeclaration &predicateDeclaration)
|
||||||
{
|
{
|
||||||
return (stream << colorlog::String(predicateDeclaration.name.c_str()));
|
return (stream << colorlog::String(predicateDeclaration.name.c_str()));
|
||||||
}
|
}
|
||||||
@ -96,13 +96,29 @@ inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// TODO: move to appropriate header
|
// TODO: move to appropriate header
|
||||||
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::ast::Predicate &predicate)
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::Predicate &predicate)
|
||||||
{
|
{
|
||||||
return (stream << *predicate.declaration);
|
return (stream << *predicate.declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO: move to appropriate header
|
||||||
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::DerivedPredicateDeclaration &derivedPredicateDeclaration)
|
||||||
|
{
|
||||||
|
return (stream << colorlog::String(derivedPredicateDeclaration.name.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO: move to appropriate header
|
||||||
|
inline colorlog::ColorStream &operator<<(colorlog::ColorStream &stream, const ::pddl::normalizedAST::DerivedPredicate &derivedPredicate)
|
||||||
|
{
|
||||||
|
return (stream << *derivedPredicate.declaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
#include <pddlparse/Parse.h>
|
#include <pddlparse/Parse.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
@ -53,10 +53,10 @@ inline void translateVariablesForRuleBody(colorlog::ColorStream &outputStream, c
|
|||||||
|
|
||||||
if (variable->type)
|
if (variable->type)
|
||||||
{
|
{
|
||||||
if (!variable->type.value().template is<::pddl::ast::PrimitiveTypePointer>())
|
if (!variable->type.value().template is<::pddl::normalizedAST::PrimitiveTypePointer>())
|
||||||
throw TranslatorException("only primitive types supported currently");
|
throw TranslatorException("only primitive types supported currently");
|
||||||
|
|
||||||
const auto &type = variable->type.value().template get<::pddl::ast::PrimitiveTypePointer>();
|
const auto &type = variable->type.value().template get<::pddl::normalizedAST::PrimitiveTypePointer>();
|
||||||
|
|
||||||
outputStream << colorlog::Function("has") << "("
|
outputStream << colorlog::Function("has") << "("
|
||||||
<< *variable << ", " << colorlog::Keyword("type") << "(" << *type << "))";
|
<< *variable << ", " << colorlog::Keyword("type") << "(" << *type << "))";
|
||||||
|
@ -82,6 +82,14 @@ class ParserException : public Exception
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
class NormalizationException : public Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Exception::Exception;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
24
lib/pddlparse/include/pddlparse/Normalize.h
Normal file
24
lib/pddlparse/include/pddlparse/Normalize.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef __PDDL_PARSE__NORMALIZE_H
|
||||||
|
#define __PDDL_PARSE__NORMALIZE_H
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Description.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Normalize
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using detail::normalize;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -133,6 +133,7 @@ struct Problem
|
|||||||
|
|
||||||
Domain *domain;
|
Domain *domain;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
DerivedPredicateDeclarations derivedPredicates;
|
||||||
ConstantDeclarations objects;
|
ConstantDeclarations objects;
|
||||||
InitialState initialState;
|
InitialState initialState;
|
||||||
std::experimental::optional<Goal> goal;
|
std::experimental::optional<Goal> goal;
|
||||||
|
@ -66,6 +66,9 @@ using ast::AtPointer;
|
|||||||
using ast::Either;
|
using ast::Either;
|
||||||
using ast::EitherPointer;
|
using ast::EitherPointer;
|
||||||
using ast::Exists;
|
using ast::Exists;
|
||||||
|
using ast::ExistsPointer;
|
||||||
|
using ast::ForAll;
|
||||||
|
using ast::ForAllPointer;
|
||||||
using ast::Not;
|
using ast::Not;
|
||||||
using ast::NotPointer;
|
using ast::NotPointer;
|
||||||
using ast::When;
|
using ast::When;
|
||||||
@ -170,7 +173,7 @@ namespace detail
|
|||||||
using EffectT = Variant<
|
using EffectT = Variant<
|
||||||
AtomicFormula,
|
AtomicFormula,
|
||||||
AndPointer<Effect>,
|
AndPointer<Effect>,
|
||||||
ast::ForAllPointer<Effect>,
|
ForAllPointer<Effect>,
|
||||||
NotPointer<Effect>,
|
NotPointer<Effect>,
|
||||||
WhenPointer<Precondition, ConditionalEffect>>;
|
WhenPointer<Precondition, ConditionalEffect>>;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__ACTION_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__ACTION_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Action
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::ActionPointer normalize(ast::ActionPointer &&domain, normalizedAST::DerivedPredicateDeclarations &derivedPredicates);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__ATOMIC_FORMULA_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__ATOMIC_FORMULA_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// AtomicFormula
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__DESCRIPTION_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__DESCRIPTION_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Description normalize(ast::Description &&description);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__DOMAIN_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__DOMAIN_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Domain
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DomainPointer normalize(ast::DomainPointer &&domain);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__EFFECT_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__EFFECT_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Effect
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Effect normalize(ast::Effect &&effect);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
26
lib/pddlparse/include/pddlparse/detail/normalization/Fact.h
Normal file
26
lib/pddlparse/include/pddlparse/detail/normalization/Fact.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__FACT_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__FACT_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Fact
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Fact normalize(ast::Fact &&fact);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__INITIAL_STATE_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__INITIAL_STATE_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// InitialState
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::InitialState normalize(ast::InitialState &&initialState);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__LITERAL_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__LITERAL_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Literal
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Literal normalize(ast::Literal &&literal);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__PRECONDITION_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__PRECONDITION_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Precondition
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Precondition normalize(ast::Precondition &&precondition, normalizedAST::DerivedPredicateDeclarations &derivedPredicates);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__PROBLEM_H
|
||||||
|
#define __PDDL_PARSE__DETAIL__NORMALIZATION__PROBLEM_H
|
||||||
|
|
||||||
|
#include <pddlparse/ASTForward.h>
|
||||||
|
#include <pddlparse/Context.h>
|
||||||
|
#include <pddlparse/NormalizedASTForward.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Problem
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::ProblemPointer normalize(ast::ProblemPointer &&problem, normalizedAST::Domain *domain);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -9,6 +9,9 @@ file(GLOB detail_headers "../include/pddlparse/detail/*.h")
|
|||||||
file(GLOB detail_parsing_sources "pddlparse/detail/parsing/*.cpp")
|
file(GLOB detail_parsing_sources "pddlparse/detail/parsing/*.cpp")
|
||||||
file(GLOB detail_parsing_headers "../include/pddlparse/detail/parsing/*.h")
|
file(GLOB detail_parsing_headers "../include/pddlparse/detail/parsing/*.h")
|
||||||
|
|
||||||
|
file(GLOB detail_normalization_sources "pddlparse/detail/normalization/*.cpp")
|
||||||
|
file(GLOB detail_normalization_headers "../include/pddlparse/detail/normalization/*.h")
|
||||||
|
|
||||||
set(includes
|
set(includes
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
${PROJECT_SOURCE_DIR}/../../lib/colorlog/include
|
${PROJECT_SOURCE_DIR}/../../lib/colorlog/include
|
||||||
@ -25,6 +28,9 @@ set(sources
|
|||||||
|
|
||||||
${detail_parsing_sources}
|
${detail_parsing_sources}
|
||||||
${detail_parsing_headers}
|
${detail_parsing_headers}
|
||||||
|
|
||||||
|
${detail_normalization_sources}
|
||||||
|
${detail_normalization_headers}
|
||||||
)
|
)
|
||||||
|
|
||||||
set(libraries
|
set(libraries
|
||||||
|
41
lib/pddlparse/src/pddlparse/detail/normalization/Action.cpp
Normal file
41
lib/pddlparse/src/pddlparse/detail/normalization/Action.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Action.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Effect.h>
|
||||||
|
#include <pddlparse/detail/normalization/Precondition.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Action
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::ActionPointer normalize(ast::ActionPointer &&action, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
auto normalizedAction = std::make_unique<normalizedAST::Action>();
|
||||||
|
|
||||||
|
normalizedAction->name = std::move(action->name);
|
||||||
|
normalizedAction->parameters = std::move(action->parameters);
|
||||||
|
|
||||||
|
if (action->precondition)
|
||||||
|
normalizedAction->precondition = normalize(std::move(action->precondition.value()), derivedPredicates);
|
||||||
|
|
||||||
|
// TODO: implement
|
||||||
|
/*
|
||||||
|
if (action->effect)
|
||||||
|
normalizedAction->effect = normalize(std::move(action->effect.value()));
|
||||||
|
*/
|
||||||
|
|
||||||
|
return normalizedAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
#include <pddlparse/detail/normalization/AtomicFormula.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// AtomicFormula
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::AtomicFormula normalize(ast::AtomicFormula &&atomicFormula)
|
||||||
|
{
|
||||||
|
const auto handleUnsupported =
|
||||||
|
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::AtomicFormula
|
||||||
|
{
|
||||||
|
throw NormalizationException("“" + unsupported->type + "” expressions as literals can’t be normalized currently");
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handlePredicate =
|
||||||
|
[&](ast::PredicatePointer &predicate) -> normalizedAST::AtomicFormula
|
||||||
|
{
|
||||||
|
return std::move(predicate);
|
||||||
|
};
|
||||||
|
|
||||||
|
return atomicFormula.match(handlePredicate, handleUnsupported);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Description.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Domain.h>
|
||||||
|
#include <pddlparse/detail/normalization/Problem.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Description normalize(ast::Description &&description)
|
||||||
|
{
|
||||||
|
normalizedAST::Description normalizedDescription;
|
||||||
|
|
||||||
|
normalizedDescription.domain = normalize(std::move(description.domain));
|
||||||
|
|
||||||
|
if (description.problem)
|
||||||
|
normalizedDescription.problem = normalize(std::move(description.problem.value()), normalizedDescription.domain.get());
|
||||||
|
|
||||||
|
return normalizedDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
38
lib/pddlparse/src/pddlparse/detail/normalization/Domain.cpp
Normal file
38
lib/pddlparse/src/pddlparse/detail/normalization/Domain.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Domain.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Action.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Description
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DomainPointer normalize(ast::DomainPointer &&domain)
|
||||||
|
{
|
||||||
|
auto normalizedDomain = std::make_unique<normalizedAST::Domain>();
|
||||||
|
|
||||||
|
normalizedDomain->types = std::move(domain->types);
|
||||||
|
normalizedDomain->name = std::move(domain->name);
|
||||||
|
normalizedDomain->constants = std::move(domain->constants);
|
||||||
|
normalizedDomain->predicates = std::move(domain->predicates);
|
||||||
|
|
||||||
|
normalizedDomain->actions.reserve(domain->actions.size());
|
||||||
|
|
||||||
|
for (auto &&action : domain->actions)
|
||||||
|
normalizedDomain->actions.emplace_back(normalize(std::move(action), normalizedDomain->derivedPredicates));
|
||||||
|
|
||||||
|
return normalizedDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
28
lib/pddlparse/src/pddlparse/detail/normalization/Effect.cpp
Normal file
28
lib/pddlparse/src/pddlparse/detail/normalization/Effect.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Effect.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Effect
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// TODO: implement
|
||||||
|
/*
|
||||||
|
normalizedAST::Effect normalize(ast::Effect &&)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
39
lib/pddlparse/src/pddlparse/detail/normalization/Fact.cpp
Normal file
39
lib/pddlparse/src/pddlparse/detail/normalization/Fact.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Fact.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Literal.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Fact
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Fact normalize(ast::Fact &&fact)
|
||||||
|
{
|
||||||
|
const auto handleLiteral =
|
||||||
|
[&](ast::Literal &literal) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return normalize(std::move(literal));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAt =
|
||||||
|
[&](ast::AtPointer<ast::Literal> &) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
throw NormalizationException("“at” expressions in preconditions can’t be normalized currently");
|
||||||
|
};
|
||||||
|
|
||||||
|
return fact.match(handleLiteral, handleAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
#include <pddlparse/detail/normalization/InitialState.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/Fact.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// InitialState
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::InitialState normalize(ast::InitialState &&initialState)
|
||||||
|
{
|
||||||
|
normalizedAST::InitialState normalizedInitialState;
|
||||||
|
normalizedInitialState.facts.reserve(initialState.facts.size());
|
||||||
|
|
||||||
|
for (auto &fact : initialState.facts)
|
||||||
|
normalizedInitialState.facts.emplace_back(normalize(std::move(fact)));
|
||||||
|
|
||||||
|
return normalizedInitialState;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
39
lib/pddlparse/src/pddlparse/detail/normalization/Literal.cpp
Normal file
39
lib/pddlparse/src/pddlparse/detail/normalization/Literal.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Literal.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/AtomicFormula.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Literal
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Literal normalize(ast::Literal &&literal)
|
||||||
|
{
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](ast::AtomicFormula &atomicFormula) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return normalize(std::move(atomicFormula));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNot =
|
||||||
|
[&](ast::NotPointer<ast::AtomicFormula> ¬_) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return std::make_unique<normalizedAST::Not<normalizedAST::AtomicFormula>>(normalize(std::move(not_->argument)));
|
||||||
|
};
|
||||||
|
|
||||||
|
return literal.match(handleAtomicFormula, handleNot);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,218 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Precondition.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Exception.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/AtomicFormula.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Precondition
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer addDerivedPredicate(normalizedAST::DerivedPredicateDeclarations &derivedPredicates, const std::string &type)
|
||||||
|
{
|
||||||
|
auto name = "derived-" + type + "-" + std::to_string(derivedPredicates.size() + 1);
|
||||||
|
|
||||||
|
derivedPredicates.emplace_back(std::make_unique<normalizedAST::DerivedPredicateDeclaration>(std::move(name), normalizedAST::VariableDeclarations()));
|
||||||
|
|
||||||
|
return std::make_unique<normalizedAST::DerivedPredicate>(normalizedAST::DerivedPredicate::Arguments(), derivedPredicates.back().get());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::AndPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "and");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &)
|
||||||
|
{
|
||||||
|
// TODO: add explanation
|
||||||
|
throw std::logic_error("atomic formulas should have been handled earlier");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::ExistsPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::ForAllPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "forall");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::ImplyPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "imply");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::NotPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "not");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::DerivedPredicatePointer normalizeNested(ast::OrPointer<ast::Precondition> &, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// TODO: handle arguments recursively
|
||||||
|
return addDerivedPredicate(derivedPredicates, "or");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::PredicatePointer normalize(ast::UnsupportedPointer &&unsupported, normalizedAST::DerivedPredicateDeclarations &)
|
||||||
|
{
|
||||||
|
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Normalize top-level negations
|
||||||
|
normalizedAST::NotPointer<normalizedAST::AtomicFormula> normalize(ast::NotPointer<ast::Precondition> &¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
// “not” expressions may be nested one time to form simple literals
|
||||||
|
if (not_->argument.is<ast::AtomicFormula>())
|
||||||
|
return std::make_unique<normalizedAST::Not<normalizedAST::AtomicFormula>>(normalize(std::move(not_->argument.get<ast::AtomicFormula>())));
|
||||||
|
|
||||||
|
const auto handleNested =
|
||||||
|
[&](auto &nested) -> normalizedAST::AtomicFormula
|
||||||
|
{
|
||||||
|
return normalizeNested(nested, derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleUnsupported =
|
||||||
|
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::AtomicFormula
|
||||||
|
{
|
||||||
|
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||||
|
};
|
||||||
|
|
||||||
|
auto normalizedArgument = not_->argument.match(handleNested, handleUnsupported);
|
||||||
|
|
||||||
|
return std::make_unique<normalizedAST::Not<normalizedAST::AtomicFormula>>(std::move(normalizedArgument));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// Normalize top-level conjunctions
|
||||||
|
normalizedAST::AndPointer<normalizedAST::Literal> normalize(ast::AndPointer<ast::Precondition> &&and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
normalizedAST::And<normalizedAST::Literal>::Arguments arguments;
|
||||||
|
|
||||||
|
arguments.reserve(and_->arguments.size());
|
||||||
|
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](ast::AtomicFormula &atomicFormula) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return normalize(std::move(atomicFormula));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNot =
|
||||||
|
[&](ast::NotPointer<ast::Precondition> ¬_) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return normalize(std::move(not_), derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNested =
|
||||||
|
[&](auto &nested) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
return normalizeNested(nested, derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleUnsupported =
|
||||||
|
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::Literal
|
||||||
|
{
|
||||||
|
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto &&argument : and_->arguments)
|
||||||
|
{
|
||||||
|
auto normalizedArgument = argument.match(handleAtomicFormula, handleNot, handleNested, handleUnsupported);
|
||||||
|
|
||||||
|
arguments.emplace_back(std::move(normalizedArgument));
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_unique<normalizedAST::And<normalizedAST::Literal>>(std::move(arguments));
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::Precondition normalize(ast::Precondition &&precondition, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
reduce
|
||||||
|
|
||||||
|
AtomicFormula,
|
||||||
|
AndPointer<Precondition>,
|
||||||
|
NotPointer<Precondition>,
|
||||||
|
UnsupportedPointer>;
|
||||||
|
|
||||||
|
ExistsPointer<Precondition>,
|
||||||
|
ForAllPointer<Precondition>,
|
||||||
|
ImplyPointer<Precondition>,
|
||||||
|
OrPointer<Precondition>,
|
||||||
|
|
||||||
|
to
|
||||||
|
|
||||||
|
Literal,
|
||||||
|
AndPointer<Literal>>;
|
||||||
|
*/
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](ast::AtomicFormula &atomicFormula) -> normalizedAST::Precondition
|
||||||
|
{
|
||||||
|
return normalize(std::move(atomicFormula));
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNot =
|
||||||
|
[&](ast::NotPointer<ast::Precondition> ¬_) -> normalizedAST::Precondition
|
||||||
|
{
|
||||||
|
return normalize(std::move(not_), derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAnd =
|
||||||
|
[&](ast::AndPointer<ast::Precondition> &and_) -> normalizedAST::Precondition
|
||||||
|
{
|
||||||
|
return normalize(std::move(and_), derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNested =
|
||||||
|
[&](auto &nested) -> normalizedAST::Precondition
|
||||||
|
{
|
||||||
|
return normalizeNested(nested, derivedPredicates);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleUnsupported =
|
||||||
|
[&](ast::UnsupportedPointer &unsupported) -> normalizedAST::Precondition
|
||||||
|
{
|
||||||
|
throw NormalizationException("“" + unsupported->type + "” expressions in preconditions can’t be normalized currently");
|
||||||
|
};
|
||||||
|
|
||||||
|
return precondition.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported, handleNested);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
36
lib/pddlparse/src/pddlparse/detail/normalization/Problem.cpp
Normal file
36
lib/pddlparse/src/pddlparse/detail/normalization/Problem.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <pddlparse/detail/normalization/Problem.h>
|
||||||
|
|
||||||
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
#include <pddlparse/detail/normalization/InitialState.h>
|
||||||
|
#include <pddlparse/detail/normalization/Precondition.h>
|
||||||
|
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Problem
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
normalizedAST::ProblemPointer normalize(ast::ProblemPointer &&problem, normalizedAST::Domain *domain)
|
||||||
|
{
|
||||||
|
auto normalizedProblem = std::make_unique<normalizedAST::Problem>(domain);
|
||||||
|
|
||||||
|
normalizedProblem->name = std::move(problem->name);
|
||||||
|
normalizedProblem->objects = std::move(problem->objects);
|
||||||
|
normalizedProblem->initialState = normalize(std::move(problem->initialState));
|
||||||
|
|
||||||
|
if (problem->goal)
|
||||||
|
normalizedProblem->goal = normalize(std::move(problem->goal.value()), normalizedProblem->derivedPredicates);
|
||||||
|
|
||||||
|
return normalizedProblem;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <colorlog/Formatting.h>
|
#include <colorlog/Formatting.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
#include <plasp/TranslatorException.h>
|
#include <plasp/TranslatorException.h>
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ namespace pddl
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TranslatorASP::TranslatorASP(const ::pddl::ast::Description &description, colorlog::ColorStream &outputStream)
|
TranslatorASP::TranslatorASP(const ::pddl::normalizedAST::Description &description, colorlog::ColorStream &outputStream)
|
||||||
: m_description{description},
|
: m_description{description},
|
||||||
m_outputStream(outputStream)
|
m_outputStream(outputStream)
|
||||||
{
|
{
|
||||||
@ -216,7 +216,7 @@ void TranslatorASP::translateActions() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TranslatorASP::translateConstants(const std::string &heading, const ::pddl::ast::ConstantDeclarations &constants) const
|
void TranslatorASP::translateConstants(const std::string &heading, const ::pddl::normalizedAST::ConstantDeclarations &constants) const
|
||||||
{
|
{
|
||||||
m_outputStream << colorlog::Heading2(heading.c_str());
|
m_outputStream << colorlog::Heading2(heading.c_str());
|
||||||
|
|
||||||
@ -232,10 +232,10 @@ void TranslatorASP::translateConstants(const std::string &heading, const ::pddl:
|
|||||||
|
|
||||||
if (type)
|
if (type)
|
||||||
{
|
{
|
||||||
if (!type.value().is<::pddl::ast::PrimitiveTypePointer>())
|
if (!type.value().is<::pddl::normalizedAST::PrimitiveTypePointer>())
|
||||||
throw TranslatorException("only primitive types supported currently");
|
throw TranslatorException("only primitive types supported currently");
|
||||||
|
|
||||||
const auto &primitveType = type.value().get<::pddl::ast::PrimitiveTypePointer>();
|
const auto &primitveType = type.value().get<::pddl::normalizedAST::PrimitiveTypePointer>();
|
||||||
|
|
||||||
m_outputStream << colorlog::Function("has") << "("
|
m_outputStream << colorlog::Function("has") << "("
|
||||||
<< colorlog::Keyword("constant") << "(" << *constant << "), "
|
<< colorlog::Keyword("constant") << "(" << *constant << "), "
|
||||||
@ -294,36 +294,44 @@ void TranslatorASP::translateInitialState() const
|
|||||||
{
|
{
|
||||||
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
|
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
|
||||||
|
|
||||||
const auto handleUnsupported =
|
const auto handlePredicate =
|
||||||
[&](const auto &)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||||
{
|
{
|
||||||
throw TranslatorException("only predicates and their negations supported in initial state currently");
|
|
||||||
};
|
|
||||||
|
|
||||||
const auto handleAtomicFormula =
|
|
||||||
[&](const ::pddl::ast::AtomicFormula &atomicFormula, bool isPositive = true)
|
|
||||||
{
|
|
||||||
if (!atomicFormula.is<::pddl::ast::PredicatePointer>())
|
|
||||||
handleUnsupported(atomicFormula);
|
|
||||||
|
|
||||||
const auto &predicate = atomicFormula.get<::pddl::ast::PredicatePointer>();
|
|
||||||
|
|
||||||
translatePredicateToVariable(m_outputStream, *predicate, isPositive);
|
translatePredicateToVariable(m_outputStream, *predicate, isPositive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto handleNegatedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||||
|
{
|
||||||
|
return handlePredicate(predicate, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleDerivedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||||
|
{
|
||||||
|
// TODO: implement
|
||||||
|
//translatePredicateToVariable(m_outputStream, *predicate, true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNegatedDerivedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||||
|
{
|
||||||
|
return handleDerivedPredicate(derivedPredicate, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleAtomicFormula =
|
||||||
|
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
||||||
|
{
|
||||||
|
atomicFormula.match(handlePredicate, handleDerivedPredicate);
|
||||||
|
};
|
||||||
|
|
||||||
const auto handleNot =
|
const auto handleNot =
|
||||||
[&](const ::pddl::ast::NotPointer<::pddl::ast::AtomicFormula> ¬_)
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||||
{
|
{
|
||||||
handleAtomicFormula(not_->argument, false);
|
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleLiteral =
|
fact.match(handleAtomicFormula, handleNot);
|
||||||
[&](const ::pddl::ast::Literal &literal)
|
|
||||||
{
|
|
||||||
literal.match(handleAtomicFormula, handleNot);
|
|
||||||
};
|
|
||||||
|
|
||||||
fact.match(handleLiteral, handleUnsupported);
|
|
||||||
|
|
||||||
m_outputStream << ").";
|
m_outputStream << ").";
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <colorlog/Logger.h>
|
#include <colorlog/Logger.h>
|
||||||
|
|
||||||
#include <pddlparse/AST.h>
|
#include <pddlparse/AST.h>
|
||||||
|
#include <pddlparse/Normalize.h>
|
||||||
#include <pddlparse/Parse.h>
|
#include <pddlparse/Parse.h>
|
||||||
|
|
||||||
#include <plasp/pddl/TranslatorASP.h>
|
#include <plasp/pddl/TranslatorASP.h>
|
||||||
@ -25,7 +26,7 @@ TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]")
|
|||||||
SECTION("translating domains without typing information works")
|
SECTION("translating domains without typing information works")
|
||||||
{
|
{
|
||||||
context.tokenizer.read("data/issues/issue-4.pddl");
|
context.tokenizer.read("data/issues/issue-4.pddl");
|
||||||
auto description = pddl::parseDescription(context);
|
auto description = pddl::normalize(pddl::parseDescription(context));
|
||||||
const auto translator = plasp::pddl::TranslatorASP(std::move(description), logger.outputStream());
|
const auto translator = plasp::pddl::TranslatorASP(std::move(description), logger.outputStream());
|
||||||
CHECK_NOTHROW(translator.translate());
|
CHECK_NOTHROW(translator.translate());
|
||||||
}
|
}
|
||||||
@ -33,7 +34,7 @@ TEST_CASE("[PDDL translation] Former issues are fixed", "[PDDL translation]")
|
|||||||
SECTION("translating the simple blocks world domain works")
|
SECTION("translating the simple blocks world domain works")
|
||||||
{
|
{
|
||||||
context.tokenizer.read("data/issues/issue-5.pddl");
|
context.tokenizer.read("data/issues/issue-5.pddl");
|
||||||
auto description = pddl::parseDescription(context);
|
auto description = pddl::normalize(pddl::parseDescription(context));
|
||||||
const auto translator = plasp::pddl::TranslatorASP(std::move(description), logger.outputStream());
|
const auto translator = plasp::pddl::TranslatorASP(std::move(description), logger.outputStream());
|
||||||
CHECK_NOTHROW(translator.translate());
|
CHECK_NOTHROW(translator.translate());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user