Skip to content

Commit

Permalink
generalized effect structure by making numeric effects a production e…
Browse files Browse the repository at this point in the history
…ffect
  • Loading branch information
drexlerd committed Nov 30, 2024
1 parent 4a26d7f commit 701ab5b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 160 deletions.
46 changes: 7 additions & 39 deletions include/loki/details/ast/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -826,47 +823,32 @@ struct AssignOperator :
};

/* <effect> */
// <p-effect>
// struct EffectRoot :
// x3::position_tagged,
// x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectComposite>, x3::forward_ast<EffectProductionNumericFluentTotalCost>>,
// std::vector<x3::variant<EffectProductionNumericFluentTotalCost, Effect>>>
//{
// using base_type::base_type;
// using base_type::operator=;
//};

struct Effect : x3::position_tagged, x3::variant<x3::forward_ast<EffectProduction>, x3::forward_ast<EffectComposite>, std::vector<Effect>>
{
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<EffectProductionLiteral, EffectProductionNumericFluentGeneral>
struct EffectProduction : x3::position_tagged, x3::variant<EffectProductionLiteral, EffectProductionNumeric>
{
using base_type::base_type;
using base_type::operator=;
};

// Composite effects
struct EffectCompositeForall : x3::position_tagged
{
TypedListOfVariables typed_list_of_variables;
Expand All @@ -881,7 +863,7 @@ struct EffectCompositeWhen : x3::position_tagged

struct EffectCompositeOneof : x3::position_tagged
{
std::vector<Effect> possibilities;
std::vector<Effect> possibilities;
};

struct EffectComposite : x3::position_tagged, x3::variant<EffectCompositeForall, EffectCompositeWhen, EffectCompositeOneof>
Expand All @@ -890,20 +872,6 @@ struct EffectComposite : x3::position_tagged, x3::variant<EffectCompositeForall,
using base_type::operator=;
};

struct EffectNumericFluentTotalCostOrEffect : x3::position_tagged, x3::variant<EffectProductionNumericFluentTotalCost, Effect>
{
using base_type::base_type;
using base_type::operator=;
};

struct EffectRoot:
x3::position_tagged,
x3::variant<EffectProduction, EffectComposite, EffectProductionNumericFluentTotalCost, std::vector<EffectNumericFluentTotalCostOrEffect>>
{
using base_type::base_type;
using base_type::operator=;
};

/* <action-def> */
struct ActionSymbol : x3::position_tagged
{
Expand All @@ -913,7 +881,7 @@ struct ActionSymbol : x3::position_tagged
struct ActionBody : x3::position_tagged
{
boost::optional<PreconditionGoalDescriptor> precondition_goal_descriptor;
boost::optional<EffectRoot> effect;
boost::optional<Effect> effect;
};

struct Action : x3::position_tagged
Expand Down
5 changes: 1 addition & 4 deletions include/loki/details/ast/printer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {});
Expand Down
3 changes: 1 addition & 2 deletions src/ast/ast_adapted.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 5 additions & 17 deletions src/ast/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -367,15 +364,12 @@ typedef x3::rule<NumericTermClass, ast::FunctionExpression> numeric_term_type;

typedef x3::rule<EffectClass, ast::Effect> effect_type;
typedef x3::rule<EffectProductionLiteralClass, ast::EffectProductionLiteral> effect_production_literal_type;
typedef x3::rule<EffectProductionNumericFluentTotalCostClass, ast::EffectProductionNumericFluentTotalCost> effect_production_numeric_fluent_total_cost_type;
typedef x3::rule<EffectProductionNumericFluentGeneralClass, ast::EffectProductionNumericFluentGeneral> effect_production_numeric_fluent_general_type;
typedef x3::rule<EffectProductionNumericClass, ast::EffectProductionNumeric> effect_production_numeric_type;
typedef x3::rule<EffectProductionClass, ast::EffectProduction> effect_production_type;
typedef x3::rule<EffectCompositeForallClass, ast::EffectCompositeForall> effect_composite_forall_type;
typedef x3::rule<EffectCompositeWhenClass, ast::EffectCompositeWhen> effect_composite_when_type;
typedef x3::rule<EffectCompositeOneofClass, ast::EffectCompositeOneof> effect_composite_oneof_type;
typedef x3::rule<EffectCompositeClass, ast::EffectComposite> effect_composite_type;
typedef x3::rule<EffectRootClass, ast::EffectRoot> effect_root_type;
typedef x3::rule<EffectNumericFluentTotalCostOrEffectClass, ast::EffectNumericFluentTotalCostOrEffect> effect_numeric_fluent_total_cost_or_effect_type;

typedef x3::rule<ActionSymbolClass, ast::ActionSymbol> action_symbol_type;
typedef x3::rule<ActionBodyClass, ast::ActionBody> action_body_type;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
49 changes: 9 additions & 40 deletions src/ast/parser_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {});
Expand Down Expand Up @@ -398,23 +396,18 @@ 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(')');
const auto effect_composite_def = effect_composite_forall | effect_composite_when | effect_composite_oneof;

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(')');

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand Down Expand Up @@ -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; }
Expand Down
5 changes: 1 addition & 4 deletions src/ast/parser_instantiations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 701ab5b

Please sign in to comment.