Skip to content

Commit

Permalink
added opposite effects for increment and decrement
Browse files Browse the repository at this point in the history
  • Loading branch information
drexlerd committed Jun 4, 2024
1 parent 3b5d541 commit 1a4c9d5
Show file tree
Hide file tree
Showing 19 changed files with 271 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/python/src/dlplan/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
PositiveBooleanCondition, NegativeBooleanCondition, \
GreaterNumericalCondition, EqualNumericalCondition, \
PositiveBooleanEffect, NegativeBooleanEffect, UnchangedBooleanEffect, \
DecrementNumericalEffect, IncrementNumericalEffect, UnchangedNumericalEffect
DecrementNumericalEffect, DecrementOrUnchangedNumericalEffect, \
IncrementNumericalEffect, IncrementOrUnchangedNumericalEffect, \
UnchangedNumericalEffect
10 changes: 10 additions & 0 deletions api/python/src/dlplan/policy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions api/python/src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ void init_policy(py::module_ &m_policy) {
.def("get_named_element", &policy::DecrementNumericalEffect::get_named_element)
;

py::class_<policy::DecrementOrUnchangedNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::DecrementOrUnchangedNumericalEffect>>(m_policy, "DecrementOrUnchangedNumericalEffect")
.def("get_named_element", &policy::DecrementOrUnchangedNumericalEffect::get_named_element)
;

py::class_<policy::IncrementNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::IncrementNumericalEffect>>(m_policy, "IncrementNumericalEffect")
.def("get_named_element", &policy::IncrementNumericalEffect::get_named_element)
;

py::class_<policy::IncrementOrUnchangedNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::IncrementOrUnchangedNumericalEffect>>(m_policy, "IncrementOrUnchangedNumericalEffect")
.def("get_named_element", &policy::IncrementOrUnchangedNumericalEffect::get_named_element)
;

py::class_<policy::UnchangedNumericalEffect, policy::BaseEffect, std::shared_ptr<policy::UnchangedNumericalEffect>>(m_policy, "UnchangedNumericalEffect")
.def("get_named_element", &policy::UnchangedNumericalEffect::get_named_element)
;
Expand Down Expand Up @@ -142,7 +150,9 @@ void init_policy(py::module_ &m_policy) {
.def("make_bot_effect", py::overload_cast<const std::shared_ptr<const policy::NamedBoolean>&>(&policy::PolicyFactory::make_bot_effect))

.def("make_inc_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_inc_effect))
.def("make_inc_bot_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_inc_bot_effect))
.def("make_dec_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_dec_effect))
.def("make_dec_bot_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_dec_bot_effect))
.def("make_bot_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_bot_effect))
.def("make_gt_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_gt_effect))
.def("make_eq_effect", py::overload_cast<const std::shared_ptr<const policy::NamedNumerical>&>(&policy::PolicyFactory::make_eq_effect))
Expand Down
2 changes: 2 additions & 0 deletions include/dlplan/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ class PolicyFactory {
std::shared_ptr<const BaseEffect> make_neg_effect(const std::shared_ptr<const NamedBoolean>& boolean);
std::shared_ptr<const BaseEffect> make_bot_effect(const std::shared_ptr<const NamedBoolean>& boolean);
std::shared_ptr<const BaseEffect> make_inc_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_inc_bot_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_dec_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_dec_bot_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_bot_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_gt_effect(const std::shared_ptr<const NamedNumerical>& numerical);
std::shared_ptr<const BaseEffect> make_eq_effect(const std::shared_ptr<const NamedNumerical>& numerical);
Expand Down
62 changes: 62 additions & 0 deletions include/dlplan/policy/effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ class IncrementNumericalEffect : public NamedElementEffect<NamedNumerical>, publ
void accept(BaseEffectVisitor& visitor) const override;
};

class IncrementOrUnchangedNumericalEffect : public NamedElementEffect<NamedNumerical>, public std::enable_shared_from_this<IncrementOrUnchangedNumericalEffect> {
private:
IncrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr<const NamedNumerical> numerical);

template<typename... Ts>
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<NamedNumerical>, public std::enable_shared_from_this<DecrementNumericalEffect> {
private:
DecrementNumericalEffect(int identifier, std::shared_ptr<const NamedNumerical> numerical);
Expand All @@ -121,6 +137,22 @@ class DecrementNumericalEffect : public NamedElementEffect<NamedNumerical>, publ
void accept(BaseEffectVisitor& visitor) const override;
};

class DecrementOrUnchangedNumericalEffect : public NamedElementEffect<NamedNumerical>, public std::enable_shared_from_this<DecrementOrUnchangedNumericalEffect> {
private:
DecrementOrUnchangedNumericalEffect(int identifier, std::shared_ptr<const NamedNumerical> numerical);

template<typename... Ts>
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<NamedNumerical>, public std::enable_shared_from_this<UnchangedNumericalEffect> {
private:
UnchangedNumericalEffect(int identifier, std::shared_ptr<const NamedNumerical> numerical);
Expand Down Expand Up @@ -260,7 +292,9 @@ class BaseEffectVisitor {
virtual void visit(const std::shared_ptr<const NegativeBooleanEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const UnchangedBooleanEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const IncrementNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const IncrementOrUnchangedNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const DecrementNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const DecrementOrUnchangedNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const UnchangedNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const GreaterNumericalEffect>& effect) = 0;
virtual void visit(const std::shared_ptr<const EqualNumericalEffect>& effect) = 0;
Expand Down Expand Up @@ -307,6 +341,14 @@ namespace std {
const std::shared_ptr<const dlplan::policy::IncrementNumericalEffect>& right_effect) const;
};

template<>
struct less<std::shared_ptr<const dlplan::policy::IncrementOrUnchangedNumericalEffect>>
{
bool operator()(
const std::shared_ptr<const dlplan::policy::IncrementOrUnchangedNumericalEffect>& left_effect,
const std::shared_ptr<const dlplan::policy::IncrementOrUnchangedNumericalEffect>& right_effect) const;
};

template<>
struct less<std::shared_ptr<const dlplan::policy::DecrementNumericalEffect>>
{
Expand All @@ -315,6 +357,14 @@ namespace std {
const std::shared_ptr<const dlplan::policy::DecrementNumericalEffect>& right_effect) const;
};

template<>
struct less<std::shared_ptr<const dlplan::policy::DecrementOrUnchangedNumericalEffect>>
{
bool operator()(
const std::shared_ptr<const dlplan::policy::DecrementOrUnchangedNumericalEffect>& left_effect,
const std::shared_ptr<const dlplan::policy::DecrementOrUnchangedNumericalEffect>& right_effect) const;
};

template<>
struct less<std::shared_ptr<const dlplan::policy::UnchangedNumericalEffect>>
{
Expand Down Expand Up @@ -403,12 +453,24 @@ namespace std {
std::size_t operator()(const dlplan::policy::IncrementNumericalEffect& effect) const;
};

template<>
struct hash<dlplan::policy::IncrementOrUnchangedNumericalEffect>
{
std::size_t operator()(const dlplan::policy::IncrementOrUnchangedNumericalEffect& effect) const;
};

template<>
struct hash<dlplan::policy::DecrementNumericalEffect>
{
std::size_t operator()(const dlplan::policy::DecrementNumericalEffect& effect) const;
};

template<>
struct hash<dlplan::policy::DecrementOrUnchangedNumericalEffect>
{
std::size_t operator()(const dlplan::policy::DecrementOrUnchangedNumericalEffect& effect) const;
};

template<>
struct hash<dlplan::policy::UnchangedNumericalEffect>
{
Expand Down
2 changes: 2 additions & 0 deletions include/dlplan/policy/parsers/semantic/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ extern std::shared_ptr<const BaseEffect> parse(const ast::PositiveBooleanEffect&
extern std::shared_ptr<const BaseEffect> parse(const ast::NegativeBooleanEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::UnchangedBooleanEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::IncrementNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::IncrementOrUnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::DecrementNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::DecrementOrUnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::UnchangedNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::GreaterNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
extern std::shared_ptr<const BaseEffect> parse(const ast::EqualNumericalEffect& node, const dlplan::error_handler_type& error_handler, Context& context);
Expand Down
12 changes: 12 additions & 0 deletions include/dlplan/policy/parsers/syntactic/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -262,7 +272,9 @@ namespace dlplan::policy::ast
x3::forward_ast<NegativeBooleanEffect>,
x3::forward_ast<UnchangedBooleanEffect>,
x3::forward_ast<IncrementNumericalEffect>,
x3::forward_ast<IncrementOrUnchangedNumericalEffect>,
x3::forward_ast<DecrementNumericalEffect>,
x3::forward_ast<DecrementOrUnchangedNumericalEffect>,
x3::forward_ast<UnchangedNumericalEffect>,
x3::forward_ast<GreaterNumericalEffect>,
x3::forward_ast<EqualNumericalEffect>,
Expand Down
10 changes: 9 additions & 1 deletion include/dlplan/policy/parsers/syntactic/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,7 +98,9 @@ namespace dlplan::policy
typedef x3::rule<NegativeBooleanEffectClass, ast::NegativeBooleanEffect> negative_boolean_effect_type;
typedef x3::rule<UnchangedBooleanEffectClass, ast::UnchangedBooleanEffect> unchanged_boolean_effect_type;
typedef x3::rule<IncrementNumericalEffectClass, ast::IncrementNumericalEffect> increment_numerical_effect_type;
typedef x3::rule<IncrementOrUnchangedNumericalEffectClass, ast::IncrementOrUnchangedNumericalEffect> increment_or_unchanged_numerical_effect_type;
typedef x3::rule<DecrementNumericalEffectClass, ast::DecrementNumericalEffect> decrement_numerical_effect_type;
typedef x3::rule<DecrementOrUnchangedNumericalEffectClass, ast::DecrementOrUnchangedNumericalEffect> decrement_or_unchanged_numerical_effect_type;
typedef x3::rule<UnchangedNumericalEffectClass, ast::UnchangedNumericalEffect> unchanged_numerical_effect_type;
typedef x3::rule<GreaterNumericalEffectClass, ast::GreaterNumericalEffect> greater_numerical_effect_type;
typedef x3::rule<EqualNumericalEffectClass, ast::EqualNumericalEffect> equal_numerical_effect_type;
Expand All @@ -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)
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion src/novelty/tuple_graph_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 1a4c9d5

Please sign in to comment.