Added translation of a PDDL problem’s initial state.

This commit is contained in:
Patrick Lühne 2016-06-13 02:59:43 +02:00
parent d3dc9101dd
commit e9c464b319
2 changed files with 38 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class TranslatorASP
void translateProblem() const;
void translateObjects() const;
void translateInitialState() const;
void translateVariablesHead(const expressions::Variables &variables) const;
void translateVariablesBody(const expressions::Variables &variables) const;

View File

@ -464,6 +464,10 @@ void TranslatorASP::translateProblem() const
m_ostream << std::endl;
translateObjects();
}
// Initial State
m_ostream << std::endl;
translateInitialState();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -492,5 +496,38 @@ void TranslatorASP::translateObjects() const
////////////////////////////////////////////////////////////////////////////////////////////////////
void TranslatorASP::translateInitialState() const
{
m_ostream << "% initial state";
const auto &initialStateFacts = m_description.problem().initialState().facts();
std::for_each(initialStateFacts.cbegin(), initialStateFacts.cend(),
[&](const auto &fact)
{
m_ostream << std::endl << "initialState(";
// Translate single predicate
if (fact->expressionType() == Expression::Type::Predicate)
this->translatePredicate(dynamic_cast<const expressions::Predicate &>(*fact));
// Assuming that "not" expression may only contain a predicate
else if (fact->expressionType() == Expression::Type::Not)
{
const auto &notExpression = dynamic_cast<const expressions::Not &>(*fact);
if (notExpression.argument()->expressionType() != Expression::Type::Predicate)
throw utils::TranslatorException("Only negations of simple predicates supported in initial state currently");
}
else
throw utils::TranslatorException("Only predicates and their negations supported in initial state currently");
m_ostream << ").";
});
m_ostream << std::endl;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}