Moved initial state translation to new header.

This commit is contained in:
Patrick Lühne 2017-10-27 16:36:01 +02:00
parent 6415f871d7
commit 6d07fcbd6c
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 71 additions and 44 deletions

View File

@ -0,0 +1,69 @@
#ifndef __PLASP__PDDL__TRANSLATION__FACT_H
#define __PLASP__PDDL__TRANSLATION__FACT_H
#include <pddl/NormalizedAST.h>
#include <plasp/TranslatorException.h>
#include <plasp/pddl/translation/Predicate.h>
namespace plasp
{
namespace pddl
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Fact
//
////////////////////////////////////////////////////////////////////////////////////////////////////
inline void translateFact(colorlog::ColorStream &outputStream, const ::pddl::normalizedAST::Fact &fact)
{
outputStream << std::endl << colorlog::Function("initialState") << "(";
const auto handlePredicate =
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
{
translatePredicateToVariable(outputStream, *predicate, isPositive);
};
const auto handleNegatedPredicate =
[&](const ::pddl::normalizedAST::PredicatePointer &predicate)
{
return handlePredicate(predicate, false);
};
const auto handleDerivedPredicate =
[&](const ::pddl::normalizedAST::DerivedPredicatePointer &, bool = true)
{
throw TranslatorException("derived predicates should not occur in initial state");
};
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::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> &not_)
{
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
};
fact.match(handleAtomicFormula, handleNot);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -11,6 +11,7 @@
#include <plasp/pddl/translation/DerivedPredicate.h>
#include <plasp/pddl/translation/DerivedPredicatePrecondition.h>
#include <plasp/pddl/translation/Effect.h>
#include <plasp/pddl/translation/Fact.h>
#include <plasp/pddl/translation/Goal.h>
#include <plasp/pddl/translation/Precondition.h>
#include <plasp/pddl/translation/Predicate.h>
@ -436,51 +437,8 @@ void TranslatorASP::translateInitialState() const
const auto &facts = m_description.problem.value()->initialState.facts;
// TODO: move to separate header
for (const auto &fact : facts)
{
m_outputStream << std::endl << colorlog::Function("initialState") << "(";
const auto handlePredicate =
[&](const ::pddl::normalizedAST::PredicatePointer &predicate, bool isPositive = true)
{
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)
{
throw TranslatorException("derived predicates should not occur in initial state");
};
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::normalizedAST::NotPointer<::pddl::normalizedAST::AtomicFormula> &not_)
{
not_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
};
fact.match(handleAtomicFormula, handleNot);
m_outputStream << ").";
}
::plasp::pddl::translateFact(m_outputStream, fact);
m_outputStream
<< std::endl << std::endl