Added support for unconditional “forall” effect statements.
This commit is contained in:
parent
39b885c47c
commit
f61cfa532d
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#include <plasp/pddl/translation/Predicate.h>
|
#include <plasp/pddl/translation/Predicate.h>
|
||||||
#include <plasp/pddl/translation/Primitives.h>
|
#include <plasp/pddl/translation/Primitives.h>
|
||||||
|
#include <plasp/pddl/translation/Variables.h>
|
||||||
|
#include <plasp/pddl/translation/VariableStack.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -22,7 +24,7 @@ namespace pddl
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename PrintObjectName>
|
template<typename PrintObjectName>
|
||||||
inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::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, VariableStack &variableStack)
|
||||||
{
|
{
|
||||||
const auto handlePredicate =
|
const auto handlePredicate =
|
||||||
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
|
||||||
@ -36,13 +38,37 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::n
|
|||||||
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
translatePredicateToVariable(outputStream, *predicate, isPositive);
|
||||||
outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "(";
|
outputStream << ") :- " << colorlog::Function(objectType.c_str()) << "(";
|
||||||
printObjectName();
|
printObjectName();
|
||||||
outputStream << ").";
|
outputStream << ")";
|
||||||
|
|
||||||
|
if (!variableStack.layers.empty())
|
||||||
|
for (const auto &layer : variableStack.layers)
|
||||||
|
{
|
||||||
|
if (!layer->empty())
|
||||||
|
outputStream << ", ";
|
||||||
|
|
||||||
|
translateVariablesForRuleBody(outputStream, *layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
outputStream << ".";
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNegatedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
|
||||||
|
{
|
||||||
|
handlePredicate(predicate, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleDerivedPredicate =
|
const auto handleDerivedPredicate =
|
||||||
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
|
||||||
{
|
{
|
||||||
throw TranslatorException("derived predicates not yet supported by translator");
|
// TODO: refactor as to exclude derived predicates from the Effect variant
|
||||||
|
throw TranslatorException("derived predicates should not appear in effects");
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto handleNegatedDerivedPredicate =
|
||||||
|
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &derivedPredicate)
|
||||||
|
{
|
||||||
|
handleDerivedPredicate(derivedPredicate, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleAtomicFormula =
|
const auto handleAtomicFormula =
|
||||||
@ -54,12 +80,7 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::n
|
|||||||
const auto handleNot =
|
const auto handleNot =
|
||||||
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
[&](const ::pddl::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> ¬_)
|
||||||
{
|
{
|
||||||
if (!not_->argument.is<::pddl::normalizedAST::PredicatePointer>())
|
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||||
throw TranslatorException("only “and” expressions and (negated) predicates supported as action effects currently");
|
|
||||||
|
|
||||||
const auto &predicate = not_->argument.get<::pddl::normalizedAST::PredicatePointer>();
|
|
||||||
|
|
||||||
handlePredicate(predicate, false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleLiteral =
|
const auto handleLiteral =
|
||||||
@ -72,13 +93,17 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::n
|
|||||||
[&](const ::pddl::normalizedAST::AndPointer<::pddl::normalizedAST::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, variableStack);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleForAll =
|
const auto handleForAll =
|
||||||
[&](const ::pddl::normalizedAST::ForAllPointer<::pddl::normalizedAST::Effect> &)
|
[&](const ::pddl::normalizedAST::ForAllPointer<::pddl::normalizedAST::Effect> &forAll)
|
||||||
{
|
{
|
||||||
throw TranslatorException("“when” expressions not yet supported by translator");
|
variableStack.push(&forAll->parameters);
|
||||||
|
|
||||||
|
translateEffect(outputStream, forAll->argument, objectType, printObjectName, variableStack);
|
||||||
|
|
||||||
|
variableStack.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto handleWhen =
|
const auto handleWhen =
|
||||||
@ -92,6 +117,16 @@ inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::n
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename PrintObjectName>
|
||||||
|
inline void translateEffect(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Effect &effect, const std::string &objectType, PrintObjectName printObjectName)
|
||||||
|
{
|
||||||
|
VariableStack variableStack;
|
||||||
|
|
||||||
|
translateEffect(outputStream, effect, objectType, printObjectName, variableStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
include/plasp/pddl/translation/VariableStack.h
Normal file
39
include/plasp/pddl/translation/VariableStack.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
|
||||||
|
#define __PLASP__PDDL__TRANSLATION__VARIABLE_STACK_H
|
||||||
|
|
||||||
|
#include <pddlparse/NormalizedAST.h>
|
||||||
|
|
||||||
|
namespace plasp
|
||||||
|
{
|
||||||
|
namespace pddl
|
||||||
|
{
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// VariableStack
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct VariableStack
|
||||||
|
{
|
||||||
|
using Layer = ::pddl::normalizedAST::VariableDeclarations *;
|
||||||
|
|
||||||
|
void push(Layer layer)
|
||||||
|
{
|
||||||
|
layers.push_back(layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pop()
|
||||||
|
{
|
||||||
|
layers.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Layer> layers;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -337,6 +337,7 @@ void TranslatorASP::translateActions() const
|
|||||||
if (action->precondition)
|
if (action->precondition)
|
||||||
translatePrecondition(m_outputStream, action->precondition.value(), "action", printActionName);
|
translatePrecondition(m_outputStream, action->precondition.value(), "action", printActionName);
|
||||||
|
|
||||||
|
// Effect
|
||||||
if (action->effect)
|
if (action->effect)
|
||||||
translateEffect(m_outputStream, action->effect.value(), "action", printActionName);
|
translateEffect(m_outputStream, action->effect.value(), "action", printActionName);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user