From 624ddc38aa9c30b833348d95031aef939e1fe5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 25 Oct 2017 17:42:54 +0200 Subject: [PATCH] Fixed incorrect derived predicate IDs in problems. The IDs of derived predicates within problems were accidentally starting with 1 again, colliding with the IDs of derived predicates in the domain. With this fix, the IDs are continuously incremented, even after switching from domain to problem. --- .../pddl/detail/normalization/Action.h | 4 +- .../pddl/detail/normalization/Effect.h | 4 +- .../normalization/NormalizationContext.h | 33 ++++++ .../pddl/detail/normalization/Precondition.h | 4 +- .../src/pddl/detail/normalization/Action.cpp | 6 +- .../src/pddl/detail/normalization/Domain.cpp | 4 +- .../src/pddl/detail/normalization/Effect.cpp | 8 +- .../detail/normalization/Precondition.cpp | 104 +++++++++--------- .../src/pddl/detail/normalization/Problem.cpp | 7 +- 9 files changed, 108 insertions(+), 66 deletions(-) create mode 100644 lib/pddl/include/pddl/detail/normalization/NormalizationContext.h diff --git a/lib/pddl/include/pddl/detail/normalization/Action.h b/lib/pddl/include/pddl/detail/normalization/Action.h index 04d5c04..9bf2d44 100644 --- a/lib/pddl/include/pddl/detail/normalization/Action.h +++ b/lib/pddl/include/pddl/detail/normalization/Action.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace pddl { @@ -16,7 +16,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::ActionPointer normalize(ast::ActionPointer &&domain, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::ActionPointer normalize(ast::ActionPointer &&domain, NormalizationContext &normalizationContext); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/pddl/include/pddl/detail/normalization/Effect.h b/lib/pddl/include/pddl/detail/normalization/Effect.h index b0df512..ad0a983 100644 --- a/lib/pddl/include/pddl/detail/normalization/Effect.h +++ b/lib/pddl/include/pddl/detail/normalization/Effect.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace pddl { @@ -16,7 +16,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Effect normalize(ast::Effect &&effect, detail::NormalizationContext &normalizationContext); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/pddl/include/pddl/detail/normalization/NormalizationContext.h b/lib/pddl/include/pddl/detail/normalization/NormalizationContext.h new file mode 100644 index 0000000..e423681 --- /dev/null +++ b/lib/pddl/include/pddl/detail/normalization/NormalizationContext.h @@ -0,0 +1,33 @@ +#ifndef __PDDL__DETAIL__NORMALIZATION__NORMALIZATION_CONTEXT_H +#define __PDDL__DETAIL__NORMALIZATION__NORMALIZATION_CONTEXT_H + +#include + +namespace pddl +{ +namespace detail +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// NormalizationContext +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +struct NormalizationContext +{ + NormalizationContext(normalizedAST::DerivedPredicateDeclarations &derivedPredicates) + : derivedPredicates{derivedPredicates} + { + } + + normalizedAST::DerivedPredicateDeclarations &derivedPredicates; + size_t derivedPredicateIDStart = 1; +}; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +} + +#endif diff --git a/lib/pddl/include/pddl/detail/normalization/Precondition.h b/lib/pddl/include/pddl/detail/normalization/Precondition.h index a90538e..37ee0ff 100644 --- a/lib/pddl/include/pddl/detail/normalization/Precondition.h +++ b/lib/pddl/include/pddl/detail/normalization/Precondition.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace pddl { @@ -16,7 +16,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Precondition normalize(ast::Precondition &&precondition, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Precondition normalize(ast::Precondition &&precondition, detail::NormalizationContext &normalizationContext); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/pddl/src/pddl/detail/normalization/Action.cpp b/lib/pddl/src/pddl/detail/normalization/Action.cpp index 8688418..07ebc0b 100644 --- a/lib/pddl/src/pddl/detail/normalization/Action.cpp +++ b/lib/pddl/src/pddl/detail/normalization/Action.cpp @@ -16,7 +16,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::ActionPointer normalize(ast::ActionPointer &&action, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::ActionPointer normalize(ast::ActionPointer &&action, detail::NormalizationContext &normalizationContext) { auto normalizedAction = std::make_unique(); @@ -24,10 +24,10 @@ normalizedAST::ActionPointer normalize(ast::ActionPointer &&action, normalizedAS normalizedAction->parameters = std::move(action->parameters); if (action->precondition) - normalizedAction->precondition = normalize(std::move(action->precondition.value()), derivedPredicates); + normalizedAction->precondition = normalize(std::move(action->precondition.value()), normalizationContext); if (action->effect) - normalizedAction->effect = normalize(std::move(action->effect.value()), derivedPredicates); + normalizedAction->effect = normalize(std::move(action->effect.value()), normalizationContext); return normalizedAction; } diff --git a/lib/pddl/src/pddl/detail/normalization/Domain.cpp b/lib/pddl/src/pddl/detail/normalization/Domain.cpp index c88fde0..28c3acd 100644 --- a/lib/pddl/src/pddl/detail/normalization/Domain.cpp +++ b/lib/pddl/src/pddl/detail/normalization/Domain.cpp @@ -26,8 +26,10 @@ normalizedAST::DomainPointer normalize(ast::DomainPointer &&domain) normalizedDomain->actions.reserve(domain->actions.size()); + NormalizationContext normalizationContext(normalizedDomain->derivedPredicates); + for (auto &&action : domain->actions) - normalizedDomain->actions.emplace_back(normalize(std::move(action), normalizedDomain->derivedPredicates)); + normalizedDomain->actions.emplace_back(normalize(std::move(action), normalizationContext)); return normalizedDomain; } diff --git a/lib/pddl/src/pddl/detail/normalization/Effect.cpp b/lib/pddl/src/pddl/detail/normalization/Effect.cpp index 010524e..dfba38d 100644 --- a/lib/pddl/src/pddl/detail/normalization/Effect.cpp +++ b/lib/pddl/src/pddl/detail/normalization/Effect.cpp @@ -18,7 +18,7 @@ namespace detail // //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Effect normalize(ast::Effect &&effect, detail::NormalizationContext &normalizationContext) { const auto handleLiteral = [](ast::Literal &literal) -> normalizedAST::Effect @@ -32,7 +32,7 @@ normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPred normalizedAST::And::Arguments arguments; for (auto &argument : and_->arguments) - arguments.emplace_back(normalize(std::move(argument), derivedPredicates)); + arguments.emplace_back(normalize(std::move(argument), normalizationContext)); return std::make_unique>(std::move(arguments)); }; @@ -40,14 +40,14 @@ normalizedAST::Effect normalize(ast::Effect &&effect, normalizedAST::DerivedPred const auto handleForAll = [&](ast::ForAllPointer &forAll) -> normalizedAST::Effect { - auto normalizedArgument = normalize(std::move(forAll->argument), derivedPredicates); + auto normalizedArgument = normalize(std::move(forAll->argument), normalizationContext); return std::make_unique>(std::move(forAll->parameters), std::move(normalizedArgument)); }; const auto handleWhen = [&](ast::WhenPointer &when) -> normalizedAST::Effect { - auto normalizedCondition = normalize(std::move(when->argumentLeft), derivedPredicates); + auto normalizedCondition = normalize(std::move(when->argumentLeft), normalizationContext); auto normalizedConditionalEffect = normalize(std::move(when->argumentRight)); return std::make_unique>(std::move(normalizedCondition), std::move(normalizedConditionalEffect)); diff --git a/lib/pddl/src/pddl/detail/normalization/Precondition.cpp b/lib/pddl/src/pddl/detail/normalization/Precondition.cpp index e81e6c4..fbb5d13 100644 --- a/lib/pddl/src/pddl/detail/normalization/Precondition.cpp +++ b/lib/pddl/src/pddl/detail/normalization/Precondition.cpp @@ -22,26 +22,28 @@ namespace detail // Forward Declarations //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::AndPointer &and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeNested(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeNested(ast::ForAllPointer &forAll, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::Literal normalizeNested(ast::ImplyPointer &, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeNested(ast::OrPointer &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::Literal normalizeTopLevel(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::Literal normalizeTopLevel(ast::ForAllPointer &forAll, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &, normalizedAST::DerivedPredicateDeclarations &); -normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); -normalizedAST::OrPointer normalizeTopLevel(ast::OrPointer &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates); +normalizedAST::Literal normalizeNested(ast::AndPointer &and_, detail::NormalizationContext &normalizationContext); +normalizedAST::Literal normalizeNested(ast::AtomicFormula &, detail::NormalizationContext &); +normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, detail::NormalizationContext &normalizationContext); +normalizedAST::Literal normalizeNested(ast::ForAllPointer &forAll, detail::NormalizationContext &); +normalizedAST::Literal normalizeNested(ast::ImplyPointer &, detail::NormalizationContext &); +normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, detail::NormalizationContext &normalizationContext); +normalizedAST::Literal normalizeNested(ast::OrPointer &or_, detail::NormalizationContext &normalizationContext); +normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &and_, detail::NormalizationContext &normalizationContext); +normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &, detail::NormalizationContext &); +normalizedAST::Literal normalizeTopLevel(ast::ExistsPointer &exists, detail::NormalizationContext &normalizationContext); +normalizedAST::Literal normalizeTopLevel(ast::ForAllPointer &forAll, detail::NormalizationContext &); +normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &, detail::NormalizationContext &); +normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer ¬_, detail::NormalizationContext &normalizationContext); +normalizedAST::OrPointer normalizeTopLevel(ast::OrPointer &or_, detail::NormalizationContext &normalizationContext); //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::DerivedPredicatePointer addDerivedPredicate(const std::vector ¶meters, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::DerivedPredicatePointer addDerivedPredicate(const std::vector ¶meters, detail::NormalizationContext &normalizationContext) { - auto name = "derived-predicate-" + std::to_string(derivedPredicates.size() + 1); + auto &derivedPredicates = normalizationContext.derivedPredicates; + const auto derivedPredicateID = normalizationContext.derivedPredicateIDStart + derivedPredicates.size() + 1; + auto name = "derived-predicate-" + std::to_string(derivedPredicateID); normalizedAST::DerivedPredicate::Arguments arguments; arguments.reserve(parameters.size()); @@ -60,14 +62,14 @@ normalizedAST::DerivedPredicatePointer addDerivedPredicate(const std::vector &and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Literal normalizeNested(ast::AndPointer &and_, detail::NormalizationContext &normalizationContext) { std::vector parameters; VariableStack variableStack; collectFreeVariables(and_, parameters, variableStack); - auto derivedPredicate = addDerivedPredicate(parameters, derivedPredicates); + auto derivedPredicate = addDerivedPredicate(parameters, normalizationContext); normalizedAST::And::Arguments normalizedArguments; normalizedArguments.reserve(and_->arguments.size()); @@ -76,7 +78,7 @@ normalizedAST::Literal normalizeNested(ast::AndPointer &and_, normalizedArguments.emplace_back(argument.match( [&](auto &x) -> normalizedAST::Literal { - return normalizeNested(x, derivedPredicates); + return normalizeNested(x, normalizationContext); })); derivedPredicate->declaration->precondition = std::make_unique>(std::move(normalizedArguments)); @@ -87,27 +89,27 @@ normalizedAST::Literal normalizeNested(ast::AndPointer &and_, //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::AtomicFormula &atomicFormula, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::Literal normalizeNested(ast::AtomicFormula &atomicFormula, detail::NormalizationContext &) { return normalize(std::move(atomicFormula)); } //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Literal normalizeNested(ast::ExistsPointer &exists, detail::NormalizationContext &normalizationContext) { std::vector parameters; VariableStack variableStack; collectFreeVariables(exists, parameters, variableStack); - auto derivedPredicate = addDerivedPredicate(parameters, derivedPredicates); + auto derivedPredicate = addDerivedPredicate(parameters, normalizationContext); derivedPredicate->declaration->existentialParameters = std::move(exists->parameters); derivedPredicate->declaration->precondition = exists->argument.match( [&](auto &x) -> normalizedAST::DerivedPredicatePrecondition { - return normalizeTopLevel(x, derivedPredicates); + return normalizeTopLevel(x, normalizationContext); }); // TODO: investigate, could be a compiler bug @@ -116,7 +118,7 @@ normalizedAST::Literal normalizeNested(ast::ExistsPointer &ex //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::ForAllPointer &, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::Literal normalizeNested(ast::ForAllPointer &, detail::NormalizationContext &) { // “forall” expressions should be reduced to negated “exists” statements at this point throw std::logic_error("precondition not in normal form (forall), please report to the bug tracker"); @@ -124,7 +126,7 @@ normalizedAST::Literal normalizeNested(ast::ForAllPointer &, //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::ImplyPointer &, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::Literal normalizeNested(ast::ImplyPointer &, detail::NormalizationContext &) { // “imply” expressions should be reduced to disjunctions at this point throw std::logic_error("precondition not in normal form (imply), please report to the bug tracker"); @@ -132,12 +134,12 @@ normalizedAST::Literal normalizeNested(ast::ImplyPointer &, n //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, detail::NormalizationContext &normalizationContext) { auto normalizedArgumentLiteral = not_->argument.match( [&](auto &x) -> normalizedAST::Literal { - return normalizeNested(x, derivedPredicates); + return normalizeNested(x, normalizationContext); }); // Multiple negations should be eliminated at this point @@ -151,14 +153,14 @@ normalizedAST::Literal normalizeNested(ast::NotPointer ¬_, //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeNested(ast::OrPointer &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Literal normalizeNested(ast::OrPointer &or_, detail::NormalizationContext &normalizationContext) { std::vector parameters; VariableStack variableStack; collectFreeVariables(or_, parameters, variableStack); - auto derivedPredicate = addDerivedPredicate(parameters, derivedPredicates); + auto derivedPredicate = addDerivedPredicate(parameters, normalizationContext); normalizedAST::Or::Arguments normalizedArguments; normalizedArguments.reserve(or_->arguments.size()); @@ -167,7 +169,7 @@ normalizedAST::Literal normalizeNested(ast::OrPointer &or_, n normalizedArguments.emplace_back(argument.match( [&](auto &x) -> normalizedAST::Literal { - return normalizeNested(x, derivedPredicates); + return normalizeNested(x, normalizationContext); })); derivedPredicate->declaration->precondition = std::make_unique>(std::move(normalizedArguments)); @@ -178,7 +180,7 @@ normalizedAST::Literal normalizeNested(ast::OrPointer &or_, n //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &atomicFormula, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &atomicFormula, detail::NormalizationContext &) { return normalize(std::move(atomicFormula)); } @@ -186,7 +188,7 @@ normalizedAST::AtomicFormula normalizeTopLevel(ast::AtomicFormula &atomicFormula //////////////////////////////////////////////////////////////////////////////////////////////////// // Normalize top-level conjunctions -normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &and_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::AndPointer normalizeTopLevel(ast::AndPointer &and_, detail::NormalizationContext &normalizationContext) { normalizedAST::And::Arguments arguments; @@ -201,13 +203,13 @@ normalizedAST::AndPointer normalizeTopLevel(ast::AndPoin const auto handleNot = [&](ast::NotPointer ¬_) -> normalizedAST::Literal { - return normalizeTopLevel(not_, derivedPredicates); + return normalizeTopLevel(not_, normalizationContext); }; const auto handleNested = [&](auto &nested) -> normalizedAST::Literal { - return normalizeNested(nested, derivedPredicates); + return normalizeNested(nested, normalizationContext); }; for (auto &argument : and_->arguments) @@ -222,21 +224,21 @@ normalizedAST::AndPointer normalizeTopLevel(ast::AndPoin //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeTopLevel(ast::ExistsPointer &exists, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Literal normalizeTopLevel(ast::ExistsPointer &exists, detail::NormalizationContext &normalizationContext) { - return normalizeNested(exists, derivedPredicates); + return normalizeNested(exists, normalizationContext); } //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeTopLevel(ast::ForAllPointer &, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::Literal normalizeTopLevel(ast::ForAllPointer &, detail::NormalizationContext &) { throw std::logic_error("precondition not in normal form (forall), please report to the bug tracker"); } //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &, normalizedAST::DerivedPredicateDeclarations &) +normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &, detail::NormalizationContext &) { throw std::logic_error("precondition not in normal form (imply), please report to the bug tracker"); } @@ -244,7 +246,7 @@ normalizedAST::Literal normalizeTopLevel(ast::ImplyPointer &, //////////////////////////////////////////////////////////////////////////////////////////////////// // Normalize top-level negations -normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer ¬_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::NotPointer normalizeTopLevel(ast::NotPointer ¬_, detail::NormalizationContext &normalizationContext) { // “not” expressions may be nested one time to form simple literals if (not_->argument.is()) @@ -253,7 +255,7 @@ normalizedAST::NotPointer normalizeTopLevel(ast::N auto normalizedArgument = not_->argument.match( [&](auto &nested) -> normalizedAST::AtomicFormula { - auto normalizedLiteral = normalizeNested(nested, derivedPredicates); + auto normalizedLiteral = normalizeNested(nested, normalizationContext); // Multiple negations should be eliminated at this point if (normalizedLiteral.template is>()) @@ -268,7 +270,7 @@ normalizedAST::NotPointer normalizeTopLevel(ast::N //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: refactor to avoid code duplication -normalizedAST::OrPointer normalizeTopLevel(ast::OrPointer &or_, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::OrPointer normalizeTopLevel(ast::OrPointer &or_, detail::NormalizationContext &normalizationContext) { normalizedAST::Or::Arguments arguments; @@ -283,13 +285,13 @@ normalizedAST::OrPointer normalizeTopLevel(ast::OrPointe const auto handleNot = [&](ast::NotPointer ¬_) -> normalizedAST::Literal { - return normalizeTopLevel(not_, derivedPredicates); + return normalizeTopLevel(not_, normalizationContext); }; const auto handleNested = [&](auto &nested) -> normalizedAST::Literal { - return normalizeNested(nested, derivedPredicates); + return normalizeNested(nested, normalizationContext); }; for (auto &argument : or_->arguments) @@ -304,7 +306,7 @@ normalizedAST::OrPointer normalizeTopLevel(ast::OrPointe //////////////////////////////////////////////////////////////////////////////////////////////////// -normalizedAST::Precondition normalize(ast::Precondition &&precondition, normalizedAST::DerivedPredicateDeclarations &derivedPredicates) +normalizedAST::Precondition normalize(ast::Precondition &&precondition, detail::NormalizationContext &normalizationContext) { // Bring precondition to normal form reduce(precondition); @@ -312,43 +314,43 @@ normalizedAST::Precondition normalize(ast::Precondition &&precondition, normaliz const auto handleAtomicFormula = [&](ast::AtomicFormula &atomicFormula) -> normalizedAST::Precondition { - return normalizeTopLevel(atomicFormula, derivedPredicates); + return normalizeTopLevel(atomicFormula, normalizationContext); }; const auto handleAnd = [&](ast::AndPointer &and_) -> normalizedAST::Precondition { - return normalizeTopLevel(and_, derivedPredicates); + return normalizeTopLevel(and_, normalizationContext); }; const auto handleExists = [&](ast::ExistsPointer &exists) -> normalizedAST::Precondition { - return normalizeTopLevel(exists, derivedPredicates); + return normalizeTopLevel(exists, normalizationContext); }; const auto handleForAll = [&](ast::ForAllPointer &forAll) -> normalizedAST::Precondition { - return normalizeTopLevel(forAll, derivedPredicates); + return normalizeTopLevel(forAll, normalizationContext); }; const auto handleImply = [&](ast::ImplyPointer &imply) -> normalizedAST::Precondition { - return normalizeTopLevel(imply, derivedPredicates); + return normalizeTopLevel(imply, normalizationContext); }; const auto handleNot = [&](ast::NotPointer ¬_) -> normalizedAST::Precondition { - return normalizeTopLevel(not_, derivedPredicates); + return normalizeTopLevel(not_, normalizationContext); }; const auto handleOr = [&](ast::OrPointer &or_) -> normalizedAST::Precondition { - return normalizeNested(or_, derivedPredicates); + return normalizeNested(or_, normalizationContext); }; return precondition.match(handleAtomicFormula, handleAnd, handleExists, handleForAll, handleImply, handleNot, handleOr); diff --git a/lib/pddl/src/pddl/detail/normalization/Problem.cpp b/lib/pddl/src/pddl/detail/normalization/Problem.cpp index 45ddf3e..5984141 100644 --- a/lib/pddl/src/pddl/detail/normalization/Problem.cpp +++ b/lib/pddl/src/pddl/detail/normalization/Problem.cpp @@ -25,7 +25,12 @@ normalizedAST::ProblemPointer normalize(ast::ProblemPointer &&problem, normalize normalizedProblem->initialState = normalize(std::move(problem->initialState)); if (problem->goal) - normalizedProblem->goal = normalize(std::move(problem->goal.value()), normalizedProblem->derivedPredicates); + { + NormalizationContext normalizationContext(normalizedProblem->derivedPredicates); + normalizationContext.derivedPredicateIDStart = domain->derivedPredicates.size() + 1; + + normalizedProblem->goal = normalize(std::move(problem->goal.value()), normalizationContext); + } return normalizedProblem; }