patrick
/
plasp
Archived
1
0
Fork 0

Handling effects in PDDL normalization step.

This commit is contained in:
Patrick Lühne 2017-06-27 22:32:49 +02:00
parent da85683f7c
commit 39b885c47c
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
5 changed files with 111 additions and 9 deletions

View File

@ -0,0 +1,26 @@
#ifndef __PDDL_PARSE__DETAIL__NORMALIZATION__CONDITIONAL_EFFECT_H
#define __PDDL_PARSE__DETAIL__NORMALIZATION__CONDITIONAL_EFFECT_H
#include <pddlparse/ASTForward.h>
#include <pddlparse/Context.h>
#include <pddlparse/NormalizedASTForward.h>
namespace pddl
{
namespace detail
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ConditionalEffect
//
////////////////////////////////////////////////////////////////////////////////////////////////////
normalizedAST::ConditionalEffect normalize(ast::ConditionalEffect &&conditionalEffect);
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -16,7 +16,7 @@ namespace detail
//
////////////////////////////////////////////////////////////////////////////////////////////////////
normalizedAST::Effect normalize(ast::Effect &&effect);
normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPredicateDeclarations &derivedPredicates);
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -26,11 +26,8 @@ normalizedAST::ActionPointer normalize(ast::ActionPointer &&action, normalizedAS
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()));
*/
normalizedAction->effect = normalize(std::move(action->effect.value()), derivedPredicates);
return normalizedAction;
}

View File

@ -0,0 +1,45 @@
#include <pddlparse/detail/normalization/Effect.h>
#include <pddlparse/AST.h>
#include <pddlparse/Exception.h>
#include <pddlparse/NormalizedAST.h>
#include <pddlparse/detail/normalization/Literal.h>
#include <pddlparse/detail/normalization/Precondition.h>
namespace pddl
{
namespace detail
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Effect
//
////////////////////////////////////////////////////////////////////////////////////////////////////
normalizedAST::ConditionalEffect normalize(ast::ConditionalEffect &&conditionalEffect)
{
const auto handleLiteral =
[](ast::Literal &literal) -> normalizedAST::ConditionalEffect
{
return normalize(std::move(literal));
};
const auto handleAnd =
[&](ast::AndPointer<ast::Literal> &and_) -> normalizedAST::ConditionalEffect
{
normalizedAST::And<normalizedAST::Literal>::Arguments arguments;
for (auto &argument : and_->arguments)
arguments.emplace_back(normalize(std::move(argument)));
return std::make_unique<normalizedAST::And<normalizedAST::Literal>>(std::move(arguments));
};
return conditionalEffect.match(handleLiteral, handleAnd);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View File

@ -3,6 +3,9 @@
#include <pddlparse/AST.h>
#include <pddlparse/Exception.h>
#include <pddlparse/NormalizedAST.h>
#include <pddlparse/detail/normalization/ConditionalEffect.h>
#include <pddlparse/detail/normalization/Literal.h>
#include <pddlparse/detail/normalization/Precondition.h>
namespace pddl
{
@ -15,12 +18,43 @@ namespace detail
//
////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: implement
/*
normalizedAST::Effect normalize(ast::Effect &&)
normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPredicateDeclarations &derivedPredicates)
{
const auto handleLiteral =
[](ast::Literal &literal) -> normalizedAST::Effect
{
return normalize(std::move(literal));
};
const auto handleAnd =
[&](ast::AndPointer<ast::Effect> &and_) -> normalizedAST::Effect
{
normalizedAST::And<normalizedAST::Effect>::Arguments arguments;
for (auto &argument : and_->arguments)
arguments.emplace_back(normalize(std::move(argument), derivedPredicates));
return std::make_unique<normalizedAST::And<normalizedAST::Effect>>(std::move(arguments));
};
const auto handleForAll =
[&](ast::ForAllPointer<ast::Effect> &forAll) -> normalizedAST::Effect
{
auto normalizedArgument = normalize(std::move(forAll->argument), derivedPredicates);
return std::make_unique<normalizedAST::ForAll<normalizedAST::Effect>>(std::move(forAll->parameters), std::move(normalizedArgument));
};
const auto handleWhen =
[&](ast::WhenPointer<ast::Precondition, ast::ConditionalEffect> &when) -> normalizedAST::Effect
{
auto normalizedCondition = normalize(std::move(when->argumentLeft), derivedPredicates);
auto normalizedConditionalEffect = normalize(std::move(when->argumentRight));
return std::make_unique<normalizedAST::When<normalizedAST::Precondition, normalizedAST::ConditionalEffect>>(std::move(normalizedCondition), std::move(normalizedConditionalEffect));
};
return effect.match(handleLiteral, handleAnd, handleForAll, handleWhen);
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////