Moved initial state translation to new header.
This commit is contained in:
parent
6415f871d7
commit
6d07fcbd6c
69
include/plasp/pddl/translation/Fact.h
Normal file
69
include/plasp/pddl/translation/Fact.h
Normal 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_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
fact.match(handleAtomicFormula, handleNot);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -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_->argument.match(handleNegatedPredicate, handleNegatedDerivedPredicate);
|
||||
};
|
||||
|
||||
fact.match(handleAtomicFormula, handleNot);
|
||||
|
||||
m_outputStream << ").";
|
||||
}
|
||||
::plasp::pddl::translateFact(m_outputStream, fact);
|
||||
|
||||
m_outputStream
|
||||
<< std::endl << std::endl
|
||||
|
Reference in New Issue
Block a user