Implemented requirement parsing.
This commit is contained in:
parent
c191b418f2
commit
8aa419b5c2
@ -1,6 +1,8 @@
|
||||
#ifndef __PLASP__PDDL__REQUIREMENT_H
|
||||
#define __PLASP__PDDL__REQUIREMENT_H
|
||||
|
||||
#include <plasp/utils/Parser.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
@ -12,8 +14,10 @@ namespace pddl
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
enum class Requirement
|
||||
struct Requirement
|
||||
{
|
||||
enum class Type
|
||||
{
|
||||
STRIPS,
|
||||
Typing,
|
||||
NegativePreconditions,
|
||||
@ -34,6 +38,12 @@ enum class Requirement
|
||||
Preferences,
|
||||
Constraints,
|
||||
ActionCosts
|
||||
};
|
||||
|
||||
static Requirement::Type fromPDDL(utils::Parser &parser);
|
||||
|
||||
static void toPDDL(std::ostream &ostream, Requirement::Type requirementType);
|
||||
static void toASP(std::ostream &ostream, Requirement::Type requirementType);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
110
src/plasp/pddl/Requirement.cpp
Normal file
110
src/plasp/pddl/Requirement.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
#include <plasp/pddl/Requirement.h>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/bimap.hpp>
|
||||
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/utils/ParserException.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
namespace pddl
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Requirement
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using RequirementTypeNames = boost::bimap<Requirement::Type, const char *>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const RequirementTypeNames requirementTypesToPDDL = boost::assign::list_of<RequirementTypeNames::relation>
|
||||
(Requirement::Type::STRIPS, "strips")
|
||||
(Requirement::Type::Typing, "typing")
|
||||
(Requirement::Type::NegativePreconditions, "negative-preconditions")
|
||||
(Requirement::Type::DisjunctivePreconditions, "disjunctive-preconditions")
|
||||
(Requirement::Type::Equality, "equality")
|
||||
(Requirement::Type::ExistentialPreconditions, "existential-preconditions")
|
||||
(Requirement::Type::UniversalPreconditions, "universal-preconditions")
|
||||
(Requirement::Type::QuantifiedPreconditions, "quantified-preconditions")
|
||||
(Requirement::Type::ConditionalEffects, "conditional-effects")
|
||||
(Requirement::Type::Fluents, "fluents")
|
||||
(Requirement::Type::NumericFluents, "numeric-fluents")
|
||||
(Requirement::Type::ADL, "adl")
|
||||
(Requirement::Type::DurativeActions, "durative-actions")
|
||||
(Requirement::Type::DurationInequalities, "duration-inequalities")
|
||||
(Requirement::Type::ContinuousEffects, "continuous-effects")
|
||||
(Requirement::Type::DerivedPredicates, "derived-predicates")
|
||||
(Requirement::Type::TimedInitialLiterals, "timed-initial-literals")
|
||||
(Requirement::Type::Preferences, "preferences")
|
||||
(Requirement::Type::Constraints, "constraints")
|
||||
(Requirement::Type::ActionCosts, "action-costs");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const RequirementTypeNames requirementTypesToASP = boost::assign::list_of<RequirementTypeNames::relation>
|
||||
(Requirement::Type::STRIPS, "strips")
|
||||
(Requirement::Type::Typing, "typing")
|
||||
(Requirement::Type::NegativePreconditions, "negativePreconditions")
|
||||
(Requirement::Type::DisjunctivePreconditions, "disjunctivePreconditions")
|
||||
(Requirement::Type::Equality, "equality")
|
||||
(Requirement::Type::ExistentialPreconditions, "existentialPreconditions")
|
||||
(Requirement::Type::UniversalPreconditions, "universalPreconditions")
|
||||
(Requirement::Type::QuantifiedPreconditions, "quantifiedPreconditions")
|
||||
(Requirement::Type::ConditionalEffects, "conditionalEffects")
|
||||
(Requirement::Type::Fluents, "fluents")
|
||||
(Requirement::Type::NumericFluents, "numericFluents")
|
||||
(Requirement::Type::ADL, "adl")
|
||||
(Requirement::Type::DurativeActions, "durativeActions")
|
||||
(Requirement::Type::DurationInequalities, "durationInequalities")
|
||||
(Requirement::Type::ContinuousEffects, "continuousEffects")
|
||||
(Requirement::Type::DerivedPredicates, "derivedPredicates")
|
||||
(Requirement::Type::TimedInitialLiterals, "timedInitialLiterals")
|
||||
(Requirement::Type::Preferences, "preferences")
|
||||
(Requirement::Type::Constraints, "constraints")
|
||||
(Requirement::Type::ActionCosts, "actionCosts");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Requirement::Type Requirement::fromPDDL(utils::Parser &parser)
|
||||
{
|
||||
const auto requirementName = parser.parseIdentifier(isIdentifier);
|
||||
|
||||
const auto match = requirementTypesToPDDL.right.find(requirementName.c_str());
|
||||
|
||||
if (match == requirementTypesToPDDL.right.end())
|
||||
throw utils::ParserException(parser.row(), parser.column(), "Could not parse requirement");
|
||||
|
||||
return match->second;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Requirement::toPDDL(std::ostream &ostream, Requirement::Type requirementType)
|
||||
{
|
||||
const auto match = requirementTypesToPDDL.left.find(requirementType);
|
||||
|
||||
BOOST_ASSERT(match != requirementTypesToPDDL.left.end());
|
||||
|
||||
ostream << match->second;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Requirement::toASP(std::ostream &ostream, Requirement::Type requirementType)
|
||||
{
|
||||
const auto match = requirementTypesToASP.left.find(requirementType);
|
||||
|
||||
BOOST_ASSERT(match != requirementTypesToASP.left.end());
|
||||
|
||||
ostream << match->second;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user