Parsing goal section of PDDL problem specifications.
This commit is contained in:
parent
15061f75a9
commit
85444f235b
@ -40,6 +40,8 @@ class Problem
|
||||
InitialState &initialState();
|
||||
const InitialState &initialState() const;
|
||||
|
||||
const Expression &goal() const;
|
||||
|
||||
void checkConsistency();
|
||||
|
||||
private:
|
||||
@ -52,6 +54,8 @@ class Problem
|
||||
|
||||
void parseInitialStateSection();
|
||||
|
||||
void parseGoalSection();
|
||||
|
||||
Context &m_context;
|
||||
Domain &m_domain;
|
||||
|
||||
@ -67,6 +71,9 @@ class Problem
|
||||
|
||||
utils::Parser::Position m_initialStatePosition;
|
||||
std::unique_ptr<InitialState> m_initialState;
|
||||
|
||||
utils::Parser::Position m_goalPosition;
|
||||
ExpressionPointer m_goal;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <plasp/pddl/Domain.h>
|
||||
#include <plasp/pddl/ExpressionContext.h>
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/pddl/IO.h>
|
||||
#include <plasp/pddl/expressions/Constant.h>
|
||||
@ -26,7 +27,8 @@ Problem::Problem(Context &context, Domain &domain)
|
||||
m_domainPosition{-1},
|
||||
m_requirementsPosition{-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);
|
||||
else if (parser.probeIdentifier("init", isIdentifier))
|
||||
setSectionPosition("init", m_initialStatePosition, position, true);
|
||||
else if (parser.probeIdentifier("goal", isIdentifier)
|
||||
|| parser.probeIdentifier("constraints", isIdentifier)
|
||||
else if (parser.probeIdentifier("goal", isIdentifier))
|
||||
setSectionPosition("goal", m_goalPosition, position, true);
|
||||
else if (parser.probeIdentifier("constraints", isIdentifier)
|
||||
|| parser.probeIdentifier("metric", isIdentifier)
|
||||
|| parser.probeIdentifier("length", isIdentifier))
|
||||
{
|
||||
@ -138,6 +141,12 @@ void Problem::parse()
|
||||
|
||||
parser.seek(m_initialStatePosition);
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user