diff --git a/api/python/src/dlplan/policy/__init__.py b/api/python/src/dlplan/policy/__init__.py index 2faa05be..9e59d972 100644 --- a/api/python/src/dlplan/policy/__init__.py +++ b/api/python/src/dlplan/policy/__init__.py @@ -4,4 +4,6 @@ PositiveBooleanCondition, NegativeBooleanCondition, \ GreaterNumericalCondition, EqualNumericalCondition, \ PositiveBooleanEffect, NegativeBooleanEffect, UnchangedBooleanEffect, \ - DecrementNumericalEffect, IncrementNumericalEffect, UnchangedNumericalEffect + DecrementNumericalEffect, DecrementOrUnchangedNumericalEffect, \ + IncrementNumericalEffect, IncrementOrUnchangedNumericalEffect, \ + UnchangedNumericalEffect diff --git a/api/python/src/dlplan/policy/__init__.pyi b/api/python/src/dlplan/policy/__init__.pyi index 84d3e7c8..c002f115 100644 --- a/api/python/src/dlplan/policy/__init__.pyi +++ b/api/python/src/dlplan/policy/__init__.pyi @@ -78,10 +78,18 @@ class DecrementNumericalEffect(BaseEffect): def get_named_element(self) -> NamedNumerical: ... +class DecrementOrUnchangedNumericalEffect(BaseEffect): + def get_named_element(self) -> NamedNumerical: ... + + class IncrementNumericalEffect(BaseEffect): def get_named_element(self) -> NamedNumerical: ... +class IncrementOrUnchangedNumericalEffect(BaseEffect): + def get_named_element(self) -> NamedNumerical: ... + + class UnchangedNumericalEffect(BaseEffect): def get_named_element(self) -> NamedNumerical: ... @@ -134,7 +142,9 @@ class PolicyFactory: def make_pos_effect(self, boolean: NamedBoolean) -> BaseEffect: ... def make_neg_effect(self, boolean: NamedBoolean) -> BaseEffect: ... def make_inc_effect(self, bnumerical: NamedNumerical) -> BaseEffect: ... + def make_inc_bot_effect(self, bnumerical: NamedNumerical) -> BaseEffect: ... def make_dec_effect(self, numerical: NamedNumerical) -> BaseEffect: ... + def make_dec_bot_effect(self, numerical: NamedNumerical) -> BaseEffect: ... @overload def make_bot_effect(self, boolean: NamedBoolean) -> BaseEffect: ... @overload diff --git a/api/python/src/policy.cpp b/api/python/src/policy.cpp index 8c701250..2376c385 100644 --- a/api/python/src/policy.cpp +++ b/api/python/src/policy.cpp @@ -86,10 +86,18 @@ void init_policy(py::module_ &m_policy) { .def("get_named_element", &policy::DecrementNumericalEffect::get_named_element) ; + py::class_>(m_policy, "DecrementOrUnchangedNumericalEffect") + .def("get_named_element", &policy::DecrementOrUnchangedNumericalEffect::get_named_element) + ; + py::class_>(m_policy, "IncrementNumericalEffect") .def("get_named_element", &policy::IncrementNumericalEffect::get_named_element) ; + py::class_>(m_policy, "IncrementOrUnchangedNumericalEffect") + .def("get_named_element", &policy::IncrementOrUnchangedNumericalEffect::get_named_element) + ; + py::class_>(m_policy, "UnchangedNumericalEffect") .def("get_named_element", &policy::UnchangedNumericalEffect::get_named_element) ; @@ -142,7 +150,9 @@ void init_policy(py::module_ &m_policy) { .def("make_bot_effect", py::overload_cast&>(&policy::PolicyFactory::make_bot_effect)) .def("make_inc_effect", py::overload_cast&>(&policy::PolicyFactory::make_inc_effect)) + .def("make_inc_bot_effect", py::overload_cast&>(&policy::PolicyFactory::make_inc_bot_effect)) .def("make_dec_effect", py::overload_cast&>(&policy::PolicyFactory::make_dec_effect)) + .def("make_dec_bot_effect", py::overload_cast&>(&policy::PolicyFactory::make_dec_bot_effect)) .def("make_bot_effect", py::overload_cast&>(&policy::PolicyFactory::make_bot_effect)) .def("make_gt_effect", py::overload_cast&>(&policy::PolicyFactory::make_gt_effect)) .def("make_eq_effect", py::overload_cast&>(&policy::PolicyFactory::make_eq_effect)) diff --git a/include/dlplan/policy.h b/include/dlplan/policy.h index 17e45136..948b7540 100644 --- a/include/dlplan/policy.h +++ b/include/dlplan/policy.h @@ -294,7 +294,9 @@ class PolicyFactory { std::shared_ptr make_neg_effect(const std::shared_ptr& boolean); std::shared_ptr make_bot_effect(const std::shared_ptr& boolean); std::shared_ptr make_inc_effect(const std::shared_ptr& numerical); + std::shared_ptr make_inc_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_dec_effect(const std::shared_ptr& numerical); + std::shared_ptr make_dec_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_gt_effect(const std::shared_ptr& numerical); std::shared_ptr make_eq_effect(const std::shared_ptr& numerical); diff --git a/include/dlplan/policy/effect.h b/include/dlplan/policy/effect.h index d8eb3181..18c03e05 100644 --- a/include/dlplan/policy/effect.h +++ b/include/dlplan/policy/effect.h @@ -105,6 +105,22 @@ class IncrementNumericalEffect : public NamedElementEffect, publ void accept(BaseEffectVisitor& visitor) const override; }; +class IncrementOrUnchangedNumericalEffect : public NamedElementEffect, public std::enable_shared_from_this { +private: + IncrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr numerical); + + template + friend class dlplan::ReferenceCountedObjectFactory; + +public: + bool are_equal_impl(const BaseEffect& other) const override; + void str_impl(std::stringstream& out) const override; + + bool evaluate(const core::State& source_state, const core::State& target_state) const override; + bool evaluate(const core::State& source_state, const core::State& target_state, core::DenotationsCaches& caches) const override; + void accept(BaseEffectVisitor& visitor) const override; +}; + class DecrementNumericalEffect : public NamedElementEffect, public std::enable_shared_from_this { private: DecrementNumericalEffect(int identifier, std::shared_ptr numerical); @@ -121,6 +137,22 @@ class DecrementNumericalEffect : public NamedElementEffect, publ void accept(BaseEffectVisitor& visitor) const override; }; +class DecrementOrUnchangedNumericalEffect : public NamedElementEffect, public std::enable_shared_from_this { +private: + DecrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr numerical); + + template + friend class dlplan::ReferenceCountedObjectFactory; + +public: + bool are_equal_impl(const BaseEffect& other) const override; + void str_impl(std::stringstream& out) const override; + + bool evaluate(const core::State& source_state, const core::State& target_state) const override; + bool evaluate(const core::State& source_state, const core::State& target_state, core::DenotationsCaches& caches) const override; + void accept(BaseEffectVisitor& visitor) const override; +}; + class UnchangedNumericalEffect : public NamedElementEffect, public std::enable_shared_from_this { private: UnchangedNumericalEffect(int identifier, std::shared_ptr numerical); @@ -260,7 +292,9 @@ class BaseEffectVisitor { virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; + virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; + virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; virtual void visit(const std::shared_ptr& effect) = 0; @@ -307,6 +341,14 @@ namespace std { const std::shared_ptr& right_effect) const; }; + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_effect, + const std::shared_ptr& right_effect) const; + }; + template<> struct less> { @@ -315,6 +357,14 @@ namespace std { const std::shared_ptr& right_effect) const; }; + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_effect, + const std::shared_ptr& right_effect) const; + }; + template<> struct less> { @@ -403,12 +453,24 @@ namespace std { std::size_t operator()(const dlplan::policy::IncrementNumericalEffect& effect) const; }; + template<> + struct hash + { + std::size_t operator()(const dlplan::policy::IncrementOrUnchangedNumericalEffect& effect) const; + }; + template<> struct hash { std::size_t operator()(const dlplan::policy::DecrementNumericalEffect& effect) const; }; + template<> + struct hash + { + std::size_t operator()(const dlplan::policy::DecrementOrUnchangedNumericalEffect& effect) const; + }; + template<> struct hash { diff --git a/include/dlplan/policy/parsers/semantic/parser.hpp b/include/dlplan/policy/parsers/semantic/parser.hpp index 5a8a166a..c73ae333 100644 --- a/include/dlplan/policy/parsers/semantic/parser.hpp +++ b/include/dlplan/policy/parsers/semantic/parser.hpp @@ -52,7 +52,9 @@ extern std::shared_ptr parse(const ast::PositiveBooleanEffect& extern std::shared_ptr parse(const ast::NegativeBooleanEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::UnchangedBooleanEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::IncrementNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); +extern std::shared_ptr parse(const ast::IncrementOrUnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::DecrementNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); +extern std::shared_ptr parse(const ast::DecrementOrUnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::UnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::GreaterNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); extern std::shared_ptr parse(const ast::EqualNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context); diff --git a/include/dlplan/policy/parsers/syntactic/ast.hpp b/include/dlplan/policy/parsers/syntactic/ast.hpp index c3cab405..9587e39a 100644 --- a/include/dlplan/policy/parsers/syntactic/ast.hpp +++ b/include/dlplan/policy/parsers/syntactic/ast.hpp @@ -49,7 +49,9 @@ namespace dlplan::policy::ast struct NegativeBooleanEffect; struct UnchangedBooleanEffect; struct IncrementNumericalEffect; + struct IncrementOrUnchangedNumericalEffect; struct DecrementNumericalEffect; + struct DecrementOrUnchangedNumericalEffect; struct UnchangedNumericalEffect; struct GreaterNumericalEffect; struct EqualNumericalEffect; @@ -220,10 +222,18 @@ namespace dlplan::policy::ast NumericalReference reference; }; + struct IncrementOrUnchangedNumericalEffect : x3::position_tagged { + NumericalReference reference; + }; + struct DecrementNumericalEffect : x3::position_tagged { NumericalReference reference; }; + struct DecrementOrUnchangedNumericalEffect : x3::position_tagged { + NumericalReference reference; + }; + struct UnchangedNumericalEffect : x3::position_tagged { NumericalReference reference; }; @@ -262,7 +272,9 @@ namespace dlplan::policy::ast x3::forward_ast, x3::forward_ast, x3::forward_ast, + x3::forward_ast, x3::forward_ast, + x3::forward_ast, x3::forward_ast, x3::forward_ast, x3::forward_ast, diff --git a/include/dlplan/policy/parsers/syntactic/parser.hpp b/include/dlplan/policy/parsers/syntactic/parser.hpp index a246848f..8c5c71fa 100644 --- a/include/dlplan/policy/parsers/syntactic/parser.hpp +++ b/include/dlplan/policy/parsers/syntactic/parser.hpp @@ -45,7 +45,9 @@ namespace dlplan::policy struct NegativeBooleanEffectClass; struct UnchangedBooleanEffectClass; struct IncrementNumericalEffectClass; + struct IncrementOrUnchangedNumericalEffectClass; struct DecrementNumericalEffectClass; + struct DecrementOrUnchangedNumericalEffectClass; struct UnchangedNumericalEffectClass; struct GreaterNumericalEffectClass; struct EqualNumericalEffectClass; @@ -96,7 +98,9 @@ namespace dlplan::policy typedef x3::rule negative_boolean_effect_type; typedef x3::rule unchanged_boolean_effect_type; typedef x3::rule increment_numerical_effect_type; + typedef x3::rule increment_or_unchanged_numerical_effect_type; typedef x3::rule decrement_numerical_effect_type; + typedef x3::rule decrement_or_unchanged_numerical_effect_type; typedef x3::rule unchanged_numerical_effect_type; typedef x3::rule greater_numerical_effect_type; typedef x3::rule equal_numerical_effect_type; @@ -121,7 +125,9 @@ namespace dlplan::policy positive_boolean_condition_type, negative_boolean_condition_type, greater_numerical_condition_type, equal_numerical_condition_type, positive_boolean_effect_type, negative_boolean_effect_type, unchanged_boolean_effect_type, greater_concept_condition_type, equal_concept_condition_type, - increment_numerical_effect_type, decrement_numerical_effect_type, unchanged_numerical_effect_type, greater_numerical_effect_type, equal_numerical_effect_type, increment_concept_effect_type, decrement_concept_effect_type, unchanged_concept_effect_type, greater_concept_effect_type, equal_concept_effect_type, + increment_numerical_effect_type, increment_or_unchanged_numerical_effect_type, + decrement_numerical_effect_type, decrement_or_unchanged_numerical_effect_type, + unchanged_numerical_effect_type, greater_numerical_effect_type, equal_numerical_effect_type, increment_concept_effect_type, decrement_concept_effect_type, unchanged_concept_effect_type, greater_concept_effect_type, equal_concept_effect_type, feature_condition_type, feature_effect_type, rule_type, rules_type, policy_type) } @@ -162,7 +168,9 @@ namespace dlplan::policy parser::negative_boolean_effect_type const& negative_boolean_effect(); parser::unchanged_boolean_effect_type const& unchanged_boolean_effect(); parser::increment_numerical_effect_type const& increment_numerical_effect(); + parser::increment_or_unchanged_numerical_effect_type const& increment_or_unchanged_numerical_effect(); parser::decrement_numerical_effect_type const& decrement_numerical_effect(); + parser::decrement_or_unchanged_numerical_effect_type const& decrement_or_unchanged_numerical_effect(); parser::unchanged_numerical_effect_type const& unchanged_numerical_effect(); parser::greater_numerical_effect_type const& greater_numerical_effect(); parser::equal_numerical_effect_type const& equal_numerical_effect(); diff --git a/setup.py b/setup.py index 2fac5af2..0192d135 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from setuptools import setup, find_packages, Extension from setuptools.command.build_ext import build_ext -__version__ = "0.3.23" +__version__ = "0.3.24" HERE = Path(__file__).resolve().parent diff --git a/src/novelty/tuple_graph_builder.cpp b/src/novelty/tuple_graph_builder.cpp index 809a2f36..90ab31cc 100644 --- a/src/novelty/tuple_graph_builder.cpp +++ b/src/novelty/tuple_graph_builder.cpp @@ -224,7 +224,6 @@ TupleNodeIndices TupleGraphBuilder::compute_nodes_layer( // Create nodes TupleNodeIndices curr_tuple_layer; for (const auto& [_, tuple_index] : curr_tuple_indices) - //for (const auto& [tuple_index, _] : m_novel_tuple_index_to_state_indices) { auto node_index = m_nodes.size(); const auto& subgoals = m_novel_tuple_index_to_state_indices.at(tuple_index); diff --git a/src/policy/effect.cpp b/src/policy/effect.cpp index 5a013337..486046e9 100644 --- a/src/policy/effect.cpp +++ b/src/policy/effect.cpp @@ -135,6 +135,44 @@ void IncrementNumericalEffect::accept(BaseEffectVisitor& visitor) const { } + +IncrementOrUnchangedNumericalEffect::IncrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr numerical) + : NamedElementEffect(identifier, numerical) {} + +bool IncrementOrUnchangedNumericalEffect::are_equal_impl(const BaseEffect& other) const { + if (typeid(*this) == typeid(other)) { + if (this == &other) return true; + const auto& other_derived = static_cast(other); + return m_named_element == other_derived.m_named_element; + } + return false; +} + +bool IncrementOrUnchangedNumericalEffect::evaluate(const core::State& source_state, const core::State& target_state) const { + int source_eval = m_named_element->get_element()->evaluate(source_state); + int target_eval = m_named_element->get_element()->evaluate(target_state); + //if (source_eval == INF) return false; + //if (target_eval == INF) return false; + return source_eval <= target_eval; +} + +bool IncrementOrUnchangedNumericalEffect::evaluate(const core::State& source_state, const core::State& target_state, core::DenotationsCaches& caches) const { + int source_eval = m_named_element->get_element()->evaluate(source_state, caches); + int target_eval = m_named_element->get_element()->evaluate(target_state, caches); + //if (source_eval == INF) return false; + //if (target_eval == INF) return false; + return source_eval <= target_eval; +} + +void IncrementOrUnchangedNumericalEffect::str_impl(std::stringstream& out) const { + out << "(:e_n_inc_bot " + m_named_element->get_key() + ")"; +} + +void IncrementOrUnchangedNumericalEffect::accept(BaseEffectVisitor& visitor) const { + visitor.visit(this->shared_from_this()); +} + + DecrementNumericalEffect::DecrementNumericalEffect(int identifier, std::shared_ptr numerical) : NamedElementEffect(identifier, numerical) {} @@ -172,6 +210,43 @@ void DecrementNumericalEffect::accept(BaseEffectVisitor& visitor) const { } +DecrementOrUnchangedNumericalEffect::DecrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr numerical) + : NamedElementEffect(identifier, numerical) {} + +bool DecrementOrUnchangedNumericalEffect::are_equal_impl(const BaseEffect& other) const { + if (typeid(*this) == typeid(other)) { + if (this == &other) return true; + const auto& other_derived = static_cast(other); + return m_named_element == other_derived.m_named_element; + } + return false; +} + +bool DecrementOrUnchangedNumericalEffect::evaluate(const core::State& source_state, const core::State& target_state) const { + int source_eval = m_named_element->get_element()->evaluate(source_state); + int target_eval = m_named_element->get_element()->evaluate(target_state); + //if (source_eval == INF) return false; + //if (target_eval == INF) return false; + return source_eval >= target_eval; +} + +bool DecrementOrUnchangedNumericalEffect::evaluate(const core::State& source_state, const core::State& target_state, core::DenotationsCaches& caches) const { + int source_eval = m_named_element->get_element()->evaluate(source_state, caches); + int target_eval = m_named_element->get_element()->evaluate(target_state, caches); + //if (source_eval == INF) return false; + //if (target_eval == INF) return false; + return source_eval >= target_eval; +} + +void DecrementOrUnchangedNumericalEffect::str_impl(std::stringstream& out) const { + out << "(:e_n_dec_bot " + m_named_element->get_key() + ")"; +} + +void DecrementOrUnchangedNumericalEffect::accept(BaseEffectVisitor& visitor) const { + visitor.visit(this->shared_from_this()); +} + + UnchangedNumericalEffect::UnchangedNumericalEffect(int identifier, std::shared_ptr numerical) : NamedElementEffect(identifier, numerical) {} @@ -476,12 +551,24 @@ namespace std { return *left_effect < *right_effect; } + bool less>::operator()( + const std::shared_ptr& left_effect, + const std::shared_ptr& right_effect) const { + return *left_effect < *right_effect; + } + bool less>::operator()( const std::shared_ptr& left_effect, const std::shared_ptr& right_effect) const { return *left_effect < *right_effect; } + bool less>::operator()( + const std::shared_ptr& left_effect, + const std::shared_ptr& right_effect) const { + return *left_effect < *right_effect; + } + bool less>::operator()( const std::shared_ptr& left_effect, const std::shared_ptr& right_effect) const { @@ -550,11 +637,21 @@ namespace std { return effect.hash(); } + std::size_t hash::operator()( + const dlplan::policy::IncrementOrUnchangedNumericalEffect& effect) const { + return effect.hash(); + } + std::size_t hash::operator()( const dlplan::policy::DecrementNumericalEffect& effect) const { return effect.hash(); } + std::size_t hash::operator()( + const dlplan::policy::DecrementOrUnchangedNumericalEffect& effect) const { + return effect.hash(); + } + std::size_t hash::operator()( const dlplan::policy::UnchangedNumericalEffect& effect) const { return effect.hash(); diff --git a/src/policy/parsers/semantic/parser.cpp b/src/policy/parsers/semantic/parser.cpp index 822e6b0f..f313f740 100644 --- a/src/policy/parsers/semantic/parser.cpp +++ b/src/policy/parsers/semantic/parser.cpp @@ -262,11 +262,21 @@ std::shared_ptr parse( return context.policy_factory.make_inc_effect(parse(node.reference, error_handler, context)); } +std::shared_ptr parse( + const ast::IncrementOrUnchangedNumericalEffect& node, const error_handler_type& error_handler, Context& context) { + return context.policy_factory.make_inc_bot_effect(parse(node.reference, error_handler, context)); +} + std::shared_ptr parse( const ast::DecrementNumericalEffect& node, const error_handler_type& error_handler, Context& context) { return context.policy_factory.make_dec_effect(parse(node.reference, error_handler, context)); } +std::shared_ptr parse( + const ast::DecrementOrUnchangedNumericalEffect& node, const error_handler_type& error_handler, Context& context) { + return context.policy_factory.make_dec_bot_effect(parse(node.reference, error_handler, context)); +} + std::shared_ptr parse( const ast::UnchangedNumericalEffect& node, const error_handler_type& error_handler, Context& context) { return context.policy_factory.make_bot_effect(parse(node.reference, error_handler, context)); diff --git a/src/policy/parsers/syntactic/ast_adapted.hpp b/src/policy/parsers/syntactic/ast_adapted.hpp index cdd3e541..e27a56d1 100644 --- a/src/policy/parsers/syntactic/ast_adapted.hpp +++ b/src/policy/parsers/syntactic/ast_adapted.hpp @@ -46,7 +46,9 @@ BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::PositiveBooleanEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::NegativeBooleanEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::UnchangedBooleanEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::IncrementNumericalEffect, reference) +BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::IncrementOrUnchangedNumericalEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::DecrementNumericalEffect, reference) +BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::DecrementOrUnchangedNumericalEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::UnchangedNumericalEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::GreaterNumericalEffect, reference) BOOST_FUSION_ADAPT_STRUCT(dlplan::policy::ast::EqualNumericalEffect, reference) diff --git a/src/policy/parsers/syntactic/parser_def.hpp b/src/policy/parsers/syntactic/parser_def.hpp index 11f029ad..63ad18a3 100644 --- a/src/policy/parsers/syntactic/parser_def.hpp +++ b/src/policy/parsers/syntactic/parser_def.hpp @@ -80,7 +80,9 @@ namespace dlplan::policy::parser negative_boolean_effect_type const negative_boolean_effect = "negative_boolean_effect"; unchanged_boolean_effect_type const unchanged_boolean_effect = "unchanged_boolean_effect"; increment_numerical_effect_type const increment_numerical_effect = "increment_numerical_effect"; + increment_or_unchanged_numerical_effect_type const increment_or_unchanged_numerical_effect = "increment_or_unchanged_numerical_effect"; decrement_numerical_effect_type const decrement_numerical_effect = "decrement_numerical_effect"; + decrement_or_unchanged_numerical_effect_type const decrement_or_unchanged_numerical_effect = "decrement_or_unchanged_numerical_effect"; unchanged_numerical_effect_type const unchanged_numerical_effect = "unchanged_numerical_effect"; greater_numerical_effect_type const greater_numerical_effect = "greater_numerical_effect"; equal_numerical_effect_type const equal_numerical_effect = "equal_numerical_effect"; @@ -140,7 +142,9 @@ namespace dlplan::policy::parser const auto negative_boolean_effect_def = lit('(') >> lit(":e_b_neg") > boolean_reference > lit(')'); const auto unchanged_boolean_effect_def = lit('(') >> lit(":e_b_bot") > boolean_reference > lit(')'); const auto increment_numerical_effect_def = lit('(') >> lit(":e_n_inc") > numerical_reference > lit(')'); + const auto increment_or_unchanged_numerical_effect_def = lit('(') >> lit(":e_n_inc_bot") > numerical_reference > lit(')'); const auto decrement_numerical_effect_def = lit('(') >> lit(":e_n_dec") > numerical_reference > lit(')'); + const auto decrement_or_unchanged_numerical_effect_def = lit('(') >> lit(":e_n_dec_bot") > numerical_reference > lit(')'); const auto unchanged_numerical_effect_def = lit('(') >> lit(":e_n_bot") > numerical_reference > lit(')'); const auto greater_numerical_effect_def = lit('(') >> lit(":e_n_gt") > numerical_reference > lit(')'); const auto equal_numerical_effect_def = lit('(') >> lit(":e_n_eq") > numerical_reference > lit(')'); @@ -155,7 +159,9 @@ namespace dlplan::policy::parser | greater_concept_condition | equal_concept_condition; const auto feature_effect_def = positive_boolean_effect | negative_boolean_effect | unchanged_boolean_effect - | increment_numerical_effect | decrement_numerical_effect | unchanged_numerical_effect | greater_numerical_effect | equal_numerical_effect + | increment_numerical_effect | increment_or_unchanged_numerical_effect + | decrement_numerical_effect | decrement_or_unchanged_numerical_effect + | unchanged_numerical_effect | greater_numerical_effect | equal_numerical_effect | increment_concept_effect | decrement_concept_effect | unchanged_concept_effect | greater_concept_effect | equal_concept_effect; const auto rule_def = lit('(') >> lit(":rule") @@ -180,7 +186,10 @@ namespace dlplan::policy::parser concept_definition, concept_implementation, concept_, concept_reference, concepts, role_definition, role_implementation, role, role_reference, roles, positive_boolean_condition, negative_boolean_condition, greater_numerical_condition, equal_numerical_condition, greater_concept_condition, equal_concept_condition, - positive_boolean_effect, negative_boolean_effect, unchanged_boolean_effect, increment_numerical_effect, decrement_numerical_effect, unchanged_numerical_effect, greater_numerical_effect, equal_numerical_effect, increment_concept_effect, decrement_concept_effect, unchanged_concept_effect, greater_concept_effect, equal_concept_effect, + positive_boolean_effect, negative_boolean_effect, unchanged_boolean_effect, + increment_numerical_effect, increment_or_unchanged_numerical_effect, + decrement_numerical_effect, decrement_or_unchanged_numerical_effect, + unchanged_numerical_effect, greater_numerical_effect, equal_numerical_effect, increment_concept_effect, decrement_concept_effect, unchanged_concept_effect, greater_concept_effect, equal_concept_effect, feature_condition, feature_effect, rule, rules, policy, policy_root) /////////////////////////////////////////////////////////////////////////// @@ -216,7 +225,9 @@ namespace dlplan::policy::parser struct NegativeBooleanEffectClass : x3::annotate_on_success {}; struct UnchangedBooleanEffectClass : x3::annotate_on_success {}; struct IncrementNumericalEffectClass : x3::annotate_on_success {}; + struct IncrementOrUnchangedNumericalEffectClass : x3::annotate_on_success {}; struct DecrementNumericalEffectClass : x3::annotate_on_success {}; + struct DecrementOrUnchangedNumericalEffectClass : x3::annotate_on_success {}; struct UnchangedNumericalEffectClass : x3::annotate_on_success {}; struct FeatureConditionClass : x3::annotate_on_success {}; struct FeatureEffectClass : x3::annotate_on_success {}; @@ -326,9 +337,15 @@ namespace dlplan::policy parser::increment_numerical_effect_type const& increment_numerical_effect() { return parser::increment_numerical_effect; } + parser::increment_or_unchanged_numerical_effect_type const& increment_or_unchanged_numerical_effect() { + return parser::increment_or_unchanged_numerical_effect; + } parser::decrement_numerical_effect_type const& decrement_numerical_effect() { return parser::decrement_numerical_effect; } + parser::decrement_or_unchanged_numerical_effect_type const& decrement_or_unchanged_numerical_effect() { + return parser::decrement_or_unchanged_numerical_effect; + } parser::unchanged_numerical_effect_type const& unchanged_numerical_effect() { return parser::unchanged_numerical_effect; } diff --git a/src/policy/parsers/syntactic/parser_instantiations.cpp b/src/policy/parsers/syntactic/parser_instantiations.cpp index 9ed54676..4231a42b 100644 --- a/src/policy/parsers/syntactic/parser_instantiations.cpp +++ b/src/policy/parsers/syntactic/parser_instantiations.cpp @@ -72,8 +72,12 @@ namespace dlplan::policy::parser unchanged_boolean_effect_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( increment_numerical_effect_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + increment_or_unchanged_numerical_effect_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( decrement_numerical_effect_type, iterator_type, context_type) + BOOST_SPIRIT_INSTANTIATE( + decrement_or_unchanged_numerical_effect_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( unchanged_numerical_effect_type, iterator_type, context_type) BOOST_SPIRIT_INSTANTIATE( diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index 04ee79a2..4a6a88f7 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -117,10 +117,18 @@ std::shared_ptr PolicyFactory::make_inc_effect(const std::shar return m_pImpl->make_inc_effect(numerical); } +std::shared_ptr PolicyFactory::make_inc_bot_effect(const std::shared_ptr& numerical) { + return m_pImpl->make_inc_bot_effect(numerical); +} + std::shared_ptr PolicyFactory::make_dec_effect(const std::shared_ptr& numerical) { return m_pImpl->make_dec_effect(numerical); } +std::shared_ptr PolicyFactory::make_dec_bot_effect(const std::shared_ptr& numerical) { + return m_pImpl->make_dec_bot_effect(numerical); +} + std::shared_ptr PolicyFactory::make_bot_effect(const std::shared_ptr& numerical) { return m_pImpl->make_bot_effect(numerical); } diff --git a/src/policy/policy_factory.cpp b/src/policy/policy_factory.cpp index 0db88ac5..a30839ff 100644 --- a/src/policy/policy_factory.cpp +++ b/src/policy/policy_factory.cpp @@ -133,10 +133,18 @@ std::shared_ptr PolicyFactoryImpl::make_inc_effect(const std:: return m_cache.get_or_create(numerical).object; } +std::shared_ptr PolicyFactoryImpl::make_inc_bot_effect(const std::shared_ptr& numerical) { + return m_cache.get_or_create(numerical).object; +} + std::shared_ptr PolicyFactoryImpl::make_dec_effect(const std::shared_ptr& numerical) { return m_cache.get_or_create(numerical).object; } +std::shared_ptr PolicyFactoryImpl::make_dec_bot_effect(const std::shared_ptr& numerical) { + return m_cache.get_or_create(numerical).object; +} + std::shared_ptr PolicyFactoryImpl::make_bot_effect(const std::shared_ptr& numerical) { return m_cache.get_or_create(numerical).object; } diff --git a/src/policy/policy_factory.h b/src/policy/policy_factory.h index 09651536..eb30b203 100644 --- a/src/policy/policy_factory.h +++ b/src/policy/policy_factory.h @@ -32,7 +32,9 @@ class PolicyFactoryImpl { , NegativeBooleanEffect , UnchangedBooleanEffect , IncrementNumericalEffect + , IncrementOrUnchangedNumericalEffect , DecrementNumericalEffect + , DecrementOrUnchangedNumericalEffect , UnchangedNumericalEffect , GreaterNumericalEffect , EqualNumericalEffect @@ -72,7 +74,9 @@ class PolicyFactoryImpl { std::shared_ptr make_neg_effect(const std::shared_ptr& boolean); std::shared_ptr make_bot_effect(const std::shared_ptr& boolean); std::shared_ptr make_inc_effect(const std::shared_ptr& numerical); + std::shared_ptr make_inc_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_dec_effect(const std::shared_ptr& numerical); + std::shared_ptr make_dec_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_bot_effect(const std::shared_ptr& numerical); std::shared_ptr make_gt_effect(const std::shared_ptr& numerical); std::shared_ptr make_eq_effect(const std::shared_ptr& numerical); diff --git a/src/policy/policy_impl.cpp b/src/policy/policy_impl.cpp index 59e640c6..ab686ef4 100644 --- a/src/policy/policy_impl.cpp +++ b/src/policy/policy_impl.cpp @@ -69,10 +69,18 @@ struct InsertNamedElementFromEffect : public BaseEffectVisitor { numericals.insert(effect->get_named_element()); } + void visit(const std::shared_ptr& effect) override { + numericals.insert(effect->get_named_element()); + } + void visit(const std::shared_ptr& effect) override { numericals.insert(effect->get_named_element()); } + void visit(const std::shared_ptr& effect) override { + numericals.insert(effect->get_named_element()); + } + void visit(const std::shared_ptr& effect) override { numericals.insert(effect->get_named_element()); }