2017-06-20 01:53:55 +02:00
|
|
|
#ifndef __PLASP__PDDL__TRANSLATION__EFFECT_H
|
|
|
|
#define __PLASP__PDDL__TRANSLATION__EFFECT_H
|
|
|
|
|
2017-06-22 20:58:31 +02:00
|
|
|
#include <colorlog/Formatting.h>
|
|
|
|
|
2017-06-23 04:18:07 +02:00
|
|
|
#include <pddlparse/NormalizedAST.h>
|
2017-06-20 01:53:55 +02:00
|
|
|
|
2017-06-22 20:58:31 +02:00
|
|
|
#include <plasp/TranslatorException.h>
|
2017-06-20 01:53:55 +02:00
|
|
|
|
|
|
|
#include <plasp/pddl/translation/Predicate.h>
|
|
|
|
#include <plasp/pddl/translation/Primitives.h>
|
|
|
|
|
|
|
|
namespace plasp
|
|
|
|
{
|
|
|
|
namespace pddl
|
|
|
|
{
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Effect
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template<typename PrintObjectName>
|
2017-06-23 04:18:07 +02:00
|
|
|
inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Effect &effect, const std::string &objectType, PrintObjectName printObjectName)
|
2017-06-20 01:53:55 +02:00
|
|
|
{
|
|
|
|
const auto handleUnsupported =
|
|
|
|
[](const auto &)
|
|
|
|
{
|
2017-06-22 20:58:31 +02:00
|
|
|
throw TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently");
|
2017-06-20 01:53:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const auto handlePredicate =
|
2017-06-23 04:18:07 +02:00
|
|
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
2017-06-20 01:53:55 +02:00
|
|
|
{
|
2017-06-22 20:58:31 +02:00
|
|
|
outputStream << std::endl << colorlog::Function("postcondition") << "(";
|
2017-06-20 01:53:55 +02:00
|
|
|
printObjectName();
|
|
|
|
outputStream
|
2017-06-22 20:58:31 +02:00
|
|
|
<< ", " << colorlog::Keyword("effect") << "("
|
|
|
|
<< colorlog::Reserved("unconditional") << ")"
|
2017-06-20 01:53:55 +02:00
|
|
|
<< ", ";
|
|
|
|
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
2017-06-22 20:58:31 +02:00
|
|
|
outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "(";
|
2017-06-20 01:53:55 +02:00
|
|
|
printObjectName();
|
|
|
|
outputStream << ").";
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto handleAtomicFormula =
|
2017-06-23 04:18:07 +02:00
|
|
|
[&](const ::pddl::normalizedAST::AtomicFormula &atomicFormula)
|
2017-06-20 01:53:55 +02:00
|
|
|
{
|
|
|
|
atomicFormula.match(handlePredicate, handleUnsupported);
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto handleNot =
|
2017-06-23 04:18:07 +02:00
|
|
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::Effect> ¬_)
|
2017-06-20 01:53:55 +02:00
|
|
|
{
|
2017-06-23 04:18:07 +02:00
|
|
|
if (!not_->argument.is<::pddl::normalizedAST::AtomicFormula>() || !not_->argument.get<::pddl::normalizedAST::AtomicFormula>().is<::pddl::normalizedAST::PredicatePointer>())
|
2017-06-20 01:53:55 +02:00
|
|
|
handleUnsupported(not_);
|
|
|
|
|
2017-06-23 04:18:07 +02:00
|
|
|
const auto &predicate = not_->argument.get<::pddl::normalizedAST::AtomicFormula>().get<::pddl::normalizedAST::PredicatePointer>();
|
2017-06-20 01:53:55 +02:00
|
|
|
|
|
|
|
handlePredicate(predicate, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto handleAnd =
|
2017-06-23 04:18:07 +02:00
|
|
|
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::Effect> &and_)
|
2017-06-20 01:53:55 +02:00
|
|
|
{
|
|
|
|
for (const auto &argument : and_->arguments)
|
|
|
|
translateEffect(outputStream, argument, objectType, printObjectName);
|
|
|
|
};
|
|
|
|
|
|
|
|
effect.match(handleAtomicFormula, handleNot, handleAnd, handleUnsupported);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|