diff --git a/include/plasp/pddl/Requirement.h b/include/plasp/pddl/Requirement.h index b0831ea..159c1ae 100644 --- a/include/plasp/pddl/Requirement.h +++ b/include/plasp/pddl/Requirement.h @@ -1,6 +1,8 @@ #ifndef __PLASP__PDDL__REQUIREMENT_H #define __PLASP__PDDL__REQUIREMENT_H +#include + namespace plasp { namespace pddl @@ -12,28 +14,36 @@ namespace pddl // //////////////////////////////////////////////////////////////////////////////////////////////////// -enum class Requirement +struct Requirement { - STRIPS, - Typing, - NegativePreconditions, - DisjunctivePreconditions, - Equality, - ExistentialPreconditions, - UniversalPreconditions, - QuantifiedPreconditions, - ConditionalEffects, - Fluents, - NumericFluents, - ADL, - DurativeActions, - DurationInequalities, - ContinuousEffects, - DerivedPredicates, - TimedInitialLiterals, - Preferences, - Constraints, - ActionCosts + enum class Type + { + STRIPS, + Typing, + NegativePreconditions, + DisjunctivePreconditions, + Equality, + ExistentialPreconditions, + UniversalPreconditions, + QuantifiedPreconditions, + ConditionalEffects, + Fluents, + NumericFluents, + ADL, + DurativeActions, + DurationInequalities, + ContinuousEffects, + DerivedPredicates, + TimedInitialLiterals, + 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); }; //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/pddl/Requirement.cpp b/src/plasp/pddl/Requirement.cpp new file mode 100644 index 0000000..ec8c168 --- /dev/null +++ b/src/plasp/pddl/Requirement.cpp @@ -0,0 +1,110 @@ +#include + +#include +#include +#include + +#include +#include + +namespace plasp +{ +namespace pddl +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Requirement +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +using RequirementTypeNames = boost::bimap; + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +const RequirementTypeNames requirementTypesToPDDL = boost::assign::list_of + (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 + (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; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}