Parsing goal section of PDDL problem specifications.

This commit is contained in:
Patrick Lühne 2016-06-09 22:54:39 +02:00
parent 15061f75a9
commit 85444f235b
2 changed files with 47 additions and 3 deletions

View File

@ -40,6 +40,8 @@ class Problem
InitialState &initialState(); InitialState &initialState();
const InitialState &initialState() const; const InitialState &initialState() const;
const Expression &goal() const;
void checkConsistency(); void checkConsistency();
private: private:
@ -52,6 +54,8 @@ class Problem
void parseInitialStateSection(); void parseInitialStateSection();
void parseGoalSection();
Context &m_context; Context &m_context;
Domain &m_domain; Domain &m_domain;
@ -67,6 +71,9 @@ class Problem
utils::Parser::Position m_initialStatePosition; utils::Parser::Position m_initialStatePosition;
std::unique_ptr<InitialState> m_initialState; std::unique_ptr<InitialState> m_initialState;
utils::Parser::Position m_goalPosition;
ExpressionPointer m_goal;
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -3,6 +3,7 @@
#include <algorithm> #include <algorithm>
#include <plasp/pddl/Domain.h> #include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/Identifier.h> #include <plasp/pddl/Identifier.h>
#include <plasp/pddl/IO.h> #include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h> #include <plasp/pddl/expressions/Constant.h>
@ -26,7 +27,8 @@ Problem::Problem(Context &context, Domain &domain)
m_domainPosition{-1}, m_domainPosition{-1},
m_requirementsPosition{-1}, m_requirementsPosition{-1},
m_objectsPosition{-1}, m_objectsPosition{-1},
m_initialStatePosition{-1} m_initialStatePosition{-1},
m_goalPosition{-1}
{ {
} }
@ -79,8 +81,9 @@ void Problem::findSections()
setSectionPosition("objects", m_objectsPosition, position, true); setSectionPosition("objects", m_objectsPosition, position, true);
else if (parser.probeIdentifier("init", isIdentifier)) else if (parser.probeIdentifier("init", isIdentifier))
setSectionPosition("init", m_initialStatePosition, position, true); setSectionPosition("init", m_initialStatePosition, position, true);
else if (parser.probeIdentifier("goal", isIdentifier) else if (parser.probeIdentifier("goal", isIdentifier))
|| parser.probeIdentifier("constraints", isIdentifier) setSectionPosition("goal", m_goalPosition, position, true);
else if (parser.probeIdentifier("constraints", isIdentifier)
|| parser.probeIdentifier("metric", isIdentifier) || parser.probeIdentifier("metric", isIdentifier)
|| parser.probeIdentifier("length", isIdentifier)) || parser.probeIdentifier("length", isIdentifier))
{ {
@ -138,6 +141,12 @@ void Problem::parse()
parser.seek(m_initialStatePosition); parser.seek(m_initialStatePosition);
parseInitialStateSection(); parseInitialStateSection();
if (m_goalPosition == -1)
throw ConsistencyException("Problem description does not specify a goal");
parser.seek(m_goalPosition);
parseGoalSection();
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -332,6 +341,25 @@ void Problem::parseInitialStateSection()
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
void Problem::parseGoalSection()
{
auto &parser = m_context.parser;
parser.expect<std::string>("(");
parser.expect<std::string>(":");
parser.expect<std::string>("goal");
expressions::Variables noParameters;
ExpressionContext expressionContext(m_domain, this, noParameters);
m_goal = parsePreconditionExpression(m_context, expressionContext);
parser.expect<std::string>(")");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
InitialState &Problem::initialState() InitialState &Problem::initialState()
{ {
BOOST_ASSERT(m_initialState); BOOST_ASSERT(m_initialState);
@ -350,6 +378,15 @@ const InitialState &Problem::initialState() const
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
const Expression &Problem::goal() const
{
BOOST_ASSERT(m_goal);
return *m_goal;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Problem::checkConsistency() void Problem::checkConsistency()
{ {
} }