From c4e3aa55d1a3fe4b01145338178c2205f11541aa Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Tue, 21 Nov 2023 16:15:53 +0100 Subject: [PATCH] moved headers to public --- include/dlplan/core/elements/booleans/empty.h | 2 +- .../dlplan/core/elements/booleans/inclusion.h | 2 +- .../dlplan/core/elements/booleans/nullary.h | 2 +- include/dlplan/core/elements/concepts/all.h | 2 +- include/dlplan/core/elements/concepts/and.h | 2 +- include/dlplan/core/elements/concepts/bot.h | 64 +++++++ include/dlplan/core/elements/concepts/diff.h | 68 +++++++ include/dlplan/core/elements/concepts/equal.h | 69 +++++++ include/dlplan/core/elements/concepts/not.h | 69 +++++++ .../dlplan/core/elements/concepts/one_of.h | 69 +++++++ include/dlplan/core/elements/concepts/or.h | 69 +++++++ .../core/elements/concepts/primitive.h | 11 +- .../core/elements/concepts/projection.h | 69 +++++++ include/dlplan/core/elements/concepts/some.h | 68 +++++++ .../dlplan/core/elements/concepts/subset.h | 68 +++++++ include/dlplan/core/elements/concepts/top.h | 64 +++++++ .../elements/numericals/concept_distance.h | 69 +++++++ .../dlplan}/core/elements/numericals/count.h | 2 +- .../core/elements/numericals/role_distance.h | 70 ++++++++ .../numericals/sum_concept_distance.h | 69 +++++++ .../elements/numericals/sum_role_distance.h | 70 ++++++++ .../dlplan}/core/elements/roles/and.h | 10 +- include/dlplan/core/elements/roles/compose.h | 68 +++++++ include/dlplan/core/elements/roles/diff.h | 70 ++++++++ include/dlplan/core/elements/roles/identity.h | 68 +++++++ include/dlplan/core/elements/roles/inverse.h | 68 +++++++ include/dlplan/core/elements/roles/not.h | 68 +++++++ include/dlplan/core/elements/roles/or.h | 68 +++++++ .../dlplan}/core/elements/roles/primitive.h | 3 +- include/dlplan/core/elements/roles/restrict.h | 68 +++++++ include/dlplan/core/elements/roles/top.h | 64 +++++++ .../core/elements/roles/transitive_closure.h | 69 +++++++ .../roles/transitive_reflexive_closure.h | 67 +++++++ {src => include/dlplan}/core/elements/utils.h | 6 +- {src => include/dlplan}/policy/condition.h | 2 +- {src => include/dlplan}/policy/effect.h | 2 +- src/core/CMakeLists.txt | 4 +- src/core/element_factory.h | 54 +++--- src/core/elements/booleans/empty.cpp | 5 - src/core/elements/booleans/inclusion.cpp | 1 - src/core/elements/concepts/diff.cpp | 91 +++++++++- src/core/elements/concepts/diff.h | 125 ------------- src/core/elements/concepts/equal.cpp | 99 +++++++++- src/core/elements/concepts/equal.h | 133 -------------- src/core/elements/concepts/not.cpp | 86 ++++++++- src/core/elements/concepts/not.h | 119 ------------ src/core/elements/concepts/one_of.cpp | 88 ++++++++- src/core/elements/concepts/one_of.h | 122 ------------- src/core/elements/concepts/or.cpp | 93 +++++++++- src/core/elements/concepts/or.h | 129 ------------- src/core/elements/concepts/primitive.cpp | 17 +- src/core/elements/concepts/projection.cpp | 91 +++++++++- src/core/elements/concepts/projection.h | 125 ------------- src/core/elements/concepts/some.cpp | 94 +++++++++- src/core/elements/concepts/some.h | 135 -------------- src/core/elements/concepts/subset.cpp | 95 +++++++++- src/core/elements/concepts/subset.h | 129 ------------- src/core/elements/concepts/top.cpp | 70 +++++++- src/core/elements/concepts/top.h | 101 ----------- .../elements/numericals/concept_distance.cpp | 128 ++++++++++++- .../elements/numericals/concept_distance.h | 165 ----------------- src/core/elements/numericals/count.cpp | 6 - .../elements/numericals/role_distance.cpp | 129 ++++++++++++- src/core/elements/numericals/role_distance.h | 170 ------------------ .../numericals/sum_concept_distance.cpp | 126 ++++++++++++- .../numericals/sum_concept_distance.h | 161 ----------------- .../elements/numericals/sum_role_distance.cpp | 130 +++++++++++++- .../elements/numericals/sum_role_distance.h | 166 ----------------- src/core/elements/roles/and.cpp | 15 +- src/core/elements/roles/compose.cpp | 99 +++++++++- src/core/elements/roles/compose.h | 133 -------------- src/core/elements/roles/diff.cpp | 91 +++++++++- src/core/elements/roles/diff.h | 126 ------------- src/core/elements/roles/identity.cpp | 84 ++++++++- src/core/elements/roles/identity.h | 119 ------------ src/core/elements/roles/inverse.cpp | 85 ++++++++- src/core/elements/roles/inverse.h | 118 ------------ src/core/elements/roles/not.cpp | 84 ++++++++- src/core/elements/roles/not.h | 117 ------------ src/core/elements/roles/or.cpp | 93 +++++++++- src/core/elements/roles/or.h | 127 ------------- src/core/elements/roles/primitive.cpp | 5 +- src/core/elements/roles/restrict.cpp | 97 +++++++++- src/core/elements/roles/restrict.h | 131 -------------- src/core/elements/roles/top.cpp | 70 +++++++- src/core/elements/roles/top.h | 101 ----------- .../elements/roles/transitive_closure.cpp | 97 +++++++++- src/core/elements/roles/transitive_closure.h | 130 -------------- .../roles/transitive_reflexive_closure.cpp | 103 ++++++++++- .../roles/transitive_reflexive_closure.h | 137 -------------- src/core/elements/utils.cpp | 2 +- src/generator/rules/concepts/equal.cpp | 2 +- src/policy/condition.cpp | 4 +- src/policy/effect.cpp | 4 +- src/policy/policy.cpp | 2 - src/policy/policy_factory.h | 5 +- src/policy/policy_impl.cpp | 3 - src/policy/policy_minimizer.cpp | 4 +- src/policy/rule.cpp | 3 - 99 files changed, 3922 insertions(+), 3135 deletions(-) create mode 100644 include/dlplan/core/elements/concepts/bot.h create mode 100644 include/dlplan/core/elements/concepts/diff.h create mode 100644 include/dlplan/core/elements/concepts/equal.h create mode 100644 include/dlplan/core/elements/concepts/not.h create mode 100644 include/dlplan/core/elements/concepts/one_of.h create mode 100644 include/dlplan/core/elements/concepts/or.h rename {src => include/dlplan}/core/elements/concepts/primitive.h (87%) create mode 100644 include/dlplan/core/elements/concepts/projection.h create mode 100644 include/dlplan/core/elements/concepts/some.h create mode 100644 include/dlplan/core/elements/concepts/subset.h create mode 100644 include/dlplan/core/elements/concepts/top.h create mode 100644 include/dlplan/core/elements/numericals/concept_distance.h rename {src => include/dlplan}/core/elements/numericals/count.h (98%) create mode 100644 include/dlplan/core/elements/numericals/role_distance.h create mode 100644 include/dlplan/core/elements/numericals/sum_concept_distance.h create mode 100644 include/dlplan/core/elements/numericals/sum_role_distance.h rename {src => include/dlplan}/core/elements/roles/and.h (91%) create mode 100644 include/dlplan/core/elements/roles/compose.h create mode 100644 include/dlplan/core/elements/roles/diff.h create mode 100644 include/dlplan/core/elements/roles/identity.h create mode 100644 include/dlplan/core/elements/roles/inverse.h create mode 100644 include/dlplan/core/elements/roles/not.h create mode 100644 include/dlplan/core/elements/roles/or.h rename {src => include/dlplan}/core/elements/roles/primitive.h (97%) create mode 100644 include/dlplan/core/elements/roles/restrict.h create mode 100644 include/dlplan/core/elements/roles/top.h create mode 100644 include/dlplan/core/elements/roles/transitive_closure.h create mode 100644 include/dlplan/core/elements/roles/transitive_reflexive_closure.h rename {src => include/dlplan}/core/elements/utils.h (86%) rename {src => include/dlplan}/policy/condition.h (99%) rename {src => include/dlplan}/policy/effect.h (99%) delete mode 100644 src/core/elements/booleans/empty.cpp delete mode 100644 src/core/elements/booleans/inclusion.cpp delete mode 100644 src/core/elements/concepts/diff.h delete mode 100644 src/core/elements/concepts/equal.h delete mode 100644 src/core/elements/concepts/not.h delete mode 100644 src/core/elements/concepts/one_of.h delete mode 100644 src/core/elements/concepts/or.h delete mode 100644 src/core/elements/concepts/projection.h delete mode 100644 src/core/elements/concepts/some.h delete mode 100644 src/core/elements/concepts/subset.h delete mode 100644 src/core/elements/concepts/top.h delete mode 100644 src/core/elements/numericals/concept_distance.h delete mode 100644 src/core/elements/numericals/count.cpp delete mode 100644 src/core/elements/numericals/role_distance.h delete mode 100644 src/core/elements/numericals/sum_concept_distance.h delete mode 100644 src/core/elements/numericals/sum_role_distance.h delete mode 100644 src/core/elements/roles/compose.h delete mode 100644 src/core/elements/roles/diff.h delete mode 100644 src/core/elements/roles/identity.h delete mode 100644 src/core/elements/roles/inverse.h delete mode 100644 src/core/elements/roles/not.h delete mode 100644 src/core/elements/roles/or.h delete mode 100644 src/core/elements/roles/restrict.h delete mode 100644 src/core/elements/roles/top.h delete mode 100644 src/core/elements/roles/transitive_closure.h delete mode 100644 src/core/elements/roles/transitive_reflexive_closure.h diff --git a/include/dlplan/core/elements/booleans/empty.h b/include/dlplan/core/elements/booleans/empty.h index 6508879c..25cd1d9d 100644 --- a/include/dlplan/core/elements/booleans/empty.h +++ b/include/dlplan/core/elements/booleans/empty.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_CORE_ELEMENTS_BOOLEAN_EMPTY_H_ #define DLPLAN_SRC_CORE_ELEMENTS_BOOLEAN_EMPTY_H_ -#include "../../../../../src/core/elements/utils.h" +#include "../utils.h" #include "../../../core.h" #include diff --git a/include/dlplan/core/elements/booleans/inclusion.h b/include/dlplan/core/elements/booleans/inclusion.h index 94280cfb..ecc00445 100644 --- a/include/dlplan/core/elements/booleans/inclusion.h +++ b/include/dlplan/core/elements/booleans/inclusion.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_CORE_ELEMENTS_BOOLEAN_INCLUSION_H_ #define DLPLAN_SRC_CORE_ELEMENTS_BOOLEAN_INCLUSION_H_ -#include "../../../../../src/core/elements/utils.h" +#include "../utils.h" #include "../../../core.h" #include diff --git a/include/dlplan/core/elements/booleans/nullary.h b/include/dlplan/core/elements/booleans/nullary.h index 497933a8..bf1967c0 100644 --- a/include/dlplan/core/elements/booleans/nullary.h +++ b/include/dlplan/core/elements/booleans/nullary.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_INCLUDE_DLPLAN_CORE_ELEMENTS_BOOLEANS_NULLARY_H_ #define DLPLAN_INCLUDE_DLPLAN_CORE_ELEMENTS_BOOLEANS_NULLARY_H_ -#include "../../../../../src/core/elements/utils.h" +#include "../utils.h" #include "../../../core.h" #include diff --git a/include/dlplan/core/elements/concepts/all.h b/include/dlplan/core/elements/concepts/all.h index 4baa4db1..638735e1 100644 --- a/include/dlplan/core/elements/concepts/all.h +++ b/include/dlplan/core/elements/concepts/all.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ALL_H_ #define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ALL_H_ -#include "../../../../../src/core/elements/utils.h" +#include "../utils.h" #include "../../../core.h" #include diff --git a/include/dlplan/core/elements/concepts/and.h b/include/dlplan/core/elements/concepts/and.h index 57ac5e33..ad1a45cb 100644 --- a/include/dlplan/core/elements/concepts/and.h +++ b/include/dlplan/core/elements/concepts/and.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_AND_H_ #define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_AND_H_ -#include "../../../../../src/core/elements/utils.h" +#include "../utils.h" #include "../../../core.h" #include diff --git a/include/dlplan/core/elements/concepts/bot.h b/include/dlplan/core/elements/concepts/bot.h new file mode 100644 index 00000000..d5040c82 --- /dev/null +++ b/include/dlplan/core/elements/concepts/bot.h @@ -0,0 +1,64 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_BOT_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_BOT_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class BotConcept : public Concept { +private: + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches&) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + BotConcept(ElementIndex index, std::shared_ptr vocabulary_info); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::BotConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/diff.h b/include/dlplan/core/elements/concepts/diff.h new file mode 100644 index 00000000..06e4b302 --- /dev/null +++ b/include/dlplan/core/elements/concepts/diff.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_DIFF_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_DIFF_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class DiffConcept : public Concept { +private: + const std::shared_ptr m_concept_left; + const std::shared_ptr m_concept_right; + + void compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + DiffConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::DiffConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/equal.h b/include/dlplan/core/elements/concepts/equal.h new file mode 100644 index 00000000..0a7cbb4b --- /dev/null +++ b/include/dlplan/core/elements/concepts/equal.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_EQUAL_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_EQUAL_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class EqualConcept : public Concept { +private: + const std::shared_ptr m_role_left; + const std::shared_ptr m_role_right; + + void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + EqualConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::EqualConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/not.h b/include/dlplan/core/elements/concepts/not.h new file mode 100644 index 00000000..0e35593e --- /dev/null +++ b/include/dlplan/core/elements/concepts/not.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_NOT_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_NOT_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class NotConcept : public Concept { +private: + const std::shared_ptr m_concept; + + void compute_result(const ConceptDenotation& denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + NotConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::NotConcept& concept_) const; + }; +} + + +#endif diff --git a/include/dlplan/core/elements/concepts/one_of.h b/include/dlplan/core/elements/concepts/one_of.h new file mode 100644 index 00000000..d9a04287 --- /dev/null +++ b/include/dlplan/core/elements/concepts/one_of.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ONE_OF_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ONE_OF_H_ + +#include "../utils.h" +#include "../../../core.h" + + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class OneOfConcept : public Concept { +private: + const Constant m_constant; + + void compute_result(const State& state, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches&) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + OneOfConcept(ElementIndex index, std::shared_ptr vocabulary_info, const Constant& constant); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::OneOfConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/or.h b/include/dlplan/core/elements/concepts/or.h new file mode 100644 index 00000000..645be990 --- /dev/null +++ b/include/dlplan/core/elements/concepts/or.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_OR_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_OR_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class OrConcept : public Concept { +private: + const std::shared_ptr m_concept_left; + const std::shared_ptr m_concept_right; + + void compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + OrConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::OrConcept& concept_) const; + }; +} + +#endif diff --git a/src/core/elements/concepts/primitive.h b/include/dlplan/core/elements/concepts/primitive.h similarity index 87% rename from src/core/elements/concepts/primitive.h rename to include/dlplan/core/elements/concepts/primitive.h index 0e08ee41..af175f15 100644 --- a/src/core/elements/concepts/primitive.h +++ b/include/dlplan/core/elements/concepts/primitive.h @@ -2,8 +2,7 @@ #define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_PRIMITIVE_H_ #include "../utils.h" -#include "../../../utils/collections.h" -#include "../../../../include/dlplan/core.h" +#include "../../../core.h" #include #include @@ -58,17 +57,13 @@ namespace std { { bool operator()( const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } + const std::shared_ptr& right_concept) const; }; template<> struct hash { - std::size_t operator()(const dlplan::core::PrimitiveConcept& concept_) const { - return concept_.hash(); - } + std::size_t operator()(const dlplan::core::PrimitiveConcept& concept_) const; }; } diff --git a/include/dlplan/core/elements/concepts/projection.h b/include/dlplan/core/elements/concepts/projection.h new file mode 100644 index 00000000..a8b6df09 --- /dev/null +++ b/include/dlplan/core/elements/concepts/projection.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_PROJECTION_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_PROJECTION_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class ProjectionConcept : public Concept { +private: + std::shared_ptr m_role; + int m_pos; + + void compute_result(const RoleDenotation& denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + ProjectionConcept(ElementIndex index, std::shared_ptr vocabulary_info, const std::shared_ptr& role, int pos); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::ProjectionConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/some.h b/include/dlplan/core/elements/concepts/some.h new file mode 100644 index 00000000..66acc5f6 --- /dev/null +++ b/include/dlplan/core/elements/concepts/some.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SOME_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SOME_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class SomeConcept : public Concept { +private: + const std::shared_ptr m_role; + const std::shared_ptr m_concept; + + void compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + SomeConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::SomeConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/subset.h b/include/dlplan/core/elements/concepts/subset.h new file mode 100644 index 00000000..5c7998ac --- /dev/null +++ b/include/dlplan/core/elements/concepts/subset.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SUBSET_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SUBSET_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class SubsetConcept : public Concept { +private: + const std::shared_ptr m_role_left; + const std::shared_ptr m_role_right; + + void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const; + + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + SubsetConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::SubsetConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/concepts/top.h b/include/dlplan/core/elements/concepts/top.h new file mode 100644 index 00000000..607846b3 --- /dev/null +++ b/include/dlplan/core/elements/concepts/top.h @@ -0,0 +1,64 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_TOP_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_TOP_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class TopConcept : public Concept { +private: + ConceptDenotation evaluate_impl(const State& state, DenotationsCaches&) const override; + + ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + TopConcept(ElementIndex index, std::shared_ptr vocabulary_info); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Concept& other) const override; + + size_t hash() const; + + ConceptDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::TopConcept& concept_) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/numericals/concept_distance.h b/include/dlplan/core/elements/numericals/concept_distance.h new file mode 100644 index 00000000..7ea559bf --- /dev/null +++ b/include/dlplan/core/elements/numericals/concept_distance.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_CONCEPT_DISTANCE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_CONCEPT_DISTANCE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class ConceptDistanceNumerical : public Numerical { +private: + const std::shared_ptr m_concept_from; + const std::shared_ptr m_role; + const std::shared_ptr m_concept_to; + + void compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const; + + int evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + ConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Numerical& other) const override; + + size_t hash() const; + + int evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::ConceptDistanceNumerical& numerical) const; + }; +} + +#endif diff --git a/src/core/elements/numericals/count.h b/include/dlplan/core/elements/numericals/count.h similarity index 98% rename from src/core/elements/numericals/count.h rename to include/dlplan/core/elements/numericals/count.h index 859ecdbb..fe3656c0 100644 --- a/src/core/elements/numericals/count.h +++ b/include/dlplan/core/elements/numericals/count.h @@ -2,7 +2,7 @@ #define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_COUNT_H_ #include "../utils.h" -#include "../../../../include/dlplan/core.h" +#include "../../../core.h" #include #include diff --git a/include/dlplan/core/elements/numericals/role_distance.h b/include/dlplan/core/elements/numericals/role_distance.h new file mode 100644 index 00000000..a42023c6 --- /dev/null +++ b/include/dlplan/core/elements/numericals/role_distance.h @@ -0,0 +1,70 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_ROLE_DISTANCE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_ROLE_DISTANCE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class RoleDistanceNumerical : public Numerical { +private: + const std::shared_ptr m_role_from; + const std::shared_ptr m_role; + const std::shared_ptr m_role_to; + + void compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const; + + int evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + RoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Numerical& other) const override; + + size_t hash() const; + + int evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::RoleDistanceNumerical& numerical) const; + }; +} + + +#endif diff --git a/include/dlplan/core/elements/numericals/sum_concept_distance.h b/include/dlplan/core/elements/numericals/sum_concept_distance.h new file mode 100644 index 00000000..a1c01db8 --- /dev/null +++ b/include/dlplan/core/elements/numericals/sum_concept_distance.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class SumConceptDistanceNumerical : public Numerical { +private: + const std::shared_ptr m_concept_from; + const std::shared_ptr m_role; + const std::shared_ptr m_concept_to; + + void compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const; + + int evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + SumConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Numerical& other) const override; + + size_t hash() const; + + int evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::SumConceptDistanceNumerical& numerical) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/numericals/sum_role_distance.h b/include/dlplan/core/elements/numericals/sum_role_distance.h new file mode 100644 index 00000000..133170cc --- /dev/null +++ b/include/dlplan/core/elements/numericals/sum_role_distance.h @@ -0,0 +1,70 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_ROLE_DISTANCE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_ROLE_DISTANCE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class SumRoleDistanceNumerical : public Numerical { +private: + const std::shared_ptr m_role_from; + const std::shared_ptr m_role; + const std::shared_ptr m_role_to; + + void compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const; + + int evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + SumRoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Numerical& other) const override; + + size_t hash() const; + + int evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::SumRoleDistanceNumerical& numerical) const; + }; +} + +#endif diff --git a/src/core/elements/roles/and.h b/include/dlplan/core/elements/roles/and.h similarity index 91% rename from src/core/elements/roles/and.h rename to include/dlplan/core/elements/roles/and.h index 669d8bef..448ab13c 100644 --- a/src/core/elements/roles/and.h +++ b/include/dlplan/core/elements/roles/and.h @@ -2,7 +2,7 @@ #define DLPLAN_SRC_CORE_ELEMENTS_ROLES_AND_H_ #include "../utils.h" -#include "../../../../include/dlplan/core.h" +#include "../../../core.h" #include #include @@ -55,17 +55,13 @@ namespace std { { bool operator()( const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } + const std::shared_ptr& right_role) const; }; template<> struct hash { - std::size_t operator()(const dlplan::core::AndRole& role) const { - return role.hash(); - } + std::size_t operator()(const dlplan::core::AndRole& role) const; }; } diff --git a/include/dlplan/core/elements/roles/compose.h b/include/dlplan/core/elements/roles/compose.h new file mode 100644 index 00000000..c665641b --- /dev/null +++ b/include/dlplan/core/elements/roles/compose.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_COMPOSE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_COMPOSE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class ComposeRole : public Role { +private: + const std::shared_ptr m_role_left; + const std::shared_ptr m_role_right; + + void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + ComposeRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::ComposeRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/diff.h b/include/dlplan/core/elements/roles/diff.h new file mode 100644 index 00000000..8a3a4b55 --- /dev/null +++ b/include/dlplan/core/elements/roles/diff.h @@ -0,0 +1,70 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_DIFF_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_DIFF_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + + +namespace dlplan::core { +class DiffRole : public Role { +private: + const std::shared_ptr m_role_left; + const std::shared_ptr m_role_right; + + void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + DiffRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::DiffRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/identity.h b/include/dlplan/core/elements/roles/identity.h new file mode 100644 index 00000000..bf39eb71 --- /dev/null +++ b/include/dlplan/core/elements/roles/identity.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_IDENTITY_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_IDENTITY_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class IdentityRole : public Role { +private: + const std::shared_ptr m_concept; + + void compute_result(const ConceptDenotation& denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + IdentityRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::IdentityRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/inverse.h b/include/dlplan/core/elements/roles/inverse.h new file mode 100644 index 00000000..e2c6d792 --- /dev/null +++ b/include/dlplan/core/elements/roles/inverse.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_INVERSE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_INVERSE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class InverseRole : public Role { +private: + const std::shared_ptr m_role; + + void compute_result(const RoleDenotation& denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + InverseRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::InverseRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/not.h b/include/dlplan/core/elements/roles/not.h new file mode 100644 index 00000000..39f9c46e --- /dev/null +++ b/include/dlplan/core/elements/roles/not.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_NOT_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_NOT_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class NotRole : public Role { +private: + const std::shared_ptr m_role; + + void compute_result(const RoleDenotation& denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + NotRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::NotRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/or.h b/include/dlplan/core/elements/roles/or.h new file mode 100644 index 00000000..059243c8 --- /dev/null +++ b/include/dlplan/core/elements/roles/or.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_OR_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_OR_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class OrRole : public Role { +private: + const std::shared_ptr m_role_left; + const std::shared_ptr m_role_right; + + void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + OrRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_1, std::shared_ptr role_2); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::OrRole& role) const; + }; +} + +#endif diff --git a/src/core/elements/roles/primitive.h b/include/dlplan/core/elements/roles/primitive.h similarity index 97% rename from src/core/elements/roles/primitive.h rename to include/dlplan/core/elements/roles/primitive.h index b0e6071f..d4c6fe28 100644 --- a/src/core/elements/roles/primitive.h +++ b/include/dlplan/core/elements/roles/primitive.h @@ -1,7 +1,8 @@ #ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_PRIMITIVE_H_ #define DLPLAN_SRC_CORE_ELEMENTS_ROLES_PRIMITIVE_H_ -#include "../../../../include/dlplan/core.h" +#include "../utils.h" +#include "../../../core.h" #include #include diff --git a/include/dlplan/core/elements/roles/restrict.h b/include/dlplan/core/elements/roles/restrict.h new file mode 100644 index 00000000..1661426f --- /dev/null +++ b/include/dlplan/core/elements/roles/restrict.h @@ -0,0 +1,68 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_RESTRICT_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_RESTRICT_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class RestrictRole : public Role { +private: + const std::shared_ptr m_role; + const std::shared_ptr m_concept; + + void compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + RestrictRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::RestrictRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/top.h b/include/dlplan/core/elements/roles/top.h new file mode 100644 index 00000000..059ed4ef --- /dev/null +++ b/include/dlplan/core/elements/roles/top.h @@ -0,0 +1,64 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TOP_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TOP_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class TopRole : public Role { +private: + RoleDenotation evaluate_impl(const State& state, DenotationsCaches&) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + TopRole(ElementIndex index, std::shared_ptr vocabulary_info); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::TopRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/transitive_closure.h b/include/dlplan/core/elements/roles/transitive_closure.h new file mode 100644 index 00000000..27af1ab9 --- /dev/null +++ b/include/dlplan/core/elements/roles/transitive_closure.h @@ -0,0 +1,69 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_CLOSURE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_CLOSURE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +// https://stackoverflow.com/questions/3517524/what-is-the-best-known-transitive-closure-algorithm-for-a-directed-graph +class TransitiveClosureRole : public Role { +private: + const std::shared_ptr m_role; + + void compute_result(const RoleDenotation& denot, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + TransitiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role); + + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::TransitiveClosureRole& role) const; + }; +} + +#endif diff --git a/include/dlplan/core/elements/roles/transitive_reflexive_closure.h b/include/dlplan/core/elements/roles/transitive_reflexive_closure.h new file mode 100644 index 00000000..4360a582 --- /dev/null +++ b/include/dlplan/core/elements/roles/transitive_reflexive_closure.h @@ -0,0 +1,67 @@ +#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ +#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ + +#include "../utils.h" +#include "../../../core.h" + +#include +#include + +using namespace std::string_literals; + + +namespace dlplan::utils { +template +class ReferenceCountedObjectFactory; +} + + +namespace dlplan::core { +class TransitiveReflexiveClosureRole : public Role { +private: + const std::shared_ptr m_role; + + void compute_result(const RoleDenotation& denot, int num_objects, RoleDenotation& result) const; + + RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override; + + RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override; + + TransitiveReflexiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role); + template + friend class dlplan::utils::ReferenceCountedObjectFactory; + +public: + bool operator==(const Role& other) const override; + + size_t hash() const; + + RoleDenotation evaluate(const State& state) const override; + + int compute_complexity() const override; + + void compute_repr(std::stringstream& out) const override; + + int compute_evaluate_time_score() const override; +}; + +} + + +namespace std { + template<> + struct less> + { + bool operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const; + }; + + template<> + struct hash + { + std::size_t operator()(const dlplan::core::TransitiveReflexiveClosureRole& role) const; + }; +} + +#endif diff --git a/src/core/elements/utils.h b/include/dlplan/core/elements/utils.h similarity index 86% rename from src/core/elements/utils.h rename to include/dlplan/core/elements/utils.h index cd9c0113..529ee946 100644 --- a/src/core/elements/utils.h +++ b/include/dlplan/core/elements/utils.h @@ -1,7 +1,7 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_UTILS_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_UTILS_H_ +#ifndef DLPLAN_INCLUDE_DLPLAN_CORE_ELEMENTS_UTILS_H_ +#define DLPLAN_INCLUDE_DLPLAN_CORE_ELEMENTS_UTILS_H_ -#include "../../../include/dlplan/core.h" +#include "../../core.h" const int SCORE_CONSTANT = 1; diff --git a/src/policy/condition.h b/include/dlplan/policy/condition.h similarity index 99% rename from src/policy/condition.h rename to include/dlplan/policy/condition.h index 3a5da7ec..b9ab8b97 100644 --- a/src/policy/condition.h +++ b/include/dlplan/policy/condition.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_POLICY_CONDITION_H_ #define DLPLAN_SRC_POLICY_CONDITION_H_ -#include "../../include/dlplan/policy.h" +#include "../policy.h" #include #include diff --git a/src/policy/effect.h b/include/dlplan/policy/effect.h similarity index 99% rename from src/policy/effect.h rename to include/dlplan/policy/effect.h index ce5c6b6c..863dc8e3 100644 --- a/src/policy/effect.h +++ b/include/dlplan/policy/effect.h @@ -1,7 +1,7 @@ #ifndef DLPLAN_SRC_POLICY_EFFECT_H_ #define DLPLAN_SRC_POLICY_EFFECT_H_ -#include "../../include/dlplan/policy.h" +#include "../policy.h" #include #include diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 49fa0d99..15e5cca6 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,8 +13,6 @@ target_sources(dlplancore core.cpp denotations_caches.cpp element_factory.cpp - elements/booleans/empty.cpp - elements/booleans/inclusion.cpp elements/booleans/nullary.cpp elements/concepts/all.cpp elements/concepts/and.cpp @@ -22,6 +20,7 @@ target_sources(dlplancore elements/concepts/diff.cpp elements/concepts/equal.cpp elements/concepts/not.cpp + elements/concepts/one_of.cpp elements/concepts/or.cpp elements/concepts/primitive.cpp elements/concepts/projection.cpp @@ -29,7 +28,6 @@ target_sources(dlplancore elements/concepts/subset.cpp elements/concepts/top.cpp elements/numericals/concept_distance.cpp - elements/numericals/count.cpp elements/numericals/role_distance.cpp elements/numericals/sum_concept_distance.cpp elements/numericals/sum_role_distance.cpp diff --git a/src/core/element_factory.h b/src/core/element_factory.h index 30b1eb76..f98a385e 100644 --- a/src/core/element_factory.h +++ b/src/core/element_factory.h @@ -7,33 +7,33 @@ #include "../../include/dlplan/core/elements/concepts/all.h" #include "../../include/dlplan/core/elements/concepts/and.h" #include "../../include/dlplan/core/elements/concepts/bot.h" -#include "elements/concepts/diff.h" -#include "elements/concepts/equal.h" -#include "elements/concepts/not.h" -#include "elements/concepts/one_of.h" -#include "elements/concepts/or.h" -#include "elements/concepts/projection.h" -#include "elements/concepts/primitive.h" -#include "elements/concepts/some.h" -#include "elements/concepts/subset.h" -#include "elements/concepts/top.h" -#include "elements/numericals/concept_distance.h" -#include "elements/numericals/count.h" -#include "elements/numericals/role_distance.h" -#include "elements/numericals/sum_concept_distance.h" -#include "elements/numericals/sum_role_distance.h" -#include "elements/roles/and.h" -#include "elements/roles/compose.h" -#include "elements/roles/diff.h" -#include "elements/roles/identity.h" -#include "elements/roles/inverse.h" -#include "elements/roles/not.h" -#include "elements/roles/or.h" -#include "elements/roles/primitive.h" -#include "elements/roles/restrict.h" -#include "elements/roles/top.h" -#include "elements/roles/transitive_closure.h" -#include "elements/roles/transitive_reflexive_closure.h" +#include "../../include/dlplan/core/elements/concepts/diff.h" +#include "../../include/dlplan/core/elements/concepts/equal.h" +#include "../../include/dlplan/core/elements/concepts/not.h" +#include "../../include/dlplan/core/elements/concepts/one_of.h" +#include "../../include/dlplan/core/elements/concepts/or.h" +#include "../../include/dlplan/core/elements/concepts/projection.h" +#include "../../include/dlplan/core/elements/concepts/primitive.h" +#include "../../include/dlplan/core/elements/concepts/some.h" +#include "../../include/dlplan/core/elements/concepts/subset.h" +#include "../../include/dlplan/core/elements/concepts/top.h" +#include "../../include/dlplan/core/elements/numericals/concept_distance.h" +#include "../../include/dlplan/core/elements/numericals/count.h" +#include "../../include/dlplan/core/elements/numericals/role_distance.h" +#include "../../include/dlplan/core/elements/numericals/sum_concept_distance.h" +#include "../../include/dlplan/core/elements/numericals/sum_role_distance.h" +#include "../../include/dlplan/core/elements/roles/and.h" +#include "../../include/dlplan/core/elements/roles/compose.h" +#include "../../include/dlplan/core/elements/roles/diff.h" +#include "../../include/dlplan/core/elements/roles/identity.h" +#include "../../include/dlplan/core/elements/roles/inverse.h" +#include "../../include/dlplan/core/elements/roles/not.h" +#include "../../include/dlplan/core/elements/roles/or.h" +#include "../../include/dlplan/core/elements/roles/primitive.h" +#include "../../include/dlplan/core/elements/roles/restrict.h" +#include "../../include/dlplan/core/elements/roles/top.h" +#include "../../include/dlplan/core/elements/roles/transitive_closure.h" +#include "../../include/dlplan/core/elements/roles/transitive_reflexive_closure.h" #include "../../include/dlplan/core.h" diff --git a/src/core/elements/booleans/empty.cpp b/src/core/elements/booleans/empty.cpp deleted file mode 100644 index 3a6e19af..00000000 --- a/src/core/elements/booleans/empty.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "../../../../include/dlplan/core/elements/booleans/empty.h" - -namespace dlplan::core { - -} diff --git a/src/core/elements/booleans/inclusion.cpp b/src/core/elements/booleans/inclusion.cpp deleted file mode 100644 index 2202fd55..00000000 --- a/src/core/elements/booleans/inclusion.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "../../../../include/dlplan/core/elements/booleans/inclusion.h" diff --git a/src/core/elements/concepts/diff.cpp b/src/core/elements/concepts/diff.cpp index 713485ac..0e7a8c92 100644 --- a/src/core/elements/concepts/diff.cpp +++ b/src/core/elements/concepts/diff.cpp @@ -1 +1,90 @@ -#include "diff.h" +#include "../../../../include/dlplan/core/elements/concepts/diff.h" + + +namespace dlplan::core { +void DiffConcept::compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const { + result = left_denot; + result -= right_denot; +} + +ConceptDenotation DiffConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_concept_left->evaluate(state, caches), + *m_concept_right->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations DiffConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto concept_left_denotations = m_concept_left->evaluate(states, caches); + auto concept_right_denotations = m_concept_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*concept_left_denotations)[i], + *(*concept_right_denotations)[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +DiffConcept::DiffConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2) + : Concept(vocabulary_info, index, concept_1->is_static() && concept_2->is_static()), m_concept_left(concept_1), m_concept_right(concept_2) { } + +bool DiffConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept_left == other_derived.m_concept_left + && m_concept_right == other_derived.m_concept_right; + } + return false; +} + +size_t DiffConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept_left, m_concept_right); +} + +ConceptDenotation DiffConcept::evaluate(const State& state) const { + ConceptDenotation result(state.get_instance_info()->get_objects().size()); + compute_result( + m_concept_left->evaluate(state), + m_concept_right->evaluate(state), + result); + return result; +} + +int DiffConcept::compute_complexity() const { + return m_concept_left->compute_complexity() + m_concept_right->compute_complexity() + 1; +} + +void DiffConcept::compute_repr(std::stringstream& out) const { + out << "c_diff" << "("; + m_concept_left->compute_repr(out); + out << ","; + m_concept_right->compute_repr(out); + out << ")"; +} + +int DiffConcept::compute_evaluate_time_score() const { + return m_concept_left->compute_evaluate_time_score() + m_concept_right->compute_evaluate_time_score() + SCORE_LINEAR; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::DiffConcept& concept_) const { + return concept_.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/concepts/diff.h b/src/core/elements/concepts/diff.h deleted file mode 100644 index 06c0c1b0..00000000 --- a/src/core/elements/concepts/diff.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_DIFF_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_DIFF_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class DiffConcept : public Concept { -private: - const std::shared_ptr m_concept_left; - const std::shared_ptr m_concept_right; - - void compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const { - result = left_denot; - result -= right_denot; - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_concept_left->evaluate(state, caches), - *m_concept_right->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto concept_left_denotations = m_concept_left->evaluate(states, caches); - auto concept_right_denotations = m_concept_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*concept_left_denotations)[i], - *(*concept_right_denotations)[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - DiffConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2) - : Concept(vocabulary_info, index, concept_1->is_static() && concept_2->is_static()), m_concept_left(concept_1), m_concept_right(concept_2) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept_left == other_derived.m_concept_left - && m_concept_right == other_derived.m_concept_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept_left, m_concept_right); - } - - ConceptDenotation evaluate(const State& state) const override { - ConceptDenotation result(state.get_instance_info()->get_objects().size()); - compute_result( - m_concept_left->evaluate(state), - m_concept_right->evaluate(state), - result); - return result; - } - - int compute_complexity() const override { - return m_concept_left->compute_complexity() + m_concept_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_diff" << "("; - m_concept_left->compute_repr(out); - out << ","; - m_concept_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept_left->compute_evaluate_time_score() + m_concept_right->compute_evaluate_time_score() + SCORE_LINEAR; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::DiffConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/equal.cpp b/src/core/elements/concepts/equal.cpp index b385f54a..07ea5af0 100644 --- a/src/core/elements/concepts/equal.cpp +++ b/src/core/elements/concepts/equal.cpp @@ -1 +1,98 @@ -#include "equal.h" +#include "../../../../include/dlplan/core/elements/concepts/equal.h" + + +namespace dlplan::core { +void EqualConcept::compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const { + // find counterexample [(a,b) in R and (a,b) not in S] or [(a,b) not in R and (a,b) in S] + result.set(); + for (const auto& pair : left_denot.to_vector()) { + if (!right_denot.contains(pair)) result.erase(pair.first); + } + for (const auto& pair : right_denot.to_vector()) { + if (!left_denot.contains(pair)) result.erase(pair.first); + } +} + +ConceptDenotation EqualConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role_left->evaluate(state, caches), + *m_role_right->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations EqualConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto role_left_denotations = m_role_left->evaluate(states, caches); + auto role_right_denotations = m_role_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_left_denotations)[i], + *(*role_right_denotations)[i], + denotation); + // register denotation and append it to denotations. + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +EqualConcept::EqualConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) + : Concept(vocabulary_info, index, role_left->is_static() && role_right->is_static()), + m_role_left(role_left), m_role_right(role_right) { } + +bool EqualConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_left == other_derived.m_role_left + && m_role_right == other_derived.m_role_right; + } + return false; +} + +size_t EqualConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); +} + +ConceptDenotation EqualConcept::evaluate(const State& state) const { + auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role_left->evaluate(state), + m_role_right->evaluate(state), + denotation); + return denotation; +} + +int EqualConcept::compute_complexity() const { + return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; +} + +void EqualConcept::compute_repr(std::stringstream& out) const { + out << "c_equal" << "("; + m_role_left->compute_repr(out); + out << ","; + m_role_right->compute_repr(out); + out << ")"; +} + +int EqualConcept::compute_evaluate_time_score() const { + return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::EqualConcept& concept_) const { + return concept_.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/concepts/equal.h b/src/core/elements/concepts/equal.h deleted file mode 100644 index 47c76861..00000000 --- a/src/core/elements/concepts/equal.h +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_EQUAL_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_EQUAL_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class EqualConcept : public Concept { -private: - const std::shared_ptr m_role_left; - const std::shared_ptr m_role_right; - - void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const { - // find counterexample [(a,b) in R and (a,b) not in S] or [(a,b) not in R and (a,b) in S] - result.set(); - for (const auto& pair : left_denot.to_vector()) { - if (!right_denot.contains(pair)) result.erase(pair.first); - } - for (const auto& pair : right_denot.to_vector()) { - if (!left_denot.contains(pair)) result.erase(pair.first); - } - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role_left->evaluate(state, caches), - *m_role_right->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto role_left_denotations = m_role_left->evaluate(states, caches); - auto role_right_denotations = m_role_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_left_denotations)[i], - *(*role_right_denotations)[i], - denotation); - // register denotation and append it to denotations. - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - EqualConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) - : Concept(vocabulary_info, index, role_left->is_static() && role_right->is_static()), - m_role_left(role_left), m_role_right(role_right) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_left == other_derived.m_role_left - && m_role_right == other_derived.m_role_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); - } - - ConceptDenotation evaluate(const State& state) const override { - auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role_left->evaluate(state), - m_role_right->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_equal" << "("; - m_role_left->compute_repr(out); - out << ","; - m_role_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::EqualConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/not.cpp b/src/core/elements/concepts/not.cpp index 77795366..f68e9b14 100644 --- a/src/core/elements/concepts/not.cpp +++ b/src/core/elements/concepts/not.cpp @@ -1 +1,85 @@ -#include "not.h" +#include "../../../../include/dlplan/core/elements/concepts/not.h" + + + +namespace dlplan::core { +void NotConcept::compute_result(const ConceptDenotation& denot, ConceptDenotation& result) const { + result = denot; + ~result; +} + +ConceptDenotation NotConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_concept->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations NotConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + // get denotations of children + auto concept_denotations = m_concept->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*concept_denotations)[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +NotConcept::NotConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept) + : Concept(vocabulary_info, index, concept->is_static()), m_concept(concept){ } + +bool NotConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept == other_derived.m_concept; + } + return false; +} + +size_t NotConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept); +} + +ConceptDenotation NotConcept::evaluate(const State& state) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_concept->evaluate(state), + denotation); + return denotation; +} + +int NotConcept::compute_complexity() const { + return m_concept->compute_complexity() + 1; +} + +void NotConcept::compute_repr(std::stringstream& out) const { + out << "c_not" << "("; + m_concept->compute_repr(out); + out << ")"; +} + +int NotConcept::compute_evaluate_time_score() const { + return m_concept->compute_evaluate_time_score() + SCORE_LINEAR; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::NotConcept& concept_) const { + return concept_.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/concepts/not.h b/src/core/elements/concepts/not.h deleted file mode 100644 index 406f258f..00000000 --- a/src/core/elements/concepts/not.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_NOT_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_NOT_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class NotConcept : public Concept { -private: - const std::shared_ptr m_concept; - - void compute_result(const ConceptDenotation& denot, ConceptDenotation& result) const { - result = denot; - ~result; - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_concept->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - // get denotations of children - auto concept_denotations = m_concept->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*concept_denotations)[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - NotConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept) - : Concept(vocabulary_info, index, concept->is_static()), m_concept(concept){ } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept == other_derived.m_concept; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept); - } - - ConceptDenotation evaluate(const State& state) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_concept->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_concept->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_not" << "("; - m_concept->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept->compute_evaluate_time_score() + SCORE_LINEAR; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::NotConcept& concept_) const { - return concept_.hash(); - } - }; -} - - -#endif diff --git a/src/core/elements/concepts/one_of.cpp b/src/core/elements/concepts/one_of.cpp index 602b17bf..ed565c6b 100644 --- a/src/core/elements/concepts/one_of.cpp +++ b/src/core/elements/concepts/one_of.cpp @@ -1 +1,87 @@ -#include "one_of.h" +#include "../../../../include/dlplan/core/elements/concepts/one_of.h" + + +namespace dlplan::core { +void OneOfConcept::compute_result(const State& state, ConceptDenotation& result) const { + bool found = false; + for (const auto& object : state.get_instance_info()->get_objects()) { + if (object.get_name() == m_constant.get_name()) { + result.insert(object.get_index()); + found = true; + break; + } + } + if (!found) { + throw std::runtime_error("OneOfConcept::evaluate - no object with name of constant exists in instance: (" + m_constant.get_name() + ")"); + } +} + +ConceptDenotation OneOfConcept::evaluate_impl(const State& state, DenotationsCaches&) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + state, + denotation); + return denotation; +} + +ConceptDenotations OneOfConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + states[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +OneOfConcept::OneOfConcept(ElementIndex index, std::shared_ptr vocabulary_info, const Constant& constant) + : Concept(vocabulary_info, index, true), m_constant(constant) { } + +bool OneOfConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_constant == other_derived.m_constant; + } + return false; +} + +size_t OneOfConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_constant); +} + +ConceptDenotation OneOfConcept::evaluate(const State& state) const { + ConceptDenotation result(state.get_instance_info()->get_objects().size()); + compute_result(state, result); + return result; +} + +int OneOfConcept::compute_complexity() const { + return 1; +} + +void OneOfConcept::compute_repr(std::stringstream& out) const { + out << "c_one_of" << "(" << m_constant.get_name() << ")"; +} + +int OneOfConcept::compute_evaluate_time_score() const { + return SCORE_LINEAR; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::OneOfConcept& concept_) const { + return concept_.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/concepts/one_of.h b/src/core/elements/concepts/one_of.h deleted file mode 100644 index 4120ffa3..00000000 --- a/src/core/elements/concepts/one_of.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ONE_OF_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_ONE_OF_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class OneOfConcept : public Concept { -private: - const Constant m_constant; - - void compute_result(const State& state, ConceptDenotation& result) const { - bool found = false; - for (const auto& object : state.get_instance_info()->get_objects()) { - if (object.get_name() == m_constant.get_name()) { - result.insert(object.get_index()); - found = true; - break; - } - } - if (!found) { - throw std::runtime_error("OneOfConcept::evaluate - no object with name of constant exists in instance: (" + m_constant.get_name() + ")"); - } - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches&) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - state, - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - states[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - OneOfConcept(ElementIndex index, std::shared_ptr vocabulary_info, const Constant& constant) - : Concept(vocabulary_info, index, true), m_constant(constant) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_constant == other_derived.m_constant; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_constant); - } - - ConceptDenotation evaluate(const State& state) const override { - ConceptDenotation result(state.get_instance_info()->get_objects().size()); - compute_result(state, result); - return result; - } - - int compute_complexity() const override { - return 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_one_of" << "(" << m_constant.get_name() << ")"; - } - - int compute_evaluate_time_score() const override { - return SCORE_LINEAR; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::OneOfConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/or.cpp b/src/core/elements/concepts/or.cpp index aa3e2b4c..252f6272 100644 --- a/src/core/elements/concepts/or.cpp +++ b/src/core/elements/concepts/or.cpp @@ -1,2 +1,93 @@ -#include "or.h" +#include "../../../../include/dlplan/core/elements/concepts/or.h" + +namespace dlplan::core { +void OrConcept::compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const { + result = left_denot; + result |= right_denot; +} + +ConceptDenotation OrConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + denotation.set(); + compute_result( + *m_concept_left->evaluate(state, caches), + *m_concept_right->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations OrConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto concept_left_denotations = m_concept_left->evaluate(states, caches); + auto concept_right_denotations = m_concept_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*concept_left_denotations)[i], + *(*concept_right_denotations)[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +OrConcept::OrConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2) + : Concept(vocabulary_info, index, concept_1->is_static() && concept_2->is_static()), + m_concept_left(concept_1->get_index() < concept_2->get_index() ? concept_1 : concept_2), + m_concept_right(concept_1->get_index() < concept_2->get_index() ? concept_2 : concept_1) { } + +bool OrConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept_left == other_derived.m_concept_left + && m_concept_right == other_derived.m_concept_right; + } + return false; +} + +size_t OrConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept_left, m_concept_right); +} + +ConceptDenotation OrConcept::evaluate(const State& state) const { + ConceptDenotation result(state.get_instance_info()->get_objects().size()); + compute_result( + m_concept_left->evaluate(state), + m_concept_right->evaluate(state), + result); + return result; +} + +int OrConcept::compute_complexity() const { + return m_concept_left->compute_complexity() + m_concept_right->compute_complexity() + 1; +} + +void OrConcept::compute_repr(std::stringstream& out) const { + out << "c_or" << "("; + m_concept_left->compute_repr(out); + out << ","; + m_concept_right->compute_repr(out); + out << ")"; +} + +int OrConcept::compute_evaluate_time_score() const { + return m_concept_left->compute_evaluate_time_score() + m_concept_right->compute_evaluate_time_score() + SCORE_LINEAR; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::OrConcept& concept_) const { + return concept_.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/concepts/or.h b/src/core/elements/concepts/or.h deleted file mode 100644 index eb61038e..00000000 --- a/src/core/elements/concepts/or.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_OR_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_OR_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class OrConcept : public Concept { -private: - const std::shared_ptr m_concept_left; - const std::shared_ptr m_concept_right; - - void compute_result(const ConceptDenotation& left_denot, const ConceptDenotation& right_denot, ConceptDenotation& result) const { - result = left_denot; - result |= right_denot; - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - denotation.set(); - compute_result( - *m_concept_left->evaluate(state, caches), - *m_concept_right->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto concept_left_denotations = m_concept_left->evaluate(states, caches); - auto concept_right_denotations = m_concept_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*concept_left_denotations)[i], - *(*concept_right_denotations)[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - OrConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_1, std::shared_ptr concept_2) - : Concept(vocabulary_info, index, concept_1->is_static() && concept_2->is_static()), - m_concept_left(concept_1->get_index() < concept_2->get_index() ? concept_1 : concept_2), - m_concept_right(concept_1->get_index() < concept_2->get_index() ? concept_2 : concept_1) { } - - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept_left == other_derived.m_concept_left - && m_concept_right == other_derived.m_concept_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept_left, m_concept_right); - } - - ConceptDenotation evaluate(const State& state) const override { - ConceptDenotation result(state.get_instance_info()->get_objects().size()); - compute_result( - m_concept_left->evaluate(state), - m_concept_right->evaluate(state), - result); - return result; - } - - int compute_complexity() const override { - return m_concept_left->compute_complexity() + m_concept_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_or" << "("; - m_concept_left->compute_repr(out); - out << ","; - m_concept_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept_left->compute_evaluate_time_score() + m_concept_right->compute_evaluate_time_score() + SCORE_LINEAR; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::OrConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/primitive.cpp b/src/core/elements/concepts/primitive.cpp index 5cea3bb2..f298d113 100644 --- a/src/core/elements/concepts/primitive.cpp +++ b/src/core/elements/concepts/primitive.cpp @@ -1,4 +1,6 @@ -#include "primitive.h" +#include "../../../../include/dlplan/core/elements/concepts/primitive.h" + +#include "../../../utils/collections.h" namespace dlplan::core { @@ -81,3 +83,16 @@ int PrimitiveConcept::compute_evaluate_time_score() const { } } + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::PrimitiveConcept& concept_) const { + return concept_.hash(); + } +} diff --git a/src/core/elements/concepts/projection.cpp b/src/core/elements/concepts/projection.cpp index 3fefe220..b0e8d17a 100644 --- a/src/core/elements/concepts/projection.cpp +++ b/src/core/elements/concepts/projection.cpp @@ -1 +1,90 @@ -#include "projection.h" +#include "../../../../include/dlplan/core/elements/concepts/projection.h" + + +namespace dlplan::core { +void ProjectionConcept::compute_result(const RoleDenotation& denot, ConceptDenotation& result) const { + for (const auto& pair : denot.to_vector()) { + if (m_pos == 0) result.insert(pair.first); + else if (m_pos == 1) result.insert(pair.second); + } +} + +ConceptDenotation ProjectionConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations ProjectionConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +ProjectionConcept::ProjectionConcept(ElementIndex index, std::shared_ptr vocabulary_info, const std::shared_ptr& role, int pos) +: Concept(vocabulary_info, index, role->is_static()), m_role(role), m_pos(pos) { + if (pos < 0 || pos > 1) { + throw std::runtime_error("ProjectionConcept::ProjectionConcept - projection index out of range, should be 0 or 1 ("s + std::to_string(pos) + ")"); + } +} + +bool ProjectionConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role + && m_pos == other_derived.m_pos; + } + return false; +} + +size_t ProjectionConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role, m_pos); +} + +ConceptDenotation ProjectionConcept::evaluate(const State& state) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + denotation); + return denotation; +} + +int ProjectionConcept::compute_complexity() const { + return m_role->compute_complexity() + 1; +} + +void ProjectionConcept::compute_repr(std::stringstream& out) const { + out << "c_projection" << "("; + m_role->compute_repr(out); + out << "," << std::to_string(m_pos) << ")"; +} + +int ProjectionConcept::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::ProjectionConcept& concept_) const { + return concept_.hash(); + } +} diff --git a/src/core/elements/concepts/projection.h b/src/core/elements/concepts/projection.h deleted file mode 100644 index b5f5375f..00000000 --- a/src/core/elements/concepts/projection.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_PROJECTION_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_PROJECTION_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class ProjectionConcept : public Concept { -private: - std::shared_ptr m_role; - int m_pos; - - void compute_result(const RoleDenotation& denot, ConceptDenotation& result) const { - for (const auto& pair : denot.to_vector()) { - if (m_pos == 0) result.insert(pair.first); - else if (m_pos == 1) result.insert(pair.second); - } - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - ProjectionConcept(ElementIndex index, std::shared_ptr vocabulary_info, const std::shared_ptr& role, int pos) - : Concept(vocabulary_info, index, role->is_static()), m_role(role), m_pos(pos) { - if (pos < 0 || pos > 1) { - throw std::runtime_error("ProjectionConcept::ProjectionConcept - projection index out of range, should be 0 or 1 ("s + std::to_string(pos) + ")"); - } - } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role - && m_pos == other_derived.m_pos; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role, m_pos); - } - - ConceptDenotation evaluate(const State& state) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_projection" << "("; - m_role->compute_repr(out); - out << "," << std::to_string(m_pos) << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::ProjectionConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/some.cpp b/src/core/elements/concepts/some.cpp index 4a66c4df..1891001d 100644 --- a/src/core/elements/concepts/some.cpp +++ b/src/core/elements/concepts/some.cpp @@ -1,2 +1,94 @@ -#include "some.h" +#include "../../../../include/dlplan/core/elements/concepts/some.h" + +namespace dlplan::core { +void SomeConcept::compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, ConceptDenotation& result) const { + // find examples a : exists b . (a,b) in R and b in C + for (const auto& pair : role_denot.to_vector()) { + if (concept_denot.contains(pair.second)) { + result.insert(pair.first); + } + } +} + +ConceptDenotation SomeConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + *m_concept->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations SomeConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + auto concept_denotations = m_concept->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + *(*concept_denotations)[i], + denotation); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +SomeConcept::SomeConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept) + : Concept(vocabulary_info, index, role->is_static() && concept->is_static()), m_role(role), m_concept(concept) { } + +bool SomeConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role + && m_concept == other_derived.m_concept; + } + return false; +} + +size_t SomeConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role, m_concept); +} + +ConceptDenotation SomeConcept::evaluate(const State& state) const { + auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + m_concept->evaluate(state), + denotation); + return denotation; +} + +int SomeConcept::compute_complexity() const { + return m_role->compute_complexity() + m_concept->compute_complexity() + 1; +} + +void SomeConcept::compute_repr(std::stringstream& out) const { + out << "c_some" << "("; + m_role->compute_repr(out); + out << ","; + m_concept->compute_repr(out); + out << ")"; +} + +int SomeConcept::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + m_concept->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::SomeConcept& concept_) const { + return concept_.hash(); + } +} diff --git a/src/core/elements/concepts/some.h b/src/core/elements/concepts/some.h deleted file mode 100644 index 2a661915..00000000 --- a/src/core/elements/concepts/some.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SOME_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SOME_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include -#include -#include -#include - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class SomeConcept : public Concept { -private: - const std::shared_ptr m_role; - const std::shared_ptr m_concept; - - void compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, ConceptDenotation& result) const { - // find examples a : exists b . (a,b) in R and b in C - for (const auto& pair : role_denot.to_vector()) { - if (concept_denot.contains(pair.second)) { - result.insert(pair.first); - } - } - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - *m_concept->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - auto concept_denotations = m_concept->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - *(*concept_denotations)[i], - denotation); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - SomeConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept) - : Concept(vocabulary_info, index, role->is_static() && concept->is_static()), m_role(role), m_concept(concept) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role - && m_concept == other_derived.m_concept; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role, m_concept); - } - - ConceptDenotation evaluate(const State& state) const override { - auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - m_concept->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + m_concept->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_some" << "("; - m_role->compute_repr(out); - out << ","; - m_concept->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + m_concept->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::SomeConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/subset.cpp b/src/core/elements/concepts/subset.cpp index d3b3fdf5..7d07add3 100644 --- a/src/core/elements/concepts/subset.cpp +++ b/src/core/elements/concepts/subset.cpp @@ -1 +1,94 @@ -#include "subset.h" +#include "../../../../include/dlplan/core/elements/concepts/subset.h" + + +namespace dlplan::core { +void SubsetConcept::compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const { + // find counterexamples a : exists b . (a,b) in R and (a,b) notin S + result.set(); + for (const auto& pair : left_denot.to_vector()) { + if (!right_denot.contains(pair)) result.erase(pair.first); + } +} + +ConceptDenotation SubsetConcept::evaluate_impl(const State& state, DenotationsCaches& caches) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role_left->evaluate(state, caches), + *m_role_right->evaluate(state, caches), + denotation); + return denotation; +} + +ConceptDenotations SubsetConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + auto role_left_denotations = m_role_left->evaluate(states, caches); + auto role_right_denotations = m_role_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_left_denotations)[i], + *(*role_right_denotations)[i], + denotation); + // register denotation and append it to denotations. + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +SubsetConcept::SubsetConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) + : Concept(vocabulary_info, index, role_left->is_static() && role_right->is_static()), m_role_left(role_left), m_role_right(role_right) { } + +bool SubsetConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_left == other_derived.m_role_left + && m_role_right == other_derived.m_role_right; + } + return false; +} + +size_t SubsetConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); +} + +ConceptDenotation SubsetConcept::evaluate(const State& state) const { + auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role_left->evaluate(state), + m_role_right->evaluate(state), + denotation); + return denotation; +} + +int SubsetConcept::compute_complexity() const { + return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; +} + +void SubsetConcept::compute_repr(std::stringstream& out) const { + out << "c_subset" << "("; + m_role_left->compute_repr(out); + out << ","; + m_role_right->compute_repr(out); + out << ")"; +} + +int SubsetConcept::compute_evaluate_time_score() const { + return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::SubsetConcept& concept_) const { + return concept_.hash(); + } +} diff --git a/src/core/elements/concepts/subset.h b/src/core/elements/concepts/subset.h deleted file mode 100644 index 4c212ec1..00000000 --- a/src/core/elements/concepts/subset.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SUBSET_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_SUBSET_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class SubsetConcept : public Concept { -private: - const std::shared_ptr m_role_left; - const std::shared_ptr m_role_right; - - void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, ConceptDenotation& result) const { - // find counterexamples a : exists b . (a,b) in R and (a,b) notin S - result.set(); - for (const auto& pair : left_denot.to_vector()) { - if (!right_denot.contains(pair)) result.erase(pair.first); - } - } - - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role_left->evaluate(state, caches), - *m_role_right->evaluate(state, caches), - denotation); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - auto role_left_denotations = m_role_left->evaluate(states, caches); - auto role_right_denotations = m_role_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_left_denotations)[i], - *(*role_right_denotations)[i], - denotation); - // register denotation and append it to denotations. - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - SubsetConcept(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) - : Concept(vocabulary_info, index, role_left->is_static() && role_right->is_static()), m_role_left(role_left), m_role_right(role_right) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_left == other_derived.m_role_left - && m_role_right == other_derived.m_role_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); - } - - ConceptDenotation evaluate(const State& state) const override { - auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role_left->evaluate(state), - m_role_right->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_subset" << "("; - m_role_left->compute_repr(out); - out << ","; - m_role_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::SubsetConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/concepts/top.cpp b/src/core/elements/concepts/top.cpp index 16ec9e05..e5274138 100644 --- a/src/core/elements/concepts/top.cpp +++ b/src/core/elements/concepts/top.cpp @@ -1 +1,69 @@ -#include "top.h" +#include "../../../../include/dlplan/core/elements/concepts/top.h" + + +namespace dlplan::core { +ConceptDenotation TopConcept::evaluate_impl(const State& state, DenotationsCaches&) const { + ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); + denotation.set(); + return denotation; +} + +ConceptDenotations TopConcept::evaluate_impl(const States& states, DenotationsCaches& caches) const { + ConceptDenotations denotations; + denotations.reserve(states.size()); + for (size_t i = 0; i < states.size(); ++i) { + ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); + denotation.set(); + denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +TopConcept::TopConcept(ElementIndex index, std::shared_ptr vocabulary_info) + : Concept(vocabulary_info, index, true) { +} + +bool TopConcept::operator==(const Concept& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static; + } + return false; +} + +size_t TopConcept::hash() const { + return dlplan::utils::hash_combine(m_is_static); +} + +ConceptDenotation TopConcept::evaluate(const State& state) const { + auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); + denotation.set(); + return denotation; +} + +int TopConcept::compute_complexity() const { + return 1; +} + +void TopConcept::compute_repr(std::stringstream& out) const { + out << "c_top"; +} + +int TopConcept::compute_evaluate_time_score() const { + return SCORE_CONSTANT; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_concept, + const std::shared_ptr& right_concept) const { + return *left_concept < *right_concept; + } + + std::size_t hash::operator()(const dlplan::core::TopConcept& concept_) const { + return concept_.hash(); + } +} diff --git a/src/core/elements/concepts/top.h b/src/core/elements/concepts/top.h deleted file mode 100644 index 288c08a6..00000000 --- a/src/core/elements/concepts/top.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_TOP_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_CONCEPTS_TOP_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class TopConcept : public Concept { -private: - ConceptDenotation evaluate_impl(const State& state, DenotationsCaches&) const override { - ConceptDenotation denotation(state.get_instance_info()->get_objects().size()); - denotation.set(); - return denotation; - } - - ConceptDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - ConceptDenotations denotations; - denotations.reserve(states.size()); - for (size_t i = 0; i < states.size(); ++i) { - ConceptDenotation denotation(states[i].get_instance_info()->get_objects().size()); - denotation.set(); - denotations.push_back(caches.concept_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - TopConcept(ElementIndex index, std::shared_ptr vocabulary_info) - : Concept(vocabulary_info, index, true) { - } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Concept& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static); - } - - ConceptDenotation evaluate(const State& state) const override { - auto denotation = ConceptDenotation(state.get_instance_info()->get_objects().size()); - denotation.set(); - return denotation; - } - - int compute_complexity() const override { - return 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "c_top"; - } - - int compute_evaluate_time_score() const override { - return SCORE_CONSTANT; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_concept, - const std::shared_ptr& right_concept) const { - return *left_concept < *right_concept; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::TopConcept& concept_) const { - return concept_.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/numericals/concept_distance.cpp b/src/core/elements/numericals/concept_distance.cpp index e9512354..0df839df 100644 --- a/src/core/elements/numericals/concept_distance.cpp +++ b/src/core/elements/numericals/concept_distance.cpp @@ -1,2 +1,128 @@ -#include "concept_distance.h" +#include "../../../../include/dlplan/core/elements/numericals/concept_distance.h" + +namespace dlplan::core { +void ConceptDistanceNumerical::compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const { + result = utils::compute_multi_source_multi_target_shortest_distance(concept_from_denot, role_denot, concept_to_denot); +} + +int ConceptDistanceNumerical::evaluate_impl(const State& state, DenotationsCaches& caches) const { + auto concept_from_denot = m_concept_from->evaluate(state, caches); + if (concept_from_denot->empty()) { + return INF; + } + auto concept_to_denot = m_concept_to->evaluate(state, caches); + if (concept_to_denot->empty()) { + return INF; + } + if (concept_from_denot->intersects(*concept_to_denot)) { + return 0; + } + auto role_denot = m_role->evaluate(state, caches); + int denotation; + compute_result( + *concept_from_denot, + *role_denot, + *concept_to_denot, denotation); + return denotation; +} + +NumericalDenotations ConceptDistanceNumerical::evaluate_impl(const States& states, DenotationsCaches& caches) const { + NumericalDenotations denotations; + denotations.reserve(states.size()); + auto concept_from_denots = m_concept_from->evaluate(states, caches); + auto role_denots = m_role->evaluate(states, caches); + auto concept_to_denots = m_concept_to->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + if ((*concept_from_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + if ((*concept_to_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + if ((*concept_from_denots)[i]->intersects(*(*concept_to_denots)[i])) { + denotations.push_back(0); + continue; + } + int denotation; + compute_result( + *(*concept_from_denots)[i], + *(*role_denots)[i], + *(*concept_to_denots)[i], + denotation); + denotations.push_back(denotation); + } + return denotations; +} + +ConceptDistanceNumerical::ConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to) + : Numerical(vocabulary_info, index, concept_from->is_static() && role->is_static() && concept_to->is_static()), + m_concept_from(concept_from), m_role(role), m_concept_to(concept_to) { } + +bool ConceptDistanceNumerical::operator==(const Numerical& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept_from == other_derived.m_concept_from + && m_role == other_derived.m_role + && m_concept_to == other_derived.m_concept_to; + } + return false; +} + +size_t ConceptDistanceNumerical::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept_from, m_role, m_concept_to); +} + +int ConceptDistanceNumerical::evaluate(const State& state) const { + auto concept_from_denot = m_concept_from->evaluate(state); + if (concept_from_denot.empty()) { + return INF; + } + auto concept_to_denot = m_concept_to->evaluate(state); + if (concept_to_denot.empty()) { + return INF; + } + if (concept_from_denot.intersects(concept_to_denot)) { + return 0; + } + auto role_denot = m_role->evaluate(state); + int denotation; + compute_result(concept_from_denot, role_denot, concept_to_denot, denotation); + return denotation; +} + +int ConceptDistanceNumerical::compute_complexity() const { + return m_concept_from->compute_complexity() + m_role->compute_complexity() + m_concept_to->compute_complexity() + 1; +} + +void ConceptDistanceNumerical::compute_repr(std::stringstream& out) const { + out << "n_concept_distance" << "("; + m_concept_from->compute_repr(out); + out << ","; + m_role->compute_repr(out); + out << ","; + m_concept_to->compute_repr(out); + out << ")"; +} + +int ConceptDistanceNumerical::compute_evaluate_time_score() const { + return m_concept_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_concept_to->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const { + return *left_numerical < *right_numerical; + } + + std::size_t hash::operator()(const dlplan::core::ConceptDistanceNumerical& numerical) const { + return numerical.hash(); + } +} diff --git a/src/core/elements/numericals/concept_distance.h b/src/core/elements/numericals/concept_distance.h deleted file mode 100644 index 7b531699..00000000 --- a/src/core/elements/numericals/concept_distance.h +++ /dev/null @@ -1,165 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_CONCEPT_DISTANCE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_CONCEPT_DISTANCE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { - -class ConceptDistanceNumerical : public Numerical { -private: - const std::shared_ptr m_concept_from; - const std::shared_ptr m_role; - const std::shared_ptr m_concept_to; - - void compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const { - result = utils::compute_multi_source_multi_target_shortest_distance(concept_from_denot, role_denot, concept_to_denot); - } - - int evaluate_impl(const State& state, DenotationsCaches& caches) const override { - auto concept_from_denot = m_concept_from->evaluate(state, caches); - if (concept_from_denot->empty()) { - return INF; - } - auto concept_to_denot = m_concept_to->evaluate(state, caches); - if (concept_to_denot->empty()) { - return INF; - } - if (concept_from_denot->intersects(*concept_to_denot)) { - return 0; - } - auto role_denot = m_role->evaluate(state, caches); - int denotation; - compute_result( - *concept_from_denot, - *role_denot, - *concept_to_denot, denotation); - return denotation; - } - - NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - NumericalDenotations denotations; - denotations.reserve(states.size()); - auto concept_from_denots = m_concept_from->evaluate(states, caches); - auto role_denots = m_role->evaluate(states, caches); - auto concept_to_denots = m_concept_to->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - if ((*concept_from_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - if ((*concept_to_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - if ((*concept_from_denots)[i]->intersects(*(*concept_to_denots)[i])) { - denotations.push_back(0); - continue; - } - int denotation; - compute_result( - *(*concept_from_denots)[i], - *(*role_denots)[i], - *(*concept_to_denots)[i], - denotation); - denotations.push_back(denotation); - } - return denotations; - } - - ConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to) - : Numerical(vocabulary_info, index, concept_from->is_static() && role->is_static() && concept_to->is_static()), - m_concept_from(concept_from), m_role(role), m_concept_to(concept_to) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Numerical& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept_from == other_derived.m_concept_from - && m_role == other_derived.m_role - && m_concept_to == other_derived.m_concept_to; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept_from, m_role, m_concept_to); - } - - int evaluate(const State& state) const override { - auto concept_from_denot = m_concept_from->evaluate(state); - if (concept_from_denot.empty()) { - return INF; - } - auto concept_to_denot = m_concept_to->evaluate(state); - if (concept_to_denot.empty()) { - return INF; - } - if (concept_from_denot.intersects(concept_to_denot)) { - return 0; - } - auto role_denot = m_role->evaluate(state); - int denotation; - compute_result(concept_from_denot, role_denot, concept_to_denot, denotation); - return denotation; - } - - int compute_complexity() const override { - return m_concept_from->compute_complexity() + m_role->compute_complexity() + m_concept_to->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "n_concept_distance" << "("; - m_concept_from->compute_repr(out); - out << ","; - m_role->compute_repr(out); - out << ","; - m_concept_to->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_concept_to->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_numerical, - const std::shared_ptr& right_numerical) const { - return *left_numerical < *right_numerical; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::ConceptDistanceNumerical& numerical) const { - return numerical.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/numericals/count.cpp b/src/core/elements/numericals/count.cpp deleted file mode 100644 index 11496392..00000000 --- a/src/core/elements/numericals/count.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "count.h" - - -namespace dlplan::core { - -} diff --git a/src/core/elements/numericals/role_distance.cpp b/src/core/elements/numericals/role_distance.cpp index 981e137c..6694d245 100644 --- a/src/core/elements/numericals/role_distance.cpp +++ b/src/core/elements/numericals/role_distance.cpp @@ -1 +1,128 @@ -#include "role_distance.h" +#include "../../../../include/dlplan/core/elements/numericals/role_distance.h" + + +namespace dlplan::core { +void RoleDistanceNumerical::compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const { + utils::PairwiseDistances pairwise_distances = utils::compute_floyd_warshall(role_denot); + result = INF; + int num_objects = role_denot.get_num_objects(); + for (int k = 0; k < num_objects; ++k) { // property + for (int i = 0; i < num_objects; ++i) { // source + if (role_from_denot.contains(std::make_pair(k, i))) { + for (int j = 0; j < num_objects; ++j) { // target + if (role_to_denot.contains(std::make_pair(k, j))) { + result = std::min(result, pairwise_distances[i][j]); + } + } + } + } + } +} + +int RoleDistanceNumerical::evaluate_impl(const State& state, DenotationsCaches& caches) const { + auto role_from_denot = m_role_from->evaluate(state, caches); + if (role_from_denot->empty()) { + return INF; + } + auto role_to_denot = m_role_to->evaluate(state, caches); + if (role_to_denot->empty()) { + return INF; + } + auto role_denot = m_role->evaluate(state, caches); + int denotation; + compute_result(*role_from_denot, *role_denot, *role_to_denot, denotation); + return denotation; +} + +NumericalDenotations RoleDistanceNumerical::evaluate_impl(const States& states, DenotationsCaches& caches) const { + NumericalDenotations denotations; + denotations.reserve(states.size()); + auto role_from_denots = m_role_from->evaluate(states, caches); + auto role_denots = m_role->evaluate(states, caches); + auto role_to_denots = m_role_to->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + if ((*role_from_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + if ((*role_to_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + int denotation; + compute_result( + *(*role_from_denots)[i], + *(*role_denots)[i], + *(*role_to_denots)[i], + denotation); + denotations.push_back(denotation); + } + return denotations; +} + +RoleDistanceNumerical::RoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to) + : Numerical(vocabulary_info, index, role_from->is_static() && role->is_static() && role_to->is_static()), + m_role_from(role_from), m_role(role), m_role_to(role_to) { } + +bool RoleDistanceNumerical::operator==(const Numerical& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_from == other_derived.m_role_from + && m_role == other_derived.m_role + && m_role_to == other_derived.m_role_to; + } + return false; +} + +size_t RoleDistanceNumerical::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_from, m_role, m_role_to); +} + +int RoleDistanceNumerical::evaluate(const State& state) const { + auto role_from_denot = m_role_from->evaluate(state); + if (role_from_denot.empty()) { + return INF; + } + auto role_to_denot = m_role_to->evaluate(state); + if (role_to_denot.empty()) { + return INF; + } + auto role_denot = m_role->evaluate(state); + int denotation; + compute_result(role_from_denot, role_denot, role_to_denot, denotation); + return denotation; +} + +int RoleDistanceNumerical::compute_complexity() const { + return m_role_from->compute_complexity() + m_role->compute_complexity() + m_role_to->compute_complexity() + 1; +} + +void RoleDistanceNumerical::compute_repr(std::stringstream& out) const { + out << "n_role_distance_numerical" << "("; + m_role_from->compute_repr(out); + out << ","; + m_role->compute_repr(out); + out << ","; + m_role_to->compute_repr(out); + out << ")"; +} + +int RoleDistanceNumerical::compute_evaluate_time_score() const { + return m_role_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_role_to->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const { + return *left_numerical < *right_numerical; + } + + std::size_t hash::operator()(const dlplan::core::RoleDistanceNumerical& numerical) const { + return numerical.hash(); + } +} diff --git a/src/core/elements/numericals/role_distance.h b/src/core/elements/numericals/role_distance.h deleted file mode 100644 index 8c689166..00000000 --- a/src/core/elements/numericals/role_distance.h +++ /dev/null @@ -1,170 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_ROLE_DISTANCE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_ROLE_DISTANCE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class RoleDistanceNumerical; -} - - -namespace dlplan::core { -class RoleDistanceNumerical : public Numerical { -private: - const std::shared_ptr m_role_from; - const std::shared_ptr m_role; - const std::shared_ptr m_role_to; - - void compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const { - utils::PairwiseDistances pairwise_distances = utils::compute_floyd_warshall(role_denot); - result = INF; - int num_objects = role_denot.get_num_objects(); - for (int k = 0; k < num_objects; ++k) { // property - for (int i = 0; i < num_objects; ++i) { // source - if (role_from_denot.contains(std::make_pair(k, i))) { - for (int j = 0; j < num_objects; ++j) { // target - if (role_to_denot.contains(std::make_pair(k, j))) { - result = std::min(result, pairwise_distances[i][j]); - } - } - } - } - } - } - - int evaluate_impl(const State& state, DenotationsCaches& caches) const override { - auto role_from_denot = m_role_from->evaluate(state, caches); - if (role_from_denot->empty()) { - return INF; - } - auto role_to_denot = m_role_to->evaluate(state, caches); - if (role_to_denot->empty()) { - return INF; - } - auto role_denot = m_role->evaluate(state, caches); - int denotation; - compute_result(*role_from_denot, *role_denot, *role_to_denot, denotation); - return denotation; - } - - NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - NumericalDenotations denotations; - denotations.reserve(states.size()); - auto role_from_denots = m_role_from->evaluate(states, caches); - auto role_denots = m_role->evaluate(states, caches); - auto role_to_denots = m_role_to->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - if ((*role_from_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - if ((*role_to_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - int denotation; - compute_result( - *(*role_from_denots)[i], - *(*role_denots)[i], - *(*role_to_denots)[i], - denotation); - denotations.push_back(denotation); - } - return denotations; - } - - RoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to) - : Numerical(vocabulary_info, index, role_from->is_static() && role->is_static() && role_to->is_static()), - m_role_from(role_from), m_role(role), m_role_to(role_to) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Numerical& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_from == other_derived.m_role_from - && m_role == other_derived.m_role - && m_role_to == other_derived.m_role_to; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_from, m_role, m_role_to); - } - - int evaluate(const State& state) const override { - auto role_from_denot = m_role_from->evaluate(state); - if (role_from_denot.empty()) { - return INF; - } - auto role_to_denot = m_role_to->evaluate(state); - if (role_to_denot.empty()) { - return INF; - } - auto role_denot = m_role->evaluate(state); - int denotation; - compute_result(role_from_denot, role_denot, role_to_denot, denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_from->compute_complexity() + m_role->compute_complexity() + m_role_to->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "n_role_distance_numerical" << "("; - m_role_from->compute_repr(out); - out << ","; - m_role->compute_repr(out); - out << ","; - m_role_to->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_role_to->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_numerical, - const std::shared_ptr& right_numerical) const { - return *left_numerical < *right_numerical; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::RoleDistanceNumerical& numerical) const { - return numerical.hash(); - } - }; -} - - -#endif diff --git a/src/core/elements/numericals/sum_concept_distance.cpp b/src/core/elements/numericals/sum_concept_distance.cpp index 87f982ec..9327799f 100644 --- a/src/core/elements/numericals/sum_concept_distance.cpp +++ b/src/core/elements/numericals/sum_concept_distance.cpp @@ -1 +1,125 @@ -#include "sum_concept_distance.h" +#include "../../../../include/dlplan/core/elements/numericals/sum_concept_distance.h" + + +namespace dlplan::core { +void SumConceptDistanceNumerical::compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const { + result = 0; + utils::Distances source_distances = utils::compute_multi_source_multi_target_shortest_distances(concept_from_denot, role_denot, concept_to_denot); + for (const auto target : concept_to_denot.to_vector()) { + result = utils::path_addition(result, source_distances[target]); + } +} + +int SumConceptDistanceNumerical::evaluate_impl(const State& state, DenotationsCaches& caches) const { + auto concept_from_denot = m_concept_from->evaluate(state, caches); + if (concept_from_denot->empty()) { + return INF; + } + auto concept_to_denot = m_concept_to->evaluate(state, caches); + if (concept_to_denot->empty()) { + return INF; + } + if (concept_from_denot->intersects(*concept_to_denot)) { + return 0; + } + auto role_denot = m_role->evaluate(state, caches); + int denotation; + compute_result( + *concept_from_denot, + *role_denot, + *concept_to_denot, denotation); + return denotation; +} + +NumericalDenotations SumConceptDistanceNumerical::evaluate_impl(const States& states, DenotationsCaches& caches) const { + NumericalDenotations denotations; + denotations.reserve(states.size()); + auto concept_from_denots = m_concept_from->evaluate(states, caches); + auto role_denots = m_role->evaluate(states, caches); + auto concept_to_denots = m_concept_to->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + if ((*concept_from_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + if ((*concept_to_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + int denotation; + compute_result( + *(*concept_from_denots)[i], + *(*role_denots)[i], + *(*concept_to_denots)[i], + denotation); + denotations.push_back(denotation); + } + return denotations; +} + +SumConceptDistanceNumerical::SumConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to) + : Numerical(vocabulary_info, index, concept_from->is_static() && role->is_static() && concept_to->is_static()), + m_concept_from(concept_from), m_role(role), m_concept_to(concept_to) { } + +bool SumConceptDistanceNumerical::operator==(const Numerical& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept_from == other_derived.m_concept_from + && m_role == other_derived.m_role + && m_concept_to == other_derived.m_concept_to; + } + return false; +} + +size_t SumConceptDistanceNumerical::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept_from, m_role, m_concept_to); +} + +int SumConceptDistanceNumerical::evaluate(const State& state) const { + auto concept_from_denot = m_concept_from->evaluate(state); + if (concept_from_denot.empty()) { + return INF; + } + auto concept_to_denot = m_concept_to->evaluate(state); + if (concept_to_denot.empty()) { + return INF; + } + auto role_denot = m_role->evaluate(state); + int denotation; + compute_result(concept_from_denot, role_denot, concept_to_denot, denotation); + return denotation; +} + +int SumConceptDistanceNumerical::compute_complexity() const { + return m_concept_from->compute_complexity() + m_role->compute_complexity() + m_concept_to->compute_complexity() + 1; +} + +void SumConceptDistanceNumerical::compute_repr(std::stringstream& out) const { + out << "n_sum_concept_distance" << "("; + m_concept_from->compute_repr(out); + out << ","; + m_role->compute_repr(out); + out << ","; + m_concept_to->compute_repr(out); + out << ")"; +} + +int SumConceptDistanceNumerical::compute_evaluate_time_score() const { + return m_concept_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_concept_to->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const { + return *left_numerical < *right_numerical; + } + + std::size_t hash::operator()(const dlplan::core::SumConceptDistanceNumerical& numerical) const { + return numerical.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/numericals/sum_concept_distance.h b/src/core/elements/numericals/sum_concept_distance.h deleted file mode 100644 index 48b40d36..00000000 --- a/src/core/elements/numericals/sum_concept_distance.h +++ /dev/null @@ -1,161 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_CONCEPT_DISTANCE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class SumConceptDistanceNumerical : public Numerical { -private: - const std::shared_ptr m_concept_from; - const std::shared_ptr m_role; - const std::shared_ptr m_concept_to; - - void compute_result(const ConceptDenotation& concept_from_denot, const RoleDenotation& role_denot, const ConceptDenotation& concept_to_denot, int& result) const { - result = 0; - utils::Distances source_distances = utils::compute_multi_source_multi_target_shortest_distances(concept_from_denot, role_denot, concept_to_denot); - for (const auto target : concept_to_denot.to_vector()) { - result = utils::path_addition(result, source_distances[target]); - } - } - - int evaluate_impl(const State& state, DenotationsCaches& caches) const override { - auto concept_from_denot = m_concept_from->evaluate(state, caches); - if (concept_from_denot->empty()) { - return INF; - } - auto concept_to_denot = m_concept_to->evaluate(state, caches); - if (concept_to_denot->empty()) { - return INF; - } - if (concept_from_denot->intersects(*concept_to_denot)) { - return 0; - } - auto role_denot = m_role->evaluate(state, caches); - int denotation; - compute_result( - *concept_from_denot, - *role_denot, - *concept_to_denot, denotation); - return denotation; - } - - NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - NumericalDenotations denotations; - denotations.reserve(states.size()); - auto concept_from_denots = m_concept_from->evaluate(states, caches); - auto role_denots = m_role->evaluate(states, caches); - auto concept_to_denots = m_concept_to->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - if ((*concept_from_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - if ((*concept_to_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - int denotation; - compute_result( - *(*concept_from_denots)[i], - *(*role_denots)[i], - *(*concept_to_denots)[i], - denotation); - denotations.push_back(denotation); - } - return denotations; - } - - SumConceptDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept_from, std::shared_ptr role, std::shared_ptr concept_to) - : Numerical(vocabulary_info, index, concept_from->is_static() && role->is_static() && concept_to->is_static()), - m_concept_from(concept_from), m_role(role), m_concept_to(concept_to) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Numerical& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept_from == other_derived.m_concept_from - && m_role == other_derived.m_role - && m_concept_to == other_derived.m_concept_to; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept_from, m_role, m_concept_to); - } - - int evaluate(const State& state) const override { - auto concept_from_denot = m_concept_from->evaluate(state); - if (concept_from_denot.empty()) { - return INF; - } - auto concept_to_denot = m_concept_to->evaluate(state); - if (concept_to_denot.empty()) { - return INF; - } - auto role_denot = m_role->evaluate(state); - int denotation; - compute_result(concept_from_denot, role_denot, concept_to_denot, denotation); - return denotation; - } - - int compute_complexity() const override { - return m_concept_from->compute_complexity() + m_role->compute_complexity() + m_concept_to->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "n_sum_concept_distance" << "("; - m_concept_from->compute_repr(out); - out << ","; - m_role->compute_repr(out); - out << ","; - m_concept_to->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_concept_to->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_numerical, - const std::shared_ptr& right_numerical) const { - return *left_numerical < *right_numerical; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::SumConceptDistanceNumerical& numerical) const { - return numerical.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/numericals/sum_role_distance.cpp b/src/core/elements/numericals/sum_role_distance.cpp index 4a8ff3ae..cbb4cd99 100644 --- a/src/core/elements/numericals/sum_role_distance.cpp +++ b/src/core/elements/numericals/sum_role_distance.cpp @@ -1,2 +1,130 @@ -#include "sum_role_distance.h" +#include "../../../../include/dlplan/core/elements/numericals/sum_role_distance.h" + +namespace dlplan::core { +void SumRoleDistanceNumerical::compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const { + utils::PairwiseDistances pairwise_distances = utils::compute_floyd_warshall(role_denot); + result = 0; + int num_objects = role_denot.get_num_objects(); + for (int k = 0; k < num_objects; ++k) { // property + for (int i = 0; i < num_objects; ++i) { // source + if (role_from_denot.contains(std::make_pair(k, i))) { + int min_distance = INF; + for (int j = 0; j < num_objects; ++j) { // target + if (role_to_denot.contains(std::make_pair(k, j))) { + min_distance = std::min(min_distance, pairwise_distances[i][j]); + } + } + result = utils::path_addition(result, min_distance); + } + } + } +} + +int SumRoleDistanceNumerical::evaluate_impl(const State& state, DenotationsCaches& caches) const { + auto role_from_denot = m_role_from->evaluate(state, caches); + if (role_from_denot->empty()) { + return INF; + } + auto role_to_denot = m_role_to->evaluate(state, caches); + if (role_to_denot->empty()) { + return INF; + } + auto role_denot = m_role->evaluate(state, caches); + int denotation; + compute_result(*role_from_denot, *role_denot, *role_to_denot, denotation); + return denotation; +} + +NumericalDenotations SumRoleDistanceNumerical::evaluate_impl(const States& states, DenotationsCaches& caches) const { + NumericalDenotations denotations; + denotations.reserve(states.size()); + auto role_from_denots = m_role_from->evaluate(states, caches); + auto role_denots = m_role->evaluate(states, caches); + auto role_to_denots = m_role_to->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + if ((*role_from_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + if ((*role_to_denots)[i]->empty()) { + denotations.push_back(INF); + continue; + } + int denotation; + compute_result( + *(*role_from_denots)[i], + *(*role_denots)[i], + *(*role_to_denots)[i], + denotation); + denotations.push_back(denotation); + } + return denotations; +} + +SumRoleDistanceNumerical::SumRoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to) + : Numerical(vocabulary_info, index, role_from->is_static() && role->is_static() && role_to->is_static()), + m_role_from(role_from), m_role(role), m_role_to(role_to) { } + +bool SumRoleDistanceNumerical::operator==(const Numerical& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_from == other_derived.m_role_from + && m_role == other_derived.m_role + && m_role_to == other_derived.m_role_to; + } + return false; +} + +size_t SumRoleDistanceNumerical::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_from, m_role, m_role_to); +} + +int SumRoleDistanceNumerical::evaluate(const State& state) const { + auto role_from_denot = m_role_from->evaluate(state); + if (role_from_denot.empty()) { + return INF; + } + auto role_to_denot = m_role_to->evaluate(state); + if (role_to_denot.empty()) { + return INF; + } + auto role_denot = m_role->evaluate(state); + int denotation; + compute_result(role_from_denot, role_denot, role_to_denot, denotation); + return denotation; +} + +int SumRoleDistanceNumerical::compute_complexity() const { + return m_role_from->compute_complexity() + m_role->compute_complexity() + m_role_to->compute_complexity() + 1; +} + +void SumRoleDistanceNumerical::compute_repr(std::stringstream& out) const { + out << "n_sum_role_distance" << "("; + m_role_from->compute_repr(out); + out << ","; + m_role->compute_repr(out); + out << ","; + m_role_to->compute_repr(out); + out << ")"; +} + +int SumRoleDistanceNumerical::compute_evaluate_time_score() const { + return m_role_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_role_to->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_numerical, + const std::shared_ptr& right_numerical) const { + return *left_numerical < *right_numerical; + } + + std::size_t hash::operator()(const dlplan::core::SumRoleDistanceNumerical& numerical) const { + return numerical.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/numericals/sum_role_distance.h b/src/core/elements/numericals/sum_role_distance.h deleted file mode 100644 index c13fd99a..00000000 --- a/src/core/elements/numericals/sum_role_distance.h +++ /dev/null @@ -1,166 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_ROLE_DISTANCE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_NUMERICAL_SUM_ROLE_DISTANCE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class SumRoleDistanceNumerical : public Numerical { -private: - const std::shared_ptr m_role_from; - const std::shared_ptr m_role; - const std::shared_ptr m_role_to; - - void compute_result(const RoleDenotation& role_from_denot, const RoleDenotation& role_denot, const RoleDenotation& role_to_denot, int& result) const { - utils::PairwiseDistances pairwise_distances = utils::compute_floyd_warshall(role_denot); - result = 0; - int num_objects = role_denot.get_num_objects(); - for (int k = 0; k < num_objects; ++k) { // property - for (int i = 0; i < num_objects; ++i) { // source - if (role_from_denot.contains(std::make_pair(k, i))) { - int min_distance = INF; - for (int j = 0; j < num_objects; ++j) { // target - if (role_to_denot.contains(std::make_pair(k, j))) { - min_distance = std::min(min_distance, pairwise_distances[i][j]); - } - } - result = utils::path_addition(result, min_distance); - } - } - } - } - - int evaluate_impl(const State& state, DenotationsCaches& caches) const override { - auto role_from_denot = m_role_from->evaluate(state, caches); - if (role_from_denot->empty()) { - return INF; - } - auto role_to_denot = m_role_to->evaluate(state, caches); - if (role_to_denot->empty()) { - return INF; - } - auto role_denot = m_role->evaluate(state, caches); - int denotation; - compute_result(*role_from_denot, *role_denot, *role_to_denot, denotation); - return denotation; - } - - NumericalDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - NumericalDenotations denotations; - denotations.reserve(states.size()); - auto role_from_denots = m_role_from->evaluate(states, caches); - auto role_denots = m_role->evaluate(states, caches); - auto role_to_denots = m_role_to->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - if ((*role_from_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - if ((*role_to_denots)[i]->empty()) { - denotations.push_back(INF); - continue; - } - int denotation; - compute_result( - *(*role_from_denots)[i], - *(*role_denots)[i], - *(*role_to_denots)[i], - denotation); - denotations.push_back(denotation); - } - return denotations; - } - - SumRoleDistanceNumerical(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_from, std::shared_ptr role, std::shared_ptr role_to) - : Numerical(vocabulary_info, index, role_from->is_static() && role->is_static() && role_to->is_static()), - m_role_from(role_from), m_role(role), m_role_to(role_to) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Numerical& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_from == other_derived.m_role_from - && m_role == other_derived.m_role - && m_role_to == other_derived.m_role_to; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_from, m_role, m_role_to); - } - - int evaluate(const State& state) const override { - auto role_from_denot = m_role_from->evaluate(state); - if (role_from_denot.empty()) { - return INF; - } - auto role_to_denot = m_role_to->evaluate(state); - if (role_to_denot.empty()) { - return INF; - } - auto role_denot = m_role->evaluate(state); - int denotation; - compute_result(role_from_denot, role_denot, role_to_denot, denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_from->compute_complexity() + m_role->compute_complexity() + m_role_to->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "n_sum_role_distance" << "("; - m_role_from->compute_repr(out); - out << ","; - m_role->compute_repr(out); - out << ","; - m_role_to->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_from->compute_evaluate_time_score() + m_role->compute_evaluate_time_score() + m_role_to->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_numerical, - const std::shared_ptr& right_numerical) const { - return *left_numerical < *right_numerical; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::SumRoleDistanceNumerical& numerical) const { - return numerical.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/and.cpp b/src/core/elements/roles/and.cpp index b5b1aa51..d0a28c14 100644 --- a/src/core/elements/roles/and.cpp +++ b/src/core/elements/roles/and.cpp @@ -1,4 +1,4 @@ -#include "and.h" +#include "../../../../include/dlplan/core/elements/roles/and.h" namespace dlplan::core { @@ -78,3 +78,16 @@ int AndRole::compute_evaluate_time_score() const { } } + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::AndRole& role) const { + return role.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/roles/compose.cpp b/src/core/elements/roles/compose.cpp index 9ef56b53..6072277b 100644 --- a/src/core/elements/roles/compose.cpp +++ b/src/core/elements/roles/compose.cpp @@ -1 +1,98 @@ -#include "compose.h" +#include "../../../../include/dlplan/core/elements/roles/compose.h" + + +namespace dlplan::core { +void ComposeRole::compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { + // Compute sparse representation. + PairsOfObjectIndices left_pairs = left_denot.to_vector(); + PairsOfObjectIndices right_pairs = right_denot.to_vector(); + for (const auto& left_pair : left_pairs) { // source + for (const auto& right_pair : right_pairs) { // target + if (left_pair.second == right_pair.first) { + result.insert(std::make_pair(left_pair.first, right_pair.second)); + } + } + } +} + +RoleDenotation ComposeRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role_left->evaluate(state, caches), + *m_role_right->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations ComposeRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_left_denotations = m_role_left->evaluate(states, caches); + auto role_right_denotations = m_role_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_left_denotations)[i], + *(*role_right_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +ComposeRole::ComposeRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) + : Role(vocabulary_info, index, role_left->is_static() && role_right->is_static()), m_role_left(role_left), m_role_right(role_right) { } + +bool ComposeRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_left == other_derived.m_role_left + && m_role_right == other_derived.m_role_right; + } + return false; +} + +size_t ComposeRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); +} + +RoleDenotation ComposeRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role_left->evaluate(state), + m_role_right->evaluate(state), + denotation); + return denotation; +} + +int ComposeRole::compute_complexity() const { + return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; +} + +void ComposeRole::compute_repr(std::stringstream& out) const { + out << "r_compose" << "("; + m_role_left->compute_repr(out); + out << ","; + m_role_right->compute_repr(out); + out << ")"; +} + +int ComposeRole::compute_evaluate_time_score() const { + return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::ComposeRole& role) const { + return role.hash(); + } +} \ No newline at end of file diff --git a/src/core/elements/roles/compose.h b/src/core/elements/roles/compose.h deleted file mode 100644 index fd68ff08..00000000 --- a/src/core/elements/roles/compose.h +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_COMPOSE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_COMPOSE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class ComposeRole : public Role { -private: - const std::shared_ptr m_role_left; - const std::shared_ptr m_role_right; - - void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { - // Compute sparse representation. - PairsOfObjectIndices left_pairs = left_denot.to_vector(); - PairsOfObjectIndices right_pairs = right_denot.to_vector(); - for (const auto& left_pair : left_pairs) { // source - for (const auto& right_pair : right_pairs) { // target - if (left_pair.second == right_pair.first) { - result.insert(std::make_pair(left_pair.first, right_pair.second)); - } - } - } - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role_left->evaluate(state, caches), - *m_role_right->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_left_denotations = m_role_left->evaluate(states, caches); - auto role_right_denotations = m_role_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_left_denotations)[i], - *(*role_right_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - ComposeRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) - : Role(vocabulary_info, index, role_left->is_static() && role_right->is_static()), m_role_left(role_left), m_role_right(role_right) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_left == other_derived.m_role_left - && m_role_right == other_derived.m_role_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role_left->evaluate(state), - m_role_right->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_compose" << "("; - m_role_left->compute_repr(out); - out << ","; - m_role_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::ComposeRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/diff.cpp b/src/core/elements/roles/diff.cpp index 713485ac..e139820c 100644 --- a/src/core/elements/roles/diff.cpp +++ b/src/core/elements/roles/diff.cpp @@ -1 +1,90 @@ -#include "diff.h" +#include "../../../../include/dlplan/core/elements/roles/diff.h" + + +namespace dlplan::core { +void DiffRole::compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { + result = left_denot; + result -= right_denot; +} + +RoleDenotation DiffRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role_left->evaluate(state, caches), + *m_role_right->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations DiffRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_left_denotations = m_role_left->evaluate(states, caches); + auto role_right_denotations = m_role_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_left_denotations)[i], + *(*role_right_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +DiffRole::DiffRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) + : Role(vocabulary_info, index, (role_left->is_static() && role_right->is_static())), m_role_left(role_left), m_role_right(role_right) { } + +bool DiffRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_left == other_derived.m_role_left + && m_role_right == other_derived.m_role_right; + } + return false; +} + +size_t DiffRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); +} + +RoleDenotation DiffRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role_left->evaluate(state), + m_role_right->evaluate(state), + denotation); + return denotation; +} + +int DiffRole::compute_complexity() const { + return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; +} + +void DiffRole::compute_repr(std::stringstream& out) const { + out << "r_diff" << "("; + m_role_left->compute_repr(out); + out << ","; + m_role_right->compute_repr(out); + out << ")"; +} + +int DiffRole::compute_evaluate_time_score() const { + return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::DiffRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/diff.h b/src/core/elements/roles/diff.h deleted file mode 100644 index 1b471731..00000000 --- a/src/core/elements/roles/diff.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_DIFF_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_DIFF_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - - -namespace dlplan::core { -class DiffRole : public Role { -private: - const std::shared_ptr m_role_left; - const std::shared_ptr m_role_right; - - void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { - result = left_denot; - result -= right_denot; - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role_left->evaluate(state, caches), - *m_role_right->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_left_denotations = m_role_left->evaluate(states, caches); - auto role_right_denotations = m_role_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_left_denotations)[i], - *(*role_right_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - DiffRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_left, std::shared_ptr role_right) - : Role(vocabulary_info, index, (role_left->is_static() && role_right->is_static())), m_role_left(role_left), m_role_right(role_right) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_left == other_derived.m_role_left - && m_role_right == other_derived.m_role_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role_left->evaluate(state), - m_role_right->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_diff" << "("; - m_role_left->compute_repr(out); - out << ","; - m_role_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::DiffRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/identity.cpp b/src/core/elements/roles/identity.cpp index 6f5a7abc..86680d87 100644 --- a/src/core/elements/roles/identity.cpp +++ b/src/core/elements/roles/identity.cpp @@ -1,2 +1,84 @@ -#include "identity.h" +#include "../../../../include/dlplan/core/elements/roles/identity.h" + +namespace dlplan::core { +void IdentityRole::compute_result(const ConceptDenotation& denot, RoleDenotation& result) const { + for (const auto& single : denot.to_vector()) { + result.insert(std::make_pair(single, single)); + } +} + +RoleDenotation IdentityRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_concept->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations IdentityRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto concept_denotations = m_concept->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*concept_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +IdentityRole::IdentityRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept) + : Role(vocabulary_info, index, concept->is_static()), m_concept(concept) { } + +bool IdentityRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_concept == other_derived.m_concept; + } + return false; +} + +size_t IdentityRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_concept); +} + +RoleDenotation IdentityRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_concept->evaluate(state), + denotation); + return denotation; +} + +int IdentityRole::compute_complexity() const { + return m_concept->compute_complexity() + 1; +} + +void IdentityRole::compute_repr(std::stringstream& out) const { + out << "r_identity" << "("; + m_concept->compute_repr(out); + out << ")"; +} + +int IdentityRole::compute_evaluate_time_score() const { + return m_concept->compute_evaluate_time_score() + SCORE_LINEAR; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::IdentityRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/identity.h b/src/core/elements/roles/identity.h deleted file mode 100644 index 7a2bab58..00000000 --- a/src/core/elements/roles/identity.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_IDENTITY_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_IDENTITY_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { - -class IdentityRole : public Role { -private: - const std::shared_ptr m_concept; - - void compute_result(const ConceptDenotation& denot, RoleDenotation& result) const { - for (const auto& single : denot.to_vector()) { - result.insert(std::make_pair(single, single)); - } - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_concept->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto concept_denotations = m_concept->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*concept_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - IdentityRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr concept) - : Role(vocabulary_info, index, concept->is_static()), m_concept(concept) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_concept == other_derived.m_concept; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_concept); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_concept->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_concept->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_identity" << "("; - m_concept->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_concept->compute_evaluate_time_score() + SCORE_LINEAR; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::IdentityRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/inverse.cpp b/src/core/elements/roles/inverse.cpp index 298bfea9..0f6dfc45 100644 --- a/src/core/elements/roles/inverse.cpp +++ b/src/core/elements/roles/inverse.cpp @@ -1 +1,84 @@ -#include "inverse.h" +#include "../../../../include/dlplan/core/elements/roles/inverse.h" + + +namespace dlplan::core { +void InverseRole::compute_result(const RoleDenotation& denot, RoleDenotation& result) const { + for (const auto& pair : denot.to_vector()) { + result.insert(std::make_pair(pair.second, pair.first)); + } +} + +RoleDenotation InverseRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations InverseRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +InverseRole::InverseRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) + : Role(vocabulary_info, index, role->is_static()), m_role(role) { } + +bool InverseRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role; + } + return false; +} + +size_t InverseRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role); +} + +RoleDenotation InverseRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + denotation); + return denotation; +} + +int InverseRole::compute_complexity() const { + return m_role->compute_complexity() + 1; +} + +void InverseRole::compute_repr(std::stringstream& out) const { + out << "r_inverse" << "("; + m_role->compute_repr(out); + out << ")"; +} + +int InverseRole::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::InverseRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/inverse.h b/src/core/elements/roles/inverse.h deleted file mode 100644 index 152eaf30..00000000 --- a/src/core/elements/roles/inverse.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_INVERSE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_INVERSE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class InverseRole : public Role { -private: - const std::shared_ptr m_role; - - void compute_result(const RoleDenotation& denot, RoleDenotation& result) const { - for (const auto& pair : denot.to_vector()) { - result.insert(std::make_pair(pair.second, pair.first)); - } - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - InverseRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) - : Role(vocabulary_info, index, role->is_static()), m_role(role) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_inverse" << "("; - m_role->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::InverseRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/not.cpp b/src/core/elements/roles/not.cpp index 77795366..b24acd3f 100644 --- a/src/core/elements/roles/not.cpp +++ b/src/core/elements/roles/not.cpp @@ -1 +1,83 @@ -#include "not.h" +#include "../../../../include/dlplan/core/elements/roles/not.h" + + +namespace dlplan::core { +void NotRole::compute_result(const RoleDenotation& denot, RoleDenotation& result) const { + result = denot; + ~result; +} + +RoleDenotation NotRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations NotRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +NotRole::NotRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) + : Role(vocabulary_info, index, role->is_static()), m_role(role) { } + +bool NotRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role; + } + return false; +} + +size_t NotRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role); +} + +RoleDenotation NotRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + denotation); + return denotation; +} + +int NotRole::compute_complexity() const { + return m_role->compute_complexity() + 1; +} + +void NotRole::compute_repr(std::stringstream& out) const { + out << "r_not" << "("; + m_role->compute_repr(out); + out << ")"; +} + +int NotRole::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::NotRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/not.h b/src/core/elements/roles/not.h deleted file mode 100644 index 8b3e24da..00000000 --- a/src/core/elements/roles/not.h +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_NOT_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_NOT_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class NotRole : public Role { -private: - const std::shared_ptr m_role; - - void compute_result(const RoleDenotation& denot, RoleDenotation& result) const { - result = denot; - ~result; - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - NotRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) - : Role(vocabulary_info, index, role->is_static()), m_role(role) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_not" << "("; - m_role->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::NotRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/or.cpp b/src/core/elements/roles/or.cpp index 6205c39e..92b27c1f 100644 --- a/src/core/elements/roles/or.cpp +++ b/src/core/elements/roles/or.cpp @@ -1 +1,92 @@ -#include "or.h" +#include "../../../../include/dlplan/core/elements/roles/or.h" + + +namespace dlplan::core { +void OrRole::compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { + result = left_denot; + result |= right_denot; +} + +RoleDenotation OrRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role_left->evaluate(state, caches), + *m_role_right->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations OrRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_left_denotations = m_role_left->evaluate(states, caches); + auto role_right_denotations = m_role_right->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_left_denotations)[i], + *(*role_right_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +OrRole::OrRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_1, std::shared_ptr role_2) + : Role(vocabulary_info, index, role_1->is_static() && role_2->is_static()), + m_role_left(role_1->get_index() < role_2->get_index() ? role_1 : role_2), + m_role_right(role_1->get_index() < role_2->get_index() ? role_2 : role_1) { } + +bool OrRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role_left == other_derived.m_role_left + && m_role_right == other_derived.m_role_right; + } + return false; +} + +size_t OrRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); +} + +RoleDenotation OrRole::evaluate(const State& state) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role_left->evaluate(state), + m_role_right->evaluate(state), + denotation); + return denotation; +} + +int OrRole::compute_complexity() const { + return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; +} + +void OrRole::compute_repr(std::stringstream& out) const { + out << "r_or" << "("; + m_role_left->compute_repr(out); + out << ","; + m_role_right->compute_repr(out); + out << ")"; +} + +int OrRole::compute_evaluate_time_score() const { + return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::OrRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/or.h b/src/core/elements/roles/or.h deleted file mode 100644 index 1897e9ac..00000000 --- a/src/core/elements/roles/or.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_OR_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_OR_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class OrRole : public Role { -private: - const std::shared_ptr m_role_left; - const std::shared_ptr m_role_right; - - void compute_result(const RoleDenotation& left_denot, const RoleDenotation& right_denot, RoleDenotation& result) const { - result = left_denot; - result |= right_denot; - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role_left->evaluate(state, caches), - *m_role_right->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_left_denotations = m_role_left->evaluate(states, caches); - auto role_right_denotations = m_role_right->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_left_denotations)[i], - *(*role_right_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - OrRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role_1, std::shared_ptr role_2) - : Role(vocabulary_info, index, role_1->is_static() && role_2->is_static()), - m_role_left(role_1->get_index() < role_2->get_index() ? role_1 : role_2), - m_role_right(role_1->get_index() < role_2->get_index() ? role_2 : role_1) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role_left == other_derived.m_role_left - && m_role_right == other_derived.m_role_right; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role_left, m_role_right); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role_left->evaluate(state), - m_role_right->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role_left->compute_complexity() + m_role_right->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_or" << "("; - m_role_left->compute_repr(out); - out << ","; - m_role_right->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role_left->compute_evaluate_time_score() + m_role_right->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::OrRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/primitive.cpp b/src/core/elements/roles/primitive.cpp index ca8121b4..4ebe4890 100644 --- a/src/core/elements/roles/primitive.cpp +++ b/src/core/elements/roles/primitive.cpp @@ -1,8 +1,7 @@ -#include "primitive.h" +#include "../../../../include/dlplan/core/elements/roles/primitive.h" -#include "../utils.h" #include "../../../utils/collections.h" -#include "../../../../include/dlplan/core.h" + using namespace std::string_literals; diff --git a/src/core/elements/roles/restrict.cpp b/src/core/elements/roles/restrict.cpp index cd554e31..36d35391 100644 --- a/src/core/elements/roles/restrict.cpp +++ b/src/core/elements/roles/restrict.cpp @@ -1 +1,96 @@ -#include "restrict.h" +#include "../../../../include/dlplan/core/elements/roles/restrict.h" + + +namespace dlplan::core { +void RestrictRole::compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, RoleDenotation& result) const { + result = role_denot; + for (const auto& pair : role_denot.to_vector()) { + if (!concept_denot.contains(pair.second)) { + result.erase(pair); + } + } +} + +RoleDenotation RestrictRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + *m_concept->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations RestrictRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + auto concept_denotations = m_concept->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + *(*concept_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +RestrictRole::RestrictRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept) +: Role(vocabulary_info, index, role->is_static() && concept->is_static()), m_role(role), m_concept(concept) { } + +bool RestrictRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role + && m_concept == other_derived.m_concept; + } + return false; +} + +size_t RestrictRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role, m_concept); +} + +RoleDenotation RestrictRole::evaluate(const State& state) const { + auto role_denot = m_role->evaluate(state); + auto concept_denot = m_concept->evaluate(state); + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + m_concept->evaluate(state), + denotation); + return denotation; +} + +int RestrictRole::compute_complexity() const { + return m_role->compute_complexity() + m_concept->compute_complexity() + 1; +} + +void RestrictRole::compute_repr(std::stringstream& out) const { + out << "r_restrict" << "("; + m_role->compute_repr(out); + out << ","; + m_concept->compute_repr(out); + out << ")"; +} + +int RestrictRole::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + m_concept->compute_evaluate_time_score() + SCORE_QUADRATIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::RestrictRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/restrict.h b/src/core/elements/roles/restrict.h deleted file mode 100644 index c8a7f420..00000000 --- a/src/core/elements/roles/restrict.h +++ /dev/null @@ -1,131 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_RESTRICT_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_RESTRICT_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class RestrictRole : public Role { -private: - const std::shared_ptr m_role; - const std::shared_ptr m_concept; - - void compute_result(const RoleDenotation& role_denot, const ConceptDenotation& concept_denot, RoleDenotation& result) const { - result = role_denot; - for (const auto& pair : role_denot.to_vector()) { - if (!concept_denot.contains(pair.second)) { - result.erase(pair); - } - } - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - *m_concept->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - auto concept_denotations = m_concept->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - *(*concept_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - RestrictRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role, std::shared_ptr concept) - : Role(vocabulary_info, index, role->is_static() && concept->is_static()), m_role(role), m_concept(concept) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role - && m_concept == other_derived.m_concept; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role, m_concept); - } - - RoleDenotation evaluate(const State& state) const override { - auto role_denot = m_role->evaluate(state); - auto concept_denot = m_concept->evaluate(state); - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - m_concept->evaluate(state), - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + m_concept->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_restrict" << "("; - m_role->compute_repr(out); - out << ","; - m_concept->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + m_concept->compute_evaluate_time_score() + SCORE_QUADRATIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::RestrictRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/top.cpp b/src/core/elements/roles/top.cpp index 16ec9e05..827201ff 100644 --- a/src/core/elements/roles/top.cpp +++ b/src/core/elements/roles/top.cpp @@ -1 +1,69 @@ -#include "top.h" +#include "../../../../include/dlplan/core/elements/roles/top.h" + + +namespace dlplan::core { +RoleDenotation TopRole::evaluate_impl(const State& state, DenotationsCaches&) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + denotation.set(); + return denotation; +} + +RoleDenotations TopRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + denotation.set(); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +TopRole::TopRole(ElementIndex index, std::shared_ptr vocabulary_info) + : Role(vocabulary_info, index, true) { } + +bool TopRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static; + } + return false; +} + +size_t TopRole::hash() const { + return dlplan::utils::hash_combine(m_is_static); +} + +RoleDenotation TopRole::evaluate(const State& state) const { + auto denotation = RoleDenotation(state.get_instance_info()->get_objects().size()); + denotation.set(); + return denotation; + +} + +int TopRole::compute_complexity() const { + return 1; +} + +void TopRole::compute_repr(std::stringstream& out) const { + out << "r_top"; +} + +int TopRole::compute_evaluate_time_score() const { + return SCORE_CONSTANT; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::TopRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/top.h b/src/core/elements/roles/top.h deleted file mode 100644 index d272fa45..00000000 --- a/src/core/elements/roles/top.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TOP_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TOP_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class TopRole : public Role { -private: - RoleDenotation evaluate_impl(const State& state, DenotationsCaches&) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - denotation.set(); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - denotation.set(); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - TopRole(ElementIndex index, std::shared_ptr vocabulary_info) - : Role(vocabulary_info, index, true) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static); - } - - RoleDenotation evaluate(const State& state) const override { - auto denotation = RoleDenotation(state.get_instance_info()->get_objects().size()); - denotation.set(); - return denotation; - - } - - int compute_complexity() const override { - return 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_top"; - } - - int compute_evaluate_time_score() const override { - return SCORE_CONSTANT; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::TopRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/transitive_closure.cpp b/src/core/elements/roles/transitive_closure.cpp index 01ce6d06..f562de65 100644 --- a/src/core/elements/roles/transitive_closure.cpp +++ b/src/core/elements/roles/transitive_closure.cpp @@ -1 +1,96 @@ -#include "transitive_closure.h" +#include "../../../../include/dlplan/core/elements/roles/transitive_closure.h" + + +namespace dlplan::core { +// https://stackoverflow.com/questions/3517524/what-is-the-best-known-transitive-closure-algorithm-for-a-directed-graph +void TransitiveClosureRole::compute_result(const RoleDenotation& denot, RoleDenotation& result) const { + result = denot; + bool changed = false; + do { + RoleDenotation tmp_result = result; + PairsOfObjectIndices pairs = tmp_result.to_vector(); + for (const auto& pair_1 : pairs) { + for (const auto& pair_2 : pairs) { + if (pair_1.second == pair_2.first) { + result.insert(std::make_pair(pair_1.first, pair_2.second)); + } + } + } + changed = (result.size() != tmp_result.size()); + } while (changed); +} + +RoleDenotation TransitiveClosureRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + denotation); + return denotation; +} + +RoleDenotations TransitiveClosureRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +TransitiveClosureRole::TransitiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) + : Role(vocabulary_info, index, role->is_static()), m_role(role) { } + +bool TransitiveClosureRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role; + } + return false; +} + +size_t TransitiveClosureRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role); +} + +RoleDenotation TransitiveClosureRole::evaluate(const State& state) const { + RoleDenotation result(state.get_instance_info()->get_objects().size()); + compute_result( + m_role->evaluate(state), + result); + return result; +} + +int TransitiveClosureRole::compute_complexity() const { + return m_role->compute_complexity() + 1; +} + +void TransitiveClosureRole::compute_repr(std::stringstream& out) const { + out << "r_transitive_closure" << "("; + m_role->compute_repr(out); + out << ")"; +} + +int TransitiveClosureRole::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::TransitiveClosureRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/transitive_closure.h b/src/core/elements/roles/transitive_closure.h deleted file mode 100644 index 790603a4..00000000 --- a/src/core/elements/roles/transitive_closure.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_CLOSURE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_CLOSURE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -// https://stackoverflow.com/questions/3517524/what-is-the-best-known-transitive-closure-algorithm-for-a-directed-graph -class TransitiveClosureRole : public Role { -private: - const std::shared_ptr m_role; - - void compute_result(const RoleDenotation& denot, RoleDenotation& result) const { - result = denot; - bool changed = false; - do { - RoleDenotation tmp_result = result; - PairsOfObjectIndices pairs = tmp_result.to_vector(); - for (const auto& pair_1 : pairs) { - for (const auto& pair_2 : pairs) { - if (pair_1.second == pair_2.first) { - result.insert(std::make_pair(pair_1.first, pair_2.second)); - } - } - } - changed = (result.size() != tmp_result.size()); - } while (changed); - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - TransitiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) - : Role(vocabulary_info, index, role->is_static()), m_role(role) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role); - } - - RoleDenotation evaluate(const State& state) const override { - RoleDenotation result(state.get_instance_info()->get_objects().size()); - compute_result( - m_role->evaluate(state), - result); - return result; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_transitive_closure" << "("; - m_role->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::TransitiveClosureRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/roles/transitive_reflexive_closure.cpp b/src/core/elements/roles/transitive_reflexive_closure.cpp index b73db41a..b9e80027 100644 --- a/src/core/elements/roles/transitive_reflexive_closure.cpp +++ b/src/core/elements/roles/transitive_reflexive_closure.cpp @@ -1,2 +1,103 @@ -#include "transitive_reflexive_closure.h" +#include "../../../../include/dlplan/core/elements/roles/transitive_reflexive_closure.h" + +namespace dlplan::core { +void TransitiveReflexiveClosureRole::compute_result(const RoleDenotation& denot, int num_objects, RoleDenotation& result) const { + result = denot; + bool changed = false; + do { + RoleDenotation tmp_result = result; + PairsOfObjectIndices pairs = tmp_result.to_vector(); + for (const auto& pair_1 : pairs) { + for (const auto& pair_2 : pairs) { + if (pair_1.second == pair_2.first) { + result.insert(std::make_pair(pair_1.first, pair_2.second)); + } + } + } + changed = (result.size() != tmp_result.size()); + } while (changed); + // add reflexive part + for (int i = 0; i < num_objects; ++i) { + result.insert(std::make_pair(i, i)); + } +} + +RoleDenotation TransitiveReflexiveClosureRole::evaluate_impl(const State& state, DenotationsCaches& caches) const { + RoleDenotation denotation(state.get_instance_info()->get_objects().size()); + compute_result( + *m_role->evaluate(state, caches), + state.get_instance_info()->get_objects().size(), + denotation); + return denotation; +} + +RoleDenotations TransitiveReflexiveClosureRole::evaluate_impl(const States& states, DenotationsCaches& caches) const { + RoleDenotations denotations; + denotations.reserve(states.size()); + auto role_denotations = m_role->evaluate(states, caches); + for (size_t i = 0; i < states.size(); ++i) { + RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); + compute_result( + *(*role_denotations)[i], + states[i].get_instance_info()->get_objects().size(), + denotation); + denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); + } + return denotations; +} + +TransitiveReflexiveClosureRole::TransitiveReflexiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) + : Role(vocabulary_info, index, role->is_static()), m_role(role) { } + +bool TransitiveReflexiveClosureRole::operator==(const Role& other) const { + if (typeid(*this) == typeid(other)) { + const auto& other_derived = static_cast(other); + return m_is_static == other_derived.m_is_static + && m_role == other_derived.m_role; + } + return false; +} + +size_t TransitiveReflexiveClosureRole::hash() const { + return dlplan::utils::hash_combine(m_is_static, m_role); +} + +RoleDenotation TransitiveReflexiveClosureRole::evaluate(const State& state) const { + int num_objects = state.get_instance_info()->get_objects().size(); + RoleDenotation denotation(num_objects); + compute_result( + m_role->evaluate(state), + num_objects, + denotation); + return denotation; +} + +int TransitiveReflexiveClosureRole::compute_complexity() const { + return m_role->compute_complexity() + 1; +} + +void TransitiveReflexiveClosureRole::compute_repr(std::stringstream& out) const { + out << "r_transitive_reflexive_closure" << "("; + m_role->compute_repr(out); + out << ")"; +} + +int TransitiveReflexiveClosureRole::compute_evaluate_time_score() const { + return m_role->compute_evaluate_time_score() + SCORE_QUBIC; +} + +} + + +namespace std { + bool less>::operator()( + const std::shared_ptr& left_role, + const std::shared_ptr& right_role) const { + return *left_role < *right_role; + } + + std::size_t hash::operator()(const dlplan::core::TransitiveReflexiveClosureRole& role) const { + return role.hash(); + } +} diff --git a/src/core/elements/roles/transitive_reflexive_closure.h b/src/core/elements/roles/transitive_reflexive_closure.h deleted file mode 100644 index bea2f1b4..00000000 --- a/src/core/elements/roles/transitive_reflexive_closure.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ -#define DLPLAN_SRC_CORE_ELEMENTS_ROLES_TRANSITIVE_REFLEXIVE_CLOSURE_H_ - -#include "../utils.h" -#include "../../../../include/dlplan/core.h" - -#include -#include - -using namespace std::string_literals; - - -namespace dlplan::utils { -template -class ReferenceCountedObjectFactory; -} - - -namespace dlplan::core { -class TransitiveReflexiveClosureRole : public Role { -private: - const std::shared_ptr m_role; - - void compute_result(const RoleDenotation& denot, int num_objects, RoleDenotation& result) const { - result = denot; - bool changed = false; - do { - RoleDenotation tmp_result = result; - PairsOfObjectIndices pairs = tmp_result.to_vector(); - for (const auto& pair_1 : pairs) { - for (const auto& pair_2 : pairs) { - if (pair_1.second == pair_2.first) { - result.insert(std::make_pair(pair_1.first, pair_2.second)); - } - } - } - changed = (result.size() != tmp_result.size()); - } while (changed); - // add reflexive part - for (int i = 0; i < num_objects; ++i) { - result.insert(std::make_pair(i, i)); - } - } - - RoleDenotation evaluate_impl(const State& state, DenotationsCaches& caches) const override { - RoleDenotation denotation(state.get_instance_info()->get_objects().size()); - compute_result( - *m_role->evaluate(state, caches), - state.get_instance_info()->get_objects().size(), - denotation); - return denotation; - } - - RoleDenotations evaluate_impl(const States& states, DenotationsCaches& caches) const override { - RoleDenotations denotations; - denotations.reserve(states.size()); - auto role_denotations = m_role->evaluate(states, caches); - for (size_t i = 0; i < states.size(); ++i) { - RoleDenotation denotation(states[i].get_instance_info()->get_objects().size()); - compute_result( - *(*role_denotations)[i], - states[i].get_instance_info()->get_objects().size(), - denotation); - denotations.push_back(caches.role_denotation_cache.insert_denotation(std::move(denotation))); - } - return denotations; - } - - TransitiveReflexiveClosureRole(ElementIndex index, std::shared_ptr vocabulary_info, std::shared_ptr role) - : Role(vocabulary_info, index, role->is_static()), m_role(role) { } - - template - friend class dlplan::utils::ReferenceCountedObjectFactory; - -public: - bool operator==(const Role& other) const override { - if (typeid(*this) == typeid(other)) { - const auto& other_derived = static_cast(other); - return m_is_static == other_derived.m_is_static - && m_role == other_derived.m_role; - } - return false; - } - - size_t hash() const { - return dlplan::utils::hash_combine(m_is_static, m_role); - } - - RoleDenotation evaluate(const State& state) const override { - int num_objects = state.get_instance_info()->get_objects().size(); - RoleDenotation denotation(num_objects); - compute_result( - m_role->evaluate(state), - num_objects, - denotation); - return denotation; - } - - int compute_complexity() const override { - return m_role->compute_complexity() + 1; - } - - void compute_repr(std::stringstream& out) const override { - out << "r_transitive_reflexive_closure" << "("; - m_role->compute_repr(out); - out << ")"; - } - - int compute_evaluate_time_score() const override { - return m_role->compute_evaluate_time_score() + SCORE_QUBIC; - } -}; - -} - - -namespace std { - template<> - struct less> - { - bool operator()( - const std::shared_ptr& left_role, - const std::shared_ptr& right_role) const { - return *left_role < *right_role; - } - }; - - template<> - struct hash - { - std::size_t operator()(const dlplan::core::TransitiveReflexiveClosureRole& role) const { - return role.hash(); - } - }; -} - -#endif diff --git a/src/core/elements/utils.cpp b/src/core/elements/utils.cpp index b51d623b..a6f7bd11 100644 --- a/src/core/elements/utils.cpp +++ b/src/core/elements/utils.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "../../../include/dlplan/core/elements/utils.h" #include #include diff --git a/src/generator/rules/concepts/equal.cpp b/src/generator/rules/concepts/equal.cpp index 812d986d..dc70b9dd 100644 --- a/src/generator/rules/concepts/equal.cpp +++ b/src/generator/rules/concepts/equal.cpp @@ -2,7 +2,7 @@ #include "../../generator_data.h" -#include "../../../core/elements/roles/primitive.h" +#include "../../../../include/dlplan/core/elements/roles/primitive.h" namespace dlplan::generator::rules { diff --git a/src/policy/condition.cpp b/src/policy/condition.cpp index bebbbd53..6c2f2be4 100644 --- a/src/policy/condition.cpp +++ b/src/policy/condition.cpp @@ -1,6 +1,6 @@ -#include "condition.h" +#include "../../include/dlplan/policy/condition.h" -#include "../core/elements/utils.h" +#include "../../include/dlplan/core/elements/utils.h" #include "../../include/dlplan/core.h" #include "../../include/dlplan/utils/hash.h" diff --git a/src/policy/effect.cpp b/src/policy/effect.cpp index d2cd1316..6d3c6e47 100644 --- a/src/policy/effect.cpp +++ b/src/policy/effect.cpp @@ -1,6 +1,6 @@ -#include "effect.h" +#include "../../include/dlplan/policy/effect.h" -#include "../core/elements/utils.h" +#include "../../include/dlplan/core/elements/utils.h" #include "../../include/dlplan/core.h" #include "../../include/dlplan/utils/hash.h" diff --git a/src/policy/policy.cpp b/src/policy/policy.cpp index 57eee622..b8326889 100644 --- a/src/policy/policy.cpp +++ b/src/policy/policy.cpp @@ -1,7 +1,5 @@ #include "../../include/dlplan/policy.h" -#include "condition.h" -#include "effect.h" #include "policy_factory.h" #include diff --git a/src/policy/policy_factory.h b/src/policy/policy_factory.h index 1c36eefe..1d06c8ef 100644 --- a/src/policy/policy_factory.h +++ b/src/policy/policy_factory.h @@ -1,13 +1,12 @@ #ifndef DLPLAN_SRC_POLICY_POLICY_BUILDER_H_ #define DLPLAN_SRC_POLICY_POLICY_BUILDER_H_ -#include "condition.h" -#include "effect.h" - #include "../utils/factory.h" #include "../../include/dlplan/core.h" #include "../../include/dlplan/policy.h" +#include "../../include/dlplan/policy/condition.h" +#include "../../include/dlplan/policy/effect.h" #include diff --git a/src/policy/policy_impl.cpp b/src/policy/policy_impl.cpp index 1ca6bcad..51ceeefc 100644 --- a/src/policy/policy_impl.cpp +++ b/src/policy/policy_impl.cpp @@ -1,8 +1,5 @@ #include "../../include/dlplan/policy.h" -#include "condition.h" -#include "effect.h" - #include "../../include/dlplan/core.h" #include "../../include/dlplan/utils/hash.h" diff --git a/src/policy/policy_minimizer.cpp b/src/policy/policy_minimizer.cpp index 09a08bcf..39f2af61 100644 --- a/src/policy/policy_minimizer.cpp +++ b/src/policy/policy_minimizer.cpp @@ -1,7 +1,7 @@ #include "../../include/dlplan/policy.h" -#include "condition.h" -#include "effect.h" +#include "../../include/dlplan/policy/condition.h" +#include "../../include/dlplan/policy/effect.h" #include "../../include/dlplan/utils/hash.h" #include diff --git a/src/policy/rule.cpp b/src/policy/rule.cpp index 28dc86a7..61b1088f 100644 --- a/src/policy/rule.cpp +++ b/src/policy/rule.cpp @@ -1,8 +1,5 @@ #include "../../include/dlplan/policy.h" -#include "condition.h" -#include "effect.h" - #include "../../include/dlplan/utils/hash.h" #include