Added translation of a PDDL problem’s initial state.
This commit is contained in:
parent
d3dc9101dd
commit
e9c464b319
@ -34,6 +34,7 @@ class TranslatorASP
|
|||||||
|
|
||||||
void translateProblem() const;
|
void translateProblem() const;
|
||||||
void translateObjects() const;
|
void translateObjects() const;
|
||||||
|
void translateInitialState() const;
|
||||||
|
|
||||||
void translateVariablesHead(const expressions::Variables &variables) const;
|
void translateVariablesHead(const expressions::Variables &variables) const;
|
||||||
void translateVariablesBody(const expressions::Variables &variables) const;
|
void translateVariablesBody(const expressions::Variables &variables) const;
|
||||||
|
@ -464,6 +464,10 @@ void TranslatorASP::translateProblem() const
|
|||||||
m_ostream << std::endl;
|
m_ostream << std::endl;
|
||||||
translateObjects();
|
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 ¬Expression = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user