diff --git a/include/loki/details/ast/ast.hpp b/include/loki/details/ast/ast.hpp index 58799bb4..2c367560 100644 --- a/include/loki/details/ast/ast.hpp +++ b/include/loki/details/ast/ast.hpp @@ -150,15 +150,12 @@ struct AssignOperator; struct Effect; struct EffectProductionLiteral; -struct EffectProductionNumericFluentTotalCost; -struct EffectProductionNumericFluentGeneral; +struct EffectProductionNumeric; struct EffectProduction; struct EffectCompositeForall; struct EffectCompositeWhen; struct EffectCompositeOneof; struct EffectComposite; -struct EffectNumericFluentTotalCostOrEffect; -struct EffectRoot; struct ActionSymbol; struct ActionBody; @@ -826,47 +823,32 @@ struct AssignOperator : }; /* */ -// -// struct EffectRoot : -// x3::position_tagged, -// x3::variant, x3::forward_ast, x3::forward_ast>, -// std::vector>> -//{ -// using base_type::base_type; -// using base_type::operator=; -//}; - struct Effect : x3::position_tagged, x3::variant, x3::forward_ast, std::vector> { using base_type::base_type; using base_type::operator=; }; +// Production effects struct EffectProductionLiteral : x3::position_tagged { Literal literal; }; -struct EffectProductionNumericFluentTotalCost : x3::position_tagged -{ - AssignOperatorIncrease assign_operator_increase; - FunctionSymbol function_symbol_total_cost; - FunctionExpression numeric_term; -}; - -struct EffectProductionNumericFluentGeneral : x3::position_tagged +struct EffectProductionNumeric : x3::position_tagged { AssignOperator assign_operator; FunctionHead function_head; FunctionExpression function_expression; }; -struct EffectProduction : x3::position_tagged, x3::variant +struct EffectProduction : x3::position_tagged, x3::variant { using base_type::base_type; using base_type::operator=; }; +// Composite effects struct EffectCompositeForall : x3::position_tagged { TypedListOfVariables typed_list_of_variables; @@ -881,7 +863,7 @@ struct EffectCompositeWhen : x3::position_tagged struct EffectCompositeOneof : x3::position_tagged { - std::vector possibilities; + std::vector possibilities; }; struct EffectComposite : x3::position_tagged, x3::variant @@ -890,20 +872,6 @@ struct EffectComposite : x3::position_tagged, x3::variant -{ - using base_type::base_type; - using base_type::operator=; -}; - -struct EffectRoot: - x3::position_tagged, - x3::variant> -{ - using base_type::base_type; - using base_type::operator=; -}; - /* */ struct ActionSymbol : x3::position_tagged { @@ -913,7 +881,7 @@ struct ActionSymbol : x3::position_tagged struct ActionBody : x3::position_tagged { boost::optional precondition_goal_descriptor; - boost::optional effect; + boost::optional effect; }; struct Action : x3::position_tagged diff --git a/include/loki/details/ast/printer.hpp b/include/loki/details/ast/printer.hpp index 616c4235..423c61cf 100644 --- a/include/loki/details/ast/printer.hpp +++ b/include/loki/details/ast/printer.hpp @@ -150,15 +150,12 @@ extern std::string parse_text(const ast::AssignOperator& node, const DefaultForm extern std::string parse_text(const ast::Effect& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectProductionLiteral& node, const DefaultFormatterOptions& options = {}); -extern std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const DefaultFormatterOptions& options = {}); -extern std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const DefaultFormatterOptions& options = {}); +extern std::string parse_text(const ast::EffectProductionNumeric& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectProduction& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectCompositeForall& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectCompositeWhen& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectCompositeOneof& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::EffectComposite& node, const DefaultFormatterOptions& options = {}); -extern std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const DefaultFormatterOptions& options = {}); -extern std::string parse_text(const ast::EffectRoot& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::ActionSymbol& node, const DefaultFormatterOptions& options = {}); extern std::string parse_text(const ast::ActionBody& node, const DefaultFormatterOptions& options = {}); diff --git a/src/ast/ast_adapted.hpp b/src/ast/ast_adapted.hpp index 56ebb3bc..acdffd8c 100644 --- a/src/ast/ast_adapted.hpp +++ b/src/ast/ast_adapted.hpp @@ -90,8 +90,7 @@ BOOST_FUSION_ADAPT_STRUCT(loki::ast::PreconditionGoalDescriptorPreference, prefe BOOST_FUSION_ADAPT_STRUCT(loki::ast::PreconditionGoalDescriptorForall, typed_list_of_variables, precondition_goal_descriptor) BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectProductionLiteral, literal) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectProductionNumericFluentTotalCost, assign_operator_increase, function_symbol_total_cost, numeric_term) -BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectProductionNumericFluentGeneral, assign_operator, function_head, function_expression) +BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectProductionNumeric, assign_operator, function_head, function_expression) BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectCompositeForall, typed_list_of_variables, effect) BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectCompositeWhen, goal_descriptor, effect) BOOST_FUSION_ADAPT_STRUCT(loki::ast::EffectCompositeOneof, possibilities) diff --git a/src/ast/parser.hpp b/src/ast/parser.hpp index 0871a7bb..ecb68e8e 100644 --- a/src/ast/parser.hpp +++ b/src/ast/parser.hpp @@ -166,15 +166,12 @@ struct NumericTermClass; struct EffectClass; struct EffectProductionLiteralClass; -struct EffectProductionNumericFluentTotalCostClass; -struct EffectProductionNumericFluentGeneralClass; +struct EffectProductionNumericClass; struct EffectProductionClass; struct EffectCompositeForallClass; struct EffectCompositeWhenClass; struct EffectCompositeOneofClass; struct EffectCompositeClass; -struct EffectNumericFluentTotalCostOrEffectClass; -struct EffectRootClass; struct ActionSymbolClass; struct ActionBodyClass; struct ActionClass; @@ -367,15 +364,12 @@ typedef x3::rule numeric_term_type; typedef x3::rule effect_type; typedef x3::rule effect_production_literal_type; -typedef x3::rule effect_production_numeric_fluent_total_cost_type; -typedef x3::rule effect_production_numeric_fluent_general_type; +typedef x3::rule effect_production_numeric_type; typedef x3::rule effect_production_type; typedef x3::rule effect_composite_forall_type; typedef x3::rule effect_composite_when_type; typedef x3::rule effect_composite_oneof_type; typedef x3::rule effect_composite_type; -typedef x3::rule effect_root_type; -typedef x3::rule effect_numeric_fluent_total_cost_or_effect_type; typedef x3::rule action_symbol_type; typedef x3::rule action_body_type; @@ -561,15 +555,12 @@ BOOST_SPIRIT_DECLARE(numeric_term_type) BOOST_SPIRIT_DECLARE(effect_type, effect_production_literal_type, - effect_production_numeric_fluent_total_cost_type, - effect_production_numeric_fluent_general_type, + effect_production_numeric_type, effect_production_type, effect_composite_forall_type, effect_composite_when_type, effect_composite_oneof_type, effect_composite_type, - effect_numeric_fluent_total_cost_or_effect_type, - effect_root_type, action_symbol_type, action_body_type, action_type, @@ -756,15 +747,12 @@ parser::numeric_term_type const& numeric_term(); parser::effect_type const& effect(); parser::effect_production_literal_type const& effect_production_literal(); -parser::effect_production_numeric_fluent_total_cost_type const& effect_production_numeric_fluent_total_cost(); -parser::effect_production_numeric_fluent_general_type const& effect_production_numeric_fluent_general(); +parser::effect_production_numeric_type const& effect_production_numeric(); parser::effect_production_type const& effect_production(); -parser::effect_composite_forall_type const& effect_omposite_forall(); +parser::effect_composite_forall_type const& effect_composite_forall(); parser::effect_composite_when_type const& effect_composite_when(); parser::effect_composite_oneof_type const& effect_composite_oneof(); parser::effect_composite_type const& effect_composite(); -parser::effect_numeric_fluent_total_cost_or_effect_type const& effect_numeric_fluent_total_cost_or_effect(); -parser::effect_root_type const& effect_root(); parser::action_symbol_type const& action_symbol(); parser::action_body_type const& action_body(); diff --git a/src/ast/parser_def.hpp b/src/ast/parser_def.hpp index 761b2749..634d1d91 100644 --- a/src/ast/parser_def.hpp +++ b/src/ast/parser_def.hpp @@ -182,15 +182,12 @@ numeric_term_type const numeric_term = "numeric_term"; effect_type const effect = "effect"; effect_production_literal_type const effect_production_literal = "effect_production_literal"; -effect_production_numeric_fluent_total_cost_type const effect_production_numeric_fluent_total_cost = "effect_production_numeric_fluent_total_cost"; -effect_production_numeric_fluent_general_type const effect_production_numeric_fluent_general = "effect_production_numeric_fluent_general"; +effect_production_numeric_type const effect_production_numeric = "effect_production_numeric"; effect_production_type const effect_production = "effect_production"; effect_composite_forall_type const effect_composite_forall = "effect_composite_forall"; effect_composite_when_type const effect_composite_when = "effect_composite_when"; effect_composite_oneof_type const effect_composite_oneof = "effect_composite_oneof"; effect_composite_type const effect_composite = "effect_composite"; -effect_numeric_fluent_total_cost_or_effect_type const effect_numeric_fluent_total_cost_or_effect = "effect_numeric_fluent_total_cost_or_effect"; -effect_root_type const effect_root = "effect_root"; action_symbol_type const action_symbol = "action_symbol"; action_body_type const action_body = "action_body"; action_type const action = "action"; @@ -297,7 +294,8 @@ const auto requirement_def = requirement_strips | requirement_typing | requireme | requirement_equality | requirement_existential_preconditions | requirement_universal_preconditions | requirement_quantified_preconditions | requirement_conditional_effects | requirement_fluents | requirement_object_fluents | requirement_numeric_fluents | requirement_adl | requirement_durative_actions | requirement_derived_predicates - | requirement_timed_initial_literals | requirement_preferences | requirement_constraints | requirement_action_costs | requirement_non_deterministic; + | requirement_timed_initial_literals | requirement_preferences | requirement_constraints | requirement_action_costs + | requirement_non_deterministic; const auto type_def = type_object | type_number | type_either | name; const auto type_object_def = keyword_lit("object") > x3::attr(ast::TypeObject {}); @@ -398,15 +396,10 @@ const auto assign_operator_def = // For action cost effects only const auto numeric_term_def = function_expression_number | function_expression_head; -const auto effect_root_def = ((lit('(') >> keyword_lit("and")) > *effect_numeric_fluent_total_cost_or_effect > lit(')')) | effect_composite - | effect_production | effect_production_numeric_fluent_total_cost; const auto effect_def = ((lit('(') >> keyword_lit("and")) > *effect > lit(')')) | effect_composite | effect_production; -const auto effect_numeric_fluent_total_cost_or_effect_def = effect_production_numeric_fluent_total_cost | effect; const auto effect_production_literal_def = literal; -const auto effect_production_numeric_fluent_total_cost_def = (lit('(') >> assign_operator_increase >> lit('(') >> function_symbol_total_cost) > lit(')') - > numeric_term > lit(')'); -const auto effect_production_numeric_fluent_general_def = (lit('(') >> assign_operator >> function_head >> function_expression) > lit(')'); -const auto effect_production_def = effect_production_numeric_fluent_general | effect_production_literal; +const auto effect_production_numeric_def = (lit('(') >> assign_operator >> function_head >> function_expression) > lit(')'); +const auto effect_production_def = effect_production_numeric | effect_production_literal; const auto effect_composite_forall_def = (lit('(') >> keyword_lit("forall")) > lit("(") > typed_list_of_variables > lit(')') > effect > lit(')'); const auto effect_composite_when_def = (lit('(') >> keyword_lit("when")) > goal_descriptor > effect > lit(')'); const auto effect_composite_oneof_def = (lit('(') >> keyword_lit("oneof")) > *effect > lit(')'); @@ -414,7 +407,7 @@ const auto effect_composite_def = effect_composite_forall | effect_composite_whe const auto action_symbol_def = name; const auto action_body_def = -(keyword_lit(":precondition") > ((lit('(') >> lit(')')) | precondition_goal_descriptor)) - > -(keyword_lit(":effect") > ((lit('(') >> lit(')')) | effect_root)); + > -(keyword_lit(":effect") > ((lit('(') >> lit(')')) | effect)); const auto action_def = (lit('(') >> keyword_lit(":action")) > action_symbol > keyword_lit(":parameters") > lit('(') > typed_list_of_variables > lit(')') > action_body > lit(')'); @@ -599,15 +592,12 @@ BOOST_SPIRIT_DEFINE(numeric_term) BOOST_SPIRIT_DEFINE(effect, effect_production_literal, - effect_production_numeric_fluent_total_cost, - effect_production_numeric_fluent_general, + effect_production_numeric, effect_production, effect_composite_forall, effect_composite_when, effect_composite_oneof, effect_composite, - effect_numeric_fluent_total_cost_or_effect, - effect_root, action_symbol, action_body, action, @@ -985,10 +975,7 @@ struct EffectClass : x3::annotate_on_success struct EffectProductionLiteralClass : x3::annotate_on_success { }; -struct EffectProductionNumericFluentTotalCostClass : x3::annotate_on_success -{ -}; -struct EffectProductionNumericFluentGeneralClass : x3::annotate_on_success +struct EffectProductionNumericClass : x3::annotate_on_success { }; struct EffectProductionClass : x3::annotate_on_success @@ -1006,12 +993,6 @@ struct EffectCompositeOneofClass : x3::annotate_on_success struct EffectCompositeClass : x3::annotate_on_success { }; -struct EffectNumericFluentTotalCostOrEffectClass : x3::annotate_on_success -{ -}; -struct EffectRootClass : x3::annotate_on_success -{ -}; struct ActionSymbolClass : x3::annotate_on_success { @@ -1341,24 +1322,12 @@ parser::numeric_term_type const& numeric_term() { return parser::numeric_term; } parser::effect_type const& effect() { return parser::effect; } parser::effect_production_literal_type const& effect_production_literal() { return parser::effect_production_literal; } -parser::effect_production_numeric_fluent_total_cost_type const& effect_production_numeric_fluent_total_cost() -{ - return parser::effect_production_numeric_fluent_total_cost; -} -parser::effect_production_numeric_fluent_general_type const& effect_production_numeric_fluent_general() -{ - return parser::effect_production_numeric_fluent_general; -} +parser::effect_production_numeric_type const& effect_production_numeric() { return parser::effect_production_numeric; } parser::effect_production_type const& effect_production() { return parser::effect_production; } parser::effect_composite_forall_type const& effect_composite_forall() { return parser::effect_composite_forall; } parser::effect_composite_when_type const& effect_composite_when() { return parser::effect_composite_when; } parser::effect_composite_oneof_type const& effect_composite_oneof() { return parser::effect_composite_oneof; } parser::effect_composite_type const& effect_composite() { return parser::effect_composite; } -parser::effect_numeric_fluent_total_cost_or_effect_type const& effect_numeric_fluent_total_cost_or_effect() -{ - return parser::effect_numeric_fluent_total_cost_or_effect; -} -parser::effect_root_type const& effect_root() { return parser::effect_root; } parser::action_symbol_type const& action_symbol() { return parser::action_symbol; } parser::action_body_type const& action_body() { return parser::action_body; } diff --git a/src/ast/parser_instantiations.cpp b/src/ast/parser_instantiations.cpp index c6749a59..d123c8be 100644 --- a/src/ast/parser_instantiations.cpp +++ b/src/ast/parser_instantiations.cpp @@ -147,15 +147,12 @@ BOOST_SPIRIT_INSTANTIATE(numeric_term_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_production_literal_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(effect_production_numeric_fluent_total_cost_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(effect_production_numeric_fluent_general_type, iterator_type, context_type) +BOOST_SPIRIT_INSTANTIATE(effect_production_numeric_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_production_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_composite_forall_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_composite_when_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_composite_oneof_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(effect_composite_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(effect_numeric_fluent_total_cost_or_effect_type, iterator_type, context_type) -BOOST_SPIRIT_INSTANTIATE(effect_root_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(action_symbol_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE(action_body_type, iterator_type, context_type) diff --git a/src/ast/printer.cpp b/src/ast/printer.cpp index afec063d..a514ceca 100644 --- a/src/ast/printer.cpp +++ b/src/ast/printer.cpp @@ -501,15 +501,7 @@ std::string parse_text(const ast::Effect& node, const DefaultFormatterOptions& o std::string parse_text(const ast::EffectProductionLiteral& node, const DefaultFormatterOptions& options) { return parse_text(node.literal, options); } -std::string parse_text(const ast::EffectProductionNumericFluentTotalCost& node, const DefaultFormatterOptions& options) -{ - std::stringstream ss; - ss << "(" << parse_text(node.assign_operator_increase, options) << " " << parse_text(node.function_symbol_total_cost, options) << " " - << parse_text(node.numeric_term, options) << ")"; - return ss.str(); -} - -std::string parse_text(const ast::EffectProductionNumericFluentGeneral& node, const DefaultFormatterOptions& options) +std::string parse_text(const ast::EffectProductionNumeric& node, const DefaultFormatterOptions& options) { std::stringstream ss; ss << "(" << parse_text(node.assign_operator, options) << " " << parse_text(node.function_head, options) << " " @@ -548,13 +540,6 @@ std::string parse_text(const ast::EffectComposite& node, const DefaultFormatterO return boost::apply_visitor(NodeVisitorPrinter(options), node); } -std::string parse_text(const ast::EffectNumericFluentTotalCostOrEffect& node, const DefaultFormatterOptions& options) -{ - return boost::apply_visitor(NodeVisitorPrinter(options), node); -} - -std::string parse_text(const ast::EffectRoot& node, const DefaultFormatterOptions& options) { return boost::apply_visitor(NodeVisitorPrinter(options), node); } - std::string parse_text(const ast::ActionSymbol& node, const DefaultFormatterOptions& options) { return parse_text(node.name, options); } std::string parse_text(const ast::ActionBody& node, const DefaultFormatterOptions& options) diff --git a/src/pddl/parser/effects.cpp b/src/pddl/parser/effects.cpp index 654e44a5..df564754 100644 --- a/src/pddl/parser/effects.cpp +++ b/src/pddl/parser/effects.cpp @@ -41,16 +41,6 @@ AssignOperatorEnum parse(const ast::AssignOperatorDecrease&) { return AssignOper AssignOperatorEnum parse(const ast::AssignOperator& node) { return boost::apply_visitor(AssignOperatorVisitor(), node); } -Effect parse(const std::vector& effect_nodes, Context& context) -{ - auto effect_list = EffectList(); - for (const auto& effect_node : effect_nodes) - { - effect_list.push_back(boost::apply_visitor(EffectVisitor(context), effect_node)); - } - return context.factories.get_or_create_effect(context.factories.get_or_create_effect_and(effect_list)); -} - Effect parse(const std::vector& effect_nodes, Context& context) { auto effect_list = EffectList(); @@ -61,8 +51,6 @@ Effect parse(const std::vector& effect_nodes, Context& context) return context.factories.get_or_create_effect(context.factories.get_or_create_effect_and(effect_list)); } -Effect parse(const ast::EffectRoot& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } - Effect parse(const ast::Effect& node, Context& context) { return boost::apply_visitor(EffectVisitor(context), node); } Effect parse(const ast::EffectProductionLiteral& node, Context& context) @@ -74,29 +62,20 @@ Effect parse(const ast::EffectProductionLiteral& node, Context& context) return effect; } -Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context) +Effect parse(const ast::EffectProductionNumeric& node, Context& context) { - test_undefined_requirement(RequirementEnum::ACTION_COSTS, node, context); - context.references.untrack(RequirementEnum::ACTION_COSTS); - const auto assign_operator_increase = parse(node.assign_operator_increase); - auto function_name = parse(node.function_symbol_total_cost.name); - assert(function_name == "total-cost"); - test_undefined_function_skeleton(function_name, node.function_symbol_total_cost, context); - auto binding = context.scopes.top().get_function_skeleton(function_name); - const auto [function_skeleton, _position, _error_handler] = binding.value(); - const auto function = context.factories.get_or_create_function(function_skeleton, TermList {}); - context.references.untrack(function->get_function_skeleton()); - const auto function_expression = boost::apply_visitor(FunctionExpressionVisitor(context), node.numeric_term); - const auto effect = - context.factories.get_or_create_effect(context.factories.get_or_create_effect_numeric(assign_operator_increase, function, function_expression)); - context.positions.push_back(effect, node); - return effect; -} - -Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context) -{ - test_undefined_requirement(RequirementEnum::NUMERIC_FLUENTS, node, context); - context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); + // "total-cost" explicitly requires :action-costs to be the specified in the requirements section. + if (node.function_head.function_symbol.name.characters == "total-cost") + { + test_undefined_requirement(RequirementEnum::ACTION_COSTS, node, context); + context.references.untrack(RequirementEnum::ACTION_COSTS); + } + // all remaining function heads require :numeric-fluents to be specified in the requirements section. + else + { + test_undefined_requirement(RequirementEnum::NUMERIC_FLUENTS, node, context); + context.references.untrack(RequirementEnum::NUMERIC_FLUENTS); + } const auto assign_operator = parse(node.assign_operator); const auto function = parse(node.function_head, context); context.references.untrack(function->get_function_skeleton()); diff --git a/src/pddl/parser/effects.hpp b/src/pddl/parser/effects.hpp index 1424cc4b..a4704b07 100644 --- a/src/pddl/parser/effects.hpp +++ b/src/pddl/parser/effects.hpp @@ -46,13 +46,10 @@ struct AssignOperatorVisitor : boost::static_visitor }; /* Effects */ -extern Effect parse(const std::vector& effect_nodes, Context& context); extern Effect parse(const std::vector& effect_nodes, Context& context); -extern Effect parse(const ast::EffectRoot& node, Context& context); extern Effect parse(const ast::Effect& node, Context& context); extern Effect parse(const ast::EffectProductionLiteral& node, Context& context); -extern Effect parse(const ast::EffectProductionNumericFluentTotalCost& node, Context& context); -extern Effect parse(const ast::EffectProductionNumericFluentGeneral& node, Context& context); +extern Effect parse(const ast::EffectProductionNumeric& node, Context& context); extern Effect parse(const ast::EffectProduction& node, Context& context); extern Effect parse(const ast::EffectCompositeForall& node, Context& context); extern Effect parse(const ast::EffectCompositeWhen& node, Context& context);