Started implementing PDDL normalization.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <colorlog/Formatting.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/NormalizedAST.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_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());
|
||||
|
||||
@@ -232,10 +232,10 @@ void TranslatorASP::translateConstants(const std::string &heading, const ::pddl:
|
||||
|
||||
if (type)
|
||||
{
|
||||
if (!type.value().is<::pddl::ast::PrimitiveTypePointer>())
|
||||
if (!type.value().is<::pddl::normalizedAST::PrimitiveTypePointer>())
|
||||
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") << "("
|
||||
<< colorlog::Keyword("constant") << "(" << *constant << "), "
|
||||
@@ -294,36 +294,44 @@ void TranslatorASP::translateInitialState() const
|
||||
{
|
||||
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
|
||||
|
||||
const auto handleUnsupported =
|
||||
[&](const auto &)
|
||||
const auto handlePredicate =
|
||||
[&](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);
|
||||
};
|
||||
|
||||
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 ::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 =
|
||||
[&](const ::pddl::ast::Literal &literal)
|
||||
{
|
||||
literal.match(handleAtomicFormula, handleNot);
|
||||
};
|
||||
|
||||
fact.match(handleLiteral, handleUnsupported);
|
||||
fact.match(handleAtomicFormula, handleNot);
|
||||
|
||||
m_outputStream << ").";
|
||||
}
|
||||
|
Reference in New Issue
Block a user