From d3a2a24170e2a42cd75fba63be30292721a12fb4 Mon Sep 17 00:00:00 2001 From: Dominik Drexler Date: Mon, 25 Nov 2024 17:50:09 +0100 Subject: [PATCH] variant types are not handled consistently. removed HolderType from SegmentedRepository since variants are handled differently now. --- include/loki/details/pddl/declarations.hpp | 9 +- include/loki/details/pddl/effects.hpp | 24 +++ .../details/pddl/function_expressions.hpp | 39 ++++ include/loki/details/pddl/repositories.hpp | 143 +++++++------ .../details/utils/segmented_repository.hpp | 23 +- src/pddl/effects.cpp | 20 +- src/pddl/equal_to.cpp | 4 +- src/pddl/formatter.cpp | 4 +- src/pddl/function_expressions.cpp | 21 ++ src/pddl/hash.cpp | 7 +- src/pddl/repositories.cpp | 200 +++++++++--------- tests/unit/pddl/reference.cpp | 4 +- tests/unit/utils/segmented_repository.cpp | 22 +- 13 files changed, 317 insertions(+), 203 deletions(-) diff --git a/include/loki/details/pddl/declarations.hpp b/include/loki/details/pddl/declarations.hpp index f838d790..9c8a078b 100644 --- a/include/loki/details/pddl/declarations.hpp +++ b/include/loki/details/pddl/declarations.hpp @@ -113,8 +113,7 @@ class EffectCompositeWhenImpl; using EffectCompositeWhen = const EffectCompositeWhenImpl*; class EffectCompositeOneofImpl; using EffectCompositeOneof = const EffectCompositeOneofImpl*; -using EffectImpl = - std::variant; +class EffectImpl; using Effect = const EffectImpl*; using EffectList = std::vector; @@ -128,11 +127,7 @@ class FunctionExpressionMinusImpl; using FunctionExpressionMinus = const FunctionExpressionMinusImpl*; class FunctionExpressionFunctionImpl; using FunctionExpressionFunction = const FunctionExpressionFunctionImpl*; -using FunctionExpressionImpl = std::variant; +class FunctionExpressionImpl; using FunctionExpression = const FunctionExpressionImpl*; using FunctionExpressionList = std::vector; diff --git a/include/loki/details/pddl/effects.hpp b/include/loki/details/pddl/effects.hpp index 8119374e..aa83b4c0 100644 --- a/include/loki/details/pddl/effects.hpp +++ b/include/loki/details/pddl/effects.hpp @@ -187,6 +187,30 @@ class EffectCompositeOneofImpl const EffectList& get_effects() const; }; +/* EffectImpl */ +class EffectImpl +{ +private: + size_t m_index; + std::variant m_effect; + + EffectImpl(size_t index, std::variant effect); + + // Give access to the constructor. + template + friend class SegmentedRepository; + +public: + // moveable but not copyable + EffectImpl(const EffectImpl& other) = delete; + EffectImpl& operator=(const EffectImpl& other) = delete; + EffectImpl(EffectImpl&& other) = default; + EffectImpl& operator=(EffectImpl&& other) = default; + + size_t get_index() const; + const std::variant& get_effect() const; +}; + extern std::ostream& operator<<(std::ostream& out, const EffectLiteralImpl& element); extern std::ostream& operator<<(std::ostream& out, const EffectAndImpl& element); extern std::ostream& operator<<(std::ostream& out, const EffectNumericImpl& element); diff --git a/include/loki/details/pddl/function_expressions.hpp b/include/loki/details/pddl/function_expressions.hpp index 3b7eeece..2c7444fb 100644 --- a/include/loki/details/pddl/function_expressions.hpp +++ b/include/loki/details/pddl/function_expressions.hpp @@ -174,6 +174,45 @@ class FunctionExpressionFunctionImpl const Function& get_function() const; }; +/* FunctionExpression */ +class FunctionExpressionImpl +{ +private: + size_t m_index; + std::variant + m_function_expression; + + FunctionExpressionImpl(size_t index, + std::variant function_expression); + + // Give access to the constructor. + template + friend class SegmentedRepository; + +public: + // moveable but not copyable + FunctionExpressionImpl(const FunctionExpressionImpl& other) = delete; + FunctionExpressionImpl& operator=(const FunctionExpressionImpl& other) = delete; + FunctionExpressionImpl(FunctionExpressionImpl&& other) = default; + FunctionExpressionImpl& operator=(FunctionExpressionImpl&& other) = default; + + size_t get_index() const; + const std::variant& + get_function_expression() const; +}; + extern std::ostream& operator<<(std::ostream& out, const FunctionExpressionNumberImpl& element); extern std::ostream& operator<<(std::ostream& out, const FunctionExpressionBinaryOperatorImpl& element); extern std::ostream& operator<<(std::ostream& out, const FunctionExpressionMultiOperatorImpl& element); diff --git a/include/loki/details/pddl/repositories.hpp b/include/loki/details/pddl/repositories.hpp index 9b354bb3..8bc35f0a 100644 --- a/include/loki/details/pddl/repositories.hpp +++ b/include/loki/details/pddl/repositories.hpp @@ -49,68 +49,87 @@ namespace loki { -using RequirementsRepository = SegmentedRepository, UniquePDDLEqualTo>; -using TypeRepository = SegmentedRepository, UniquePDDLEqualTo>; -using VariableRepository = SegmentedRepository, UniquePDDLEqualTo>; -using TermRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ObjectRepository = SegmentedRepository, UniquePDDLEqualTo>; -using AtomRepository = SegmentedRepository, UniquePDDLEqualTo>; -using LiteralRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ParameterRepository = SegmentedRepository, UniquePDDLEqualTo>; -using PredicateRepository = SegmentedRepository, UniquePDDLEqualTo>; -using FunctionExpressionRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using FunctionRepository = SegmentedRepository, UniquePDDLEqualTo>; -using FunctionSkeletonRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using ConditionLiteralRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using ConditionAndRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ConditionOrRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ConditionNotRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ConditionImplyRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using ConditionExistsRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using ConditionForallRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using ConditionRepository = SegmentedRepository, UniquePDDLEqualTo>; -using EffectRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ActionRepository = SegmentedRepository, UniquePDDLEqualTo>; -using AxiomRepository = SegmentedRepository, UniquePDDLEqualTo>; -using OptimizationMetricRepository = - SegmentedRepository, UniquePDDLEqualTo>; -using NumericFluentRepository = SegmentedRepository, UniquePDDLEqualTo>; -using DomainRepository = SegmentedRepository, UniquePDDLEqualTo>; -using ProblemRepository = SegmentedRepository, UniquePDDLEqualTo>; - -using PDDLTypeToRepository = boost::hana::map, RequirementsRepository>, - boost::hana::pair, TypeRepository>, - boost::hana::pair, VariableRepository>, - boost::hana::pair, TermRepository>, - boost::hana::pair, ObjectRepository>, - boost::hana::pair, AtomRepository>, - boost::hana::pair, LiteralRepository>, - boost::hana::pair, ParameterRepository>, - boost::hana::pair, PredicateRepository>, - boost::hana::pair, FunctionExpressionRepository>, - boost::hana::pair, FunctionRepository>, - boost::hana::pair, FunctionSkeletonRepository>, - boost::hana::pair, ConditionLiteralRepository>, - boost::hana::pair, ConditionAndRepository>, - boost::hana::pair, ConditionOrRepository>, - boost::hana::pair, ConditionNotRepository>, - boost::hana::pair, ConditionImplyRepository>, - boost::hana::pair, ConditionExistsRepository>, - boost::hana::pair, ConditionForallRepository>, - boost::hana::pair, ConditionRepository>, - boost::hana::pair, EffectRepository>, - boost::hana::pair, ActionRepository>, - boost::hana::pair, AxiomRepository>, - boost::hana::pair, OptimizationMetricRepository>, - boost::hana::pair, NumericFluentRepository>, - boost::hana::pair, DomainRepository>, - boost::hana::pair, ProblemRepository>>; +template +using SegmentedPDDLRepository = SegmentedRepository, UniquePDDLEqualTo>; + +using RequirementsRepository = SegmentedPDDLRepository; +using TypeRepository = SegmentedPDDLRepository; +using VariableRepository = SegmentedPDDLRepository; +using TermRepository = SegmentedPDDLRepository; +using ObjectRepository = SegmentedPDDLRepository; +using AtomRepository = SegmentedPDDLRepository; +using LiteralRepository = SegmentedPDDLRepository; +using ParameterRepository = SegmentedPDDLRepository; +using PredicateRepository = SegmentedPDDLRepository; +using FunctionExpressionNumberRepository = SegmentedPDDLRepository; +using FunctionExpressionBinaryOperatorRepository = SegmentedPDDLRepository; +using FunctionExpressionMultiOperatorRepository = SegmentedPDDLRepository; +using FunctionExpressionMinusRepository = SegmentedPDDLRepository; +using FunctionExpressionFunctionRepository = SegmentedPDDLRepository; +using FunctionExpressionRepository = SegmentedPDDLRepository; +using FunctionRepository = SegmentedPDDLRepository; +using FunctionSkeletonRepository = SegmentedPDDLRepository; +using ConditionLiteralRepository = SegmentedPDDLRepository; +using ConditionAndRepository = SegmentedPDDLRepository; +using ConditionOrRepository = SegmentedPDDLRepository; +using ConditionNotRepository = SegmentedPDDLRepository; +using ConditionImplyRepository = SegmentedPDDLRepository; +using ConditionExistsRepository = SegmentedPDDLRepository; +using ConditionForallRepository = SegmentedPDDLRepository; +using ConditionRepository = SegmentedPDDLRepository; +using EffectLiteralRepository = SegmentedPDDLRepository; +using EffectAndRepository = SegmentedPDDLRepository; +using EffectNumericRepository = SegmentedPDDLRepository; +using EffectCompositeForallRepository = SegmentedPDDLRepository; +using EffectCompositeWhenRepository = SegmentedPDDLRepository; +using EffectCompositeOneofRepository = SegmentedPDDLRepository; +using EffectRepository = SegmentedPDDLRepository; +using ActionRepository = SegmentedPDDLRepository; +using AxiomRepository = SegmentedPDDLRepository; +using OptimizationMetricRepository = SegmentedPDDLRepository; +using NumericFluentRepository = SegmentedPDDLRepository; +using DomainRepository = SegmentedPDDLRepository; +using ProblemRepository = SegmentedPDDLRepository; + +using PDDLTypeToRepository = + boost::hana::map, RequirementsRepository>, + boost::hana::pair, TypeRepository>, + boost::hana::pair, VariableRepository>, + boost::hana::pair, TermRepository>, + boost::hana::pair, ObjectRepository>, + boost::hana::pair, AtomRepository>, + boost::hana::pair, LiteralRepository>, + boost::hana::pair, ParameterRepository>, + boost::hana::pair, PredicateRepository>, + boost::hana::pair, FunctionExpressionNumberRepository>, + boost::hana::pair, FunctionExpressionBinaryOperatorRepository>, + boost::hana::pair, FunctionExpressionMultiOperatorRepository>, + boost::hana::pair, FunctionExpressionMinusRepository>, + boost::hana::pair, FunctionExpressionFunctionRepository>, + boost::hana::pair, FunctionExpressionRepository>, + boost::hana::pair, FunctionRepository>, + boost::hana::pair, FunctionSkeletonRepository>, + boost::hana::pair, ConditionLiteralRepository>, + boost::hana::pair, ConditionAndRepository>, + boost::hana::pair, ConditionOrRepository>, + boost::hana::pair, ConditionNotRepository>, + boost::hana::pair, ConditionImplyRepository>, + boost::hana::pair, ConditionExistsRepository>, + boost::hana::pair, ConditionForallRepository>, + boost::hana::pair, ConditionRepository>, + boost::hana::pair, EffectLiteralRepository>, + boost::hana::pair, EffectAndRepository>, + boost::hana::pair, EffectNumericRepository>, + boost::hana::pair, EffectCompositeForallRepository>, + boost::hana::pair, EffectCompositeWhenRepository>, + boost::hana::pair, EffectCompositeOneofRepository>, + boost::hana::pair, EffectRepository>, + boost::hana::pair, ActionRepository>, + boost::hana::pair, AxiomRepository>, + boost::hana::pair, OptimizationMetricRepository>, + boost::hana::pair, NumericFluentRepository>, + boost::hana::pair, DomainRepository>, + boost::hana::pair, ProblemRepository>>; extern PDDLTypeToRepository create_default_pddl_type_to_repository(); diff --git a/include/loki/details/utils/segmented_repository.hpp b/include/loki/details/utils/segmented_repository.hpp index 8aa2eefe..b4baea31 100644 --- a/include/loki/details/utils/segmented_repository.hpp +++ b/include/loki/details/utils/segmented_repository.hpp @@ -32,19 +32,18 @@ namespace loki /// @brief `UniqueFactory` manages unique creation of objects /// in a persistent and efficient manner, utilizing a combination of unordered_set for /// uniqueness checks and SegmentedVector for continuous and cache-efficient storage of value types. -/// @tparam HolderType is the holder value type which can be an std::variant. -/// Note that using a base class value type will result in object slicing. +/// @tparam T is the type. /// @tparam Hash the hash function. /// @tparam KeyEqual the comparison function. -template +template class SegmentedRepository { private: // We use an unordered_set to test for uniqueness. - std::unordered_set m_uniqueness_set; + std::unordered_set m_uniqueness_set; // We use pre-allocated memory to store objects persistent. - SegmentedVector m_persistent_vector; + SegmentedVector m_persistent_vector; void range_check(size_t pos) const { @@ -57,7 +56,7 @@ class SegmentedRepository public: SegmentedRepository(size_t initial_num_element_per_segment = 16, size_t maximum_num_elements_per_segment = 16 * 1024) : - m_persistent_vector(SegmentedVector(initial_num_element_per_segment, maximum_num_elements_per_segment)) + m_persistent_vector(SegmentedVector(initial_num_element_per_segment, maximum_num_elements_per_segment)) { } SegmentedRepository(const SegmentedRepository& other) = delete; @@ -66,8 +65,8 @@ class SegmentedRepository SegmentedRepository& operator=(SegmentedRepository&& other) = default; /// @brief Returns a pointer to an existing object or creates it before if it does not exist. - template - HolderType const* get_or_create(Args&&... args) + template + T const* get_or_create(Args&&... args) { /* Construct and insert the element in persistent memory. */ @@ -76,7 +75,7 @@ class SegmentedRepository assert(index == m_persistent_vector.size()); // Explicitly call the constructor of T to give exclusive access to the factory. - const auto* element_ptr = &m_persistent_vector.emplace_back(SubType(index, std::forward(args)...)); + const auto* element_ptr = &m_persistent_vector.emplace_back(T(index, std::forward(args)...)); // The pointer to the location in persistent memory. assert(element_ptr); @@ -105,13 +104,13 @@ class SegmentedRepository */ /// @brief Returns a pointer to an existing object with the given pos. - HolderType const* operator[](size_t pos) const + T const* operator[](size_t pos) const { assert(pos < size()); return &(m_persistent_vector.at(pos)); } - HolderType const* at(size_t pos) const + T const* at(size_t pos) const { range_check(pos); return &(m_persistent_vector.at(pos)); @@ -121,7 +120,7 @@ class SegmentedRepository auto end() const { return m_persistent_vector.end(); } - const SegmentedVector& get_storage() const { return m_persistent_vector; } + const SegmentedVector& get_storage() const { return m_persistent_vector; } /** * Capacity diff --git a/src/pddl/effects.cpp b/src/pddl/effects.cpp index d10ac9aa..1c795c6b 100644 --- a/src/pddl/effects.cpp +++ b/src/pddl/effects.cpp @@ -100,16 +100,26 @@ const Condition& EffectCompositeWhenImpl::get_condition() const { return m_condi const Effect& EffectCompositeWhenImpl::get_effect() const { return m_effect; } /* EffectCompositeOneofImpl */ -EffectCompositeOneofImpl::EffectCompositeOneofImpl(size_t index, EffectList effects) : - m_index(index), - m_effects(std::move(effects)) -{ -} +EffectCompositeOneofImpl::EffectCompositeOneofImpl(size_t index, EffectList effects) : m_index(index), m_effects(std::move(effects)) {} size_t EffectCompositeOneofImpl::get_index() const { return m_index; } const EffectList& EffectCompositeOneofImpl::get_effects() const { return m_effects; } +/* EffectImpl */ +EffectImpl::EffectImpl(size_t index, + std::variant effect) : + m_index(index), + m_effect(std::move(effect)) +{ +} + +size_t EffectImpl::get_index() const { return m_index; } + +const std::variant& EffectImpl::get_effect() const +{ + return m_effect; +} std::ostream& operator<<(std::ostream& out, const EffectLiteralImpl& element) { diff --git a/src/pddl/equal_to.cpp b/src/pddl/equal_to.cpp index 3c0ec90d..36cf8601 100644 --- a/src/pddl/equal_to.cpp +++ b/src/pddl/equal_to.cpp @@ -210,7 +210,7 @@ bool UniquePDDLEqualTo::operator()(const Effect return true; } -bool UniquePDDLEqualTo::operator()(const EffectImpl* l, const EffectImpl* r) const { return UniquePDDLEqualTo()(*l, *r); } +bool UniquePDDLEqualTo::operator()(const EffectImpl* l, const EffectImpl* r) const { return l->get_effect() == r->get_effect(); } bool UniquePDDLEqualTo::operator()(const FunctionExpressionNumberImpl& l, const FunctionExpressionNumberImpl& r) const { @@ -264,7 +264,7 @@ bool UniquePDDLEqualTo::operator()(const bool UniquePDDLEqualTo::operator()(const FunctionExpressionImpl* l, const FunctionExpressionImpl* r) const { - return UniquePDDLEqualTo()(*l, *r); + return l->get_function_expression() == r->get_function_expression(); } bool UniquePDDLEqualTo::operator()(const FunctionSkeletonImpl* l, const FunctionSkeletonImpl* r) const diff --git a/src/pddl/formatter.cpp b/src/pddl/formatter.cpp index 886361c5..b4b0552d 100644 --- a/src/pddl/formatter.cpp +++ b/src/pddl/formatter.cpp @@ -352,7 +352,7 @@ void PDDLFormatter::write(const EffectCompositeOneofImpl& element, std::ostream& void PDDLFormatter::write(const EffectImpl& element, std::ostream& out) { - std::visit([this, &out](const auto& arg) { this->write(arg, out); }, element); + std::visit([this, &out](const auto& arg) { this->write(*arg, out); }, element.get_effect()); } void PDDLFormatter::write(const FunctionExpressionNumberImpl& element, std::ostream& out) { out << element.get_number(); } @@ -389,7 +389,7 @@ void PDDLFormatter::write(const FunctionExpressionFunctionImpl& element, std::os void PDDLFormatter::write(const FunctionExpressionImpl& element, std::ostream& out) { - std::visit([this, &out](const auto& arg) { this->write(arg, out); }, element); + std::visit([this, &out](const auto& arg) { this->write(*arg, out); }, element.get_function_expression()); } void PDDLFormatter::write(const FunctionSkeletonImpl& element, std::ostream& out) diff --git a/src/pddl/function_expressions.cpp b/src/pddl/function_expressions.cpp index 62eab3e4..49f753b8 100644 --- a/src/pddl/function_expressions.cpp +++ b/src/pddl/function_expressions.cpp @@ -110,6 +110,27 @@ size_t FunctionExpressionFunctionImpl::get_index() const { return m_index; } const Function& FunctionExpressionFunctionImpl::get_function() const { return m_function; } +/* FunctionExpression */ +FunctionExpressionImpl::FunctionExpressionImpl(size_t index, + std::variant function_expression) : + m_index(index), + m_function_expression(function_expression) +{ +} + +size_t FunctionExpressionImpl::get_index() const { return m_index; } + +const std:: + variant& + FunctionExpressionImpl::get_function_expression() const +{ + return m_function_expression; +} + std::ostream& operator<<(std::ostream& out, const FunctionExpressionNumberImpl& element) { auto formatter = PDDLFormatter(); diff --git a/src/pddl/hash.cpp b/src/pddl/hash.cpp index a2d6d4dd..0768176f 100644 --- a/src/pddl/hash.cpp +++ b/src/pddl/hash.cpp @@ -122,10 +122,7 @@ size_t UniquePDDLHasher::operator()(const Effec return UniquePDDLHashCombiner()(get_sorted_vector(e.get_effects())); } -size_t UniquePDDLHasher::operator()(const EffectImpl* e) const -{ - return std::visit([](const auto& arg) { return UniquePDDLHasher()(arg); }, *e); -} +size_t UniquePDDLHasher::operator()(const EffectImpl* e) const { return UniquePDDLHashCombiner()(e->get_effect()); } size_t UniquePDDLHasher::operator()(const FunctionExpressionNumberImpl& e) const { @@ -154,7 +151,7 @@ size_t UniquePDDLHasher::operator()(const size_t UniquePDDLHasher::operator()(const FunctionExpressionImpl* e) const { - return std::visit([](const auto& arg) { return UniquePDDLHasher()(arg); }, *e); + return UniquePDDLHashCombiner()(e->get_function_expression()); } size_t UniquePDDLHasher::operator()(const FunctionSkeletonImpl* e) const diff --git a/src/pddl/repositories.cpp b/src/pddl/repositories.cpp index 9a0fd093..2dfac85d 100644 --- a/src/pddl/repositories.cpp +++ b/src/pddl/repositories.cpp @@ -22,33 +22,45 @@ namespace loki PDDLTypeToRepository create_default_pddl_type_to_repository() { - return boost::hana::make_map(boost::hana::make_pair(boost::hana::type_c, RequirementsRepository {}), - boost::hana::make_pair(boost::hana::type_c, TypeRepository {}), - boost::hana::make_pair(boost::hana::type_c, VariableRepository {}), - boost::hana::make_pair(boost::hana::type_c, TermRepository {}), - boost::hana::make_pair(boost::hana::type_c, ObjectRepository {}), - boost::hana::make_pair(boost::hana::type_c, AtomRepository {}), - boost::hana::make_pair(boost::hana::type_c, LiteralRepository {}), - boost::hana::make_pair(boost::hana::type_c, ParameterRepository {}), - boost::hana::make_pair(boost::hana::type_c, PredicateRepository {}), - boost::hana::make_pair(boost::hana::type_c, FunctionExpressionRepository {}), - boost::hana::make_pair(boost::hana::type_c, FunctionRepository {}), - boost::hana::make_pair(boost::hana::type_c, FunctionSkeletonRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionLiteralRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionAndRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionOrRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionNotRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionImplyRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionExistsRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionForallRepository {}), - boost::hana::make_pair(boost::hana::type_c, ConditionRepository {}), - boost::hana::make_pair(boost::hana::type_c, EffectRepository {}), - boost::hana::make_pair(boost::hana::type_c, ActionRepository {}), - boost::hana::make_pair(boost::hana::type_c, AxiomRepository {}), - boost::hana::make_pair(boost::hana::type_c, OptimizationMetricRepository {}), - boost::hana::make_pair(boost::hana::type_c, NumericFluentRepository {}), - boost::hana::make_pair(boost::hana::type_c, DomainRepository {}), - boost::hana::make_pair(boost::hana::type_c, ProblemRepository {})); + return boost::hana::make_map( + boost::hana::make_pair(boost::hana::type_c, RequirementsRepository {}), + boost::hana::make_pair(boost::hana::type_c, TypeRepository {}), + boost::hana::make_pair(boost::hana::type_c, VariableRepository {}), + boost::hana::make_pair(boost::hana::type_c, TermRepository {}), + boost::hana::make_pair(boost::hana::type_c, ObjectRepository {}), + boost::hana::make_pair(boost::hana::type_c, AtomRepository {}), + boost::hana::make_pair(boost::hana::type_c, LiteralRepository {}), + boost::hana::make_pair(boost::hana::type_c, ParameterRepository {}), + boost::hana::make_pair(boost::hana::type_c, PredicateRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionNumberRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionBinaryOperatorRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionMultiOperatorRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionMinusRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionFunctionRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionExpressionRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionRepository {}), + boost::hana::make_pair(boost::hana::type_c, FunctionSkeletonRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionLiteralRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionAndRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionOrRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionNotRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionImplyRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionExistsRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionForallRepository {}), + boost::hana::make_pair(boost::hana::type_c, ConditionRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectLiteralRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectAndRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectNumericRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectCompositeForallRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectCompositeWhenRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectCompositeOneofRepository {}), + boost::hana::make_pair(boost::hana::type_c, EffectRepository {}), + boost::hana::make_pair(boost::hana::type_c, ActionRepository {}), + boost::hana::make_pair(boost::hana::type_c, AxiomRepository {}), + boost::hana::make_pair(boost::hana::type_c, OptimizationMetricRepository {}), + boost::hana::make_pair(boost::hana::type_c, NumericFluentRepository {}), + boost::hana::make_pair(boost::hana::type_c, DomainRepository {}), + boost::hana::make_pair(boost::hana::type_c, ProblemRepository {})); } PDDLRepositories::PDDLRepositories() : m_repositories(create_default_pddl_type_to_repository()) {} @@ -59,59 +71,58 @@ PDDLRepositories& PDDLRepositories::operator=(PDDLRepositories&& other) = defaul Requirements PDDLRepositories::get_or_create_requirements(RequirementEnumSet requirement_set) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(requirement_set)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(requirement_set)); } Type PDDLRepositories::get_or_create_type(std::string name, TypeList bases) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(name), std::move(bases)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(name), std::move(bases)); } Variable PDDLRepositories::get_or_create_variable(std::string name) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(name)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(name)); } Term PDDLRepositories::get_or_create_term_variable(Variable variable) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(variable); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(variable); } Term PDDLRepositories::get_or_create_term_object(Object object) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(object); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(object); } Object PDDLRepositories::get_or_create_object(std::string name, TypeList types) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(name), std::move(types)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(name), std::move(types)); } Atom PDDLRepositories::get_or_create_atom(Predicate predicate, TermList terms) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(predicate), std::move(terms)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(predicate), std::move(terms)); } Literal PDDLRepositories::get_or_create_literal(bool is_negated, Atom atom) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(is_negated), std::move(atom)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(is_negated), std::move(atom)); } Parameter PDDLRepositories::get_or_create_parameter(Variable variable, TypeList types) { - return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(variable), std::move(types)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(variable), std::move(types)); } Predicate PDDLRepositories::get_or_create_predicate(std::string name, ParameterList parameters) { - return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(name), std::move(parameters)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(name), std::move(parameters)); } FunctionExpression PDDLRepositories::get_or_create_function_expression_number(double number) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(number); + return boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(number)); } FunctionExpression PDDLRepositories::get_or_create_function_expression_binary_operator(BinaryOperatorEnum binary_operator, @@ -119,122 +130,123 @@ FunctionExpression PDDLRepositories::get_or_create_function_expression_binary_op FunctionExpression right_function_expression) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(binary_operator, - std::move(left_function_expression), - std::move(right_function_expression)); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(binary_operator, std::move(left_function_expression), std::move(right_function_expression))); } FunctionExpression PDDLRepositories::get_or_create_function_expression_multi_operator(MultiOperatorEnum multi_operator, FunctionExpressionList function_expressions_) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(multi_operator, std::move(function_expressions_)); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(multi_operator, std::move(function_expressions_))); } FunctionExpression PDDLRepositories::get_or_create_function_expression_minus(FunctionExpression function_expression) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(function_expression)); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(function_expression))); } FunctionExpression PDDLRepositories::get_or_create_function_expression_function(Function function) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(function)); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(function))); } Function PDDLRepositories::get_or_create_function(FunctionSkeleton function_skeleton, TermList terms) { - return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(function_skeleton), std::move(terms)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(function_skeleton), std::move(terms)); } FunctionSkeleton PDDLRepositories::get_or_create_function_skeleton(std::string name, ParameterList parameters, Type type) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(name), std::move(parameters), std::move(type)); + .get_or_create(std::move(name), std::move(parameters), std::move(type)); } Condition PDDLRepositories::get_or_create_condition_literal(Literal literal) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create( - boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(literal))); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(literal))); } Condition PDDLRepositories::get_or_create_condition_and(ConditionList conditions_) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create( - boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(conditions_))); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(conditions_))); } Condition PDDLRepositories::get_or_create_condition_or(ConditionList conditions_) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create( - boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(conditions_))); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(conditions_))); } Condition PDDLRepositories::get_or_create_condition_not(Condition condition) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create( - boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(condition))); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(condition))); } Condition PDDLRepositories::get_or_create_condition_imply(Condition condition_left, Condition condition_right) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(condition_left), std::move(condition_right))); + .get_or_create( + boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(condition_left), std::move(condition_right))); } Condition PDDLRepositories::get_or_create_condition_exists(ParameterList parameters, Condition condition) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(parameters), std::move(condition))); + .get_or_create( + boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(parameters), std::move(condition))); } Condition PDDLRepositories::get_or_create_condition_forall(ParameterList parameters, Condition condition) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(parameters), std::move(condition))); + .get_or_create( + boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(parameters), std::move(condition))); } Effect PDDLRepositories::get_or_create_effect_literal(Literal literal) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(literal)); + return boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(literal))); } Effect PDDLRepositories::get_or_create_effect_and(EffectList effects_) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(effects_)); + return boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(effects_))); } Effect PDDLRepositories::get_or_create_effect_numeric(AssignOperatorEnum assign_operator, Function function, FunctionExpression function_expression) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(assign_operator), std::move(function), std::move(function_expression)); + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(std::move(assign_operator), std::move(function), std::move(function_expression))); } Effect PDDLRepositories::get_or_create_effect_composite_forall(ParameterList parameters, Effect effect) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(parameters), std::move(effect)); + .get_or_create( + boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(parameters), std::move(effect))); } Effect PDDLRepositories::get_or_create_effect_composite_when(Condition condition, Effect effect) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(condition), std::move(effect)); + .get_or_create( + boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(condition), std::move(effect))); } Effect PDDLRepositories::get_or_create_effect_composite_oneof(EffectList effects_) { - return boost::hana::at_key(m_repositories, boost::hana::type {}).template get_or_create(std::move(effects_)); + return boost::hana::at_key(m_repositories, boost::hana::type {}) + .get_or_create(boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(effects_))); } Action PDDLRepositories::get_or_create_action(std::string name, @@ -244,7 +256,7 @@ Action PDDLRepositories::get_or_create_action(std::string name, std::optional effect) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(name), std::move(original_arity), std::move(parameters), std::move(condition), std::move(effect)); + .get_or_create(std::move(name), std::move(original_arity), std::move(parameters), std::move(condition), std::move(effect)); } Axiom PDDLRepositories::get_or_create_axiom(std::string derived_predicate_name, @@ -253,19 +265,17 @@ Axiom PDDLRepositories::get_or_create_axiom(std::string derived_predicate_name, size_t num_parameters_to_ground_head) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(derived_predicate_name), std::move(parameters), std::move(condition), num_parameters_to_ground_head); + .get_or_create(std::move(derived_predicate_name), std::move(parameters), std::move(condition), num_parameters_to_ground_head); } OptimizationMetric PDDLRepositories::get_or_create_optimization_metric(OptimizationMetricEnum metric, FunctionExpression function_expression) { - return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(metric), std::move(function_expression)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(metric), std::move(function_expression)); } NumericFluent PDDLRepositories::get_or_create_numeric_fluent(Function function, double number) { - return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(function), std::move(number)); + return boost::hana::at_key(m_repositories, boost::hana::type {}).get_or_create(std::move(function), std::move(number)); } Domain PDDLRepositories::get_or_create_domain(std::optional filepath, @@ -279,15 +289,15 @@ Domain PDDLRepositories::get_or_create_domain(std::optional filepath, AxiomList axioms) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(filepath), - std::move(name), - std::move(requirements), - std::move(types), - std::move(constants), - std::move(predicates), - std::move(functions), - std::move(actions), - std::move(axioms)); + .get_or_create(std::move(filepath), + std::move(name), + std::move(requirements), + std::move(types), + std::move(constants), + std::move(predicates), + std::move(functions), + std::move(actions), + std::move(axioms)); } Problem PDDLRepositories::get_or_create_problem(std::optional filepath, @@ -303,16 +313,16 @@ Problem PDDLRepositories::get_or_create_problem(std::optional filepath AxiomList axioms) { return boost::hana::at_key(m_repositories, boost::hana::type {}) - .template get_or_create(std::move(filepath), - std::move(domain), - std::move(name), - std::move(requirements), - std::move(objects), - std::move(derived_predicates), - std::move(initial_literals), - std::move(numeric_fluents), - std::move(goal_condition), - std::move(optimization_metric), - std::move(axioms)); + .get_or_create(std::move(filepath), + std::move(domain), + std::move(name), + std::move(requirements), + std::move(objects), + std::move(derived_predicates), + std::move(initial_literals), + std::move(numeric_fluents), + std::move(goal_condition), + std::move(optimization_metric), + std::move(axioms)); } } diff --git a/tests/unit/pddl/reference.cpp b/tests/unit/pddl/reference.cpp index 0514d5d4..30ea4106 100644 --- a/tests/unit/pddl/reference.cpp +++ b/tests/unit/pddl/reference.cpp @@ -28,8 +28,8 @@ namespace loki::domain::tests TEST(LokiTests, PddlReferenceTest) { SegmentedRepository, UniquePDDLEqualTo> factory(2); - const auto object_0 = factory.get_or_create("object_0", TypeList()); - const auto object_1 = factory.get_or_create("object_1", TypeList()); + const auto object_0 = factory.get_or_create("object_0", TypeList()); + const auto object_1 = factory.get_or_create("object_1", TypeList()); ReferencedPDDLObjects references; EXPECT_TRUE(!references.exists(object_0)); diff --git a/tests/unit/utils/segmented_repository.cpp b/tests/unit/utils/segmented_repository.cpp index 72346ff8..6bab2e76 100644 --- a/tests/unit/utils/segmented_repository.cpp +++ b/tests/unit/utils/segmented_repository.cpp @@ -30,9 +30,9 @@ namespace loki::domain::tests TEST(LokiTests, UtilsSegmentedRepositoryIteratorTest) { SegmentedRepository, UniquePDDLEqualTo> factory(2); - const auto object_0 = factory.get_or_create("object_0", TypeList()); - const auto object_1 = factory.get_or_create("object_1", TypeList()); - const auto object_2 = factory.get_or_create("object_2", TypeList()); + const auto object_0 = factory.get_or_create("object_0", TypeList()); + const auto object_1 = factory.get_or_create("object_1", TypeList()); + const auto object_2 = factory.get_or_create("object_2", TypeList()); auto objects = ObjectList {}; for (const auto& object : factory) @@ -63,12 +63,12 @@ TEST(LokiTests, UtilsSegmentedRepositoryVariantTest) { SegmentedRepository, UniquePDDLEqualTo> objects(2); SegmentedRepository, UniquePDDLEqualTo> terms(2); - const auto object_0 = objects.get_or_create("object_0", TypeList()); - const auto object_1 = objects.get_or_create("object_1", TypeList()); + const auto object_0 = objects.get_or_create("object_0", TypeList()); + const auto object_1 = objects.get_or_create("object_1", TypeList()); - const auto term_0_object_0 = terms.get_or_create(object_0); - const auto term_1_object_0 = terms.get_or_create(object_0); - const auto term_2_object_1 = terms.get_or_create(object_1); + const auto term_0_object_0 = terms.get_or_create(object_0); + const auto term_1_object_0 = terms.get_or_create(object_0); + const auto term_2_object_1 = terms.get_or_create(object_1); EXPECT_EQ(term_0_object_0, term_1_object_0); EXPECT_NE(term_0_object_0, term_2_object_1); @@ -80,18 +80,18 @@ TEST(LokiTests, UtilsSegmentedRepositoryTest) EXPECT_EQ(factory.size(), 0); // Test uniqueness: insert the same element twice - const auto object_0_0 = factory.get_or_create("object_0", TypeList()); + const auto object_0_0 = factory.get_or_create("object_0", TypeList()); EXPECT_EQ(factory.size(), 1); EXPECT_EQ(object_0_0->get_index(), 0); EXPECT_EQ(object_0_0->get_name(), "object_0"); - const auto object_0_1 = factory.get_or_create("object_0", TypeList()); + const auto object_0_1 = factory.get_or_create("object_0", TypeList()); EXPECT_EQ(factory.size(), 1); EXPECT_EQ(object_0_0, object_0_1); EXPECT_EQ(UniquePDDLHasher()(object_0_0), UniquePDDLHasher()(object_0_1)); EXPECT_TRUE(UniquePDDLEqualTo()(object_0_0, object_0_1)); - const auto object_1 = factory.get_or_create("object_1", TypeList()); + const auto object_1 = factory.get_or_create("object_1", TypeList()); EXPECT_EQ(factory.size(), 2); EXPECT_NE(object_0_0, object_1); EXPECT_EQ(object_1->get_index(), 1);