Skip to content

Commit

Permalink
variant types are not handled consistently. removed HolderType from S…
Browse files Browse the repository at this point in the history
…egmentedRepository since variants are handled differently now.
  • Loading branch information
drexlerd committed Nov 25, 2024
1 parent 5da19a9 commit d3a2a24
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 203 deletions.
9 changes: 2 additions & 7 deletions include/loki/details/pddl/declarations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ class EffectCompositeWhenImpl;
using EffectCompositeWhen = const EffectCompositeWhenImpl*;
class EffectCompositeOneofImpl;
using EffectCompositeOneof = const EffectCompositeOneofImpl*;
using EffectImpl =
std::variant<EffectLiteralImpl, EffectAndImpl, EffectNumericImpl, EffectCompositeForallImpl, EffectCompositeWhenImpl, EffectCompositeOneofImpl>;
class EffectImpl;
using Effect = const EffectImpl*;
using EffectList = std::vector<Effect>;

Expand All @@ -128,11 +127,7 @@ class FunctionExpressionMinusImpl;
using FunctionExpressionMinus = const FunctionExpressionMinusImpl*;
class FunctionExpressionFunctionImpl;
using FunctionExpressionFunction = const FunctionExpressionFunctionImpl*;
using FunctionExpressionImpl = std::variant<FunctionExpressionNumberImpl,
FunctionExpressionBinaryOperatorImpl,
FunctionExpressionMultiOperatorImpl,
FunctionExpressionMinusImpl,
FunctionExpressionFunctionImpl>;
class FunctionExpressionImpl;
using FunctionExpression = const FunctionExpressionImpl*;
using FunctionExpressionList = std::vector<FunctionExpression>;

Expand Down
24 changes: 24 additions & 0 deletions include/loki/details/pddl/effects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ class EffectCompositeOneofImpl
const EffectList& get_effects() const;
};

/* EffectImpl */
class EffectImpl
{
private:
size_t m_index;
std::variant<EffectLiteral, EffectAnd, EffectNumeric, EffectCompositeForall, EffectCompositeWhen, EffectCompositeOneof> m_effect;

EffectImpl(size_t index, std::variant<EffectLiteral, EffectAnd, EffectNumeric, EffectCompositeForall, EffectCompositeWhen, EffectCompositeOneof> effect);

// Give access to the constructor.
template<typename HolderType, typename Hash, typename EqualTo>
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<EffectLiteral, EffectAnd, EffectNumeric, EffectCompositeForall, EffectCompositeWhen, EffectCompositeOneof>& 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);
Expand Down
39 changes: 39 additions & 0 deletions include/loki/details/pddl/function_expressions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,45 @@ class FunctionExpressionFunctionImpl
const Function& get_function() const;
};

/* FunctionExpression */
class FunctionExpressionImpl
{
private:
size_t m_index;
std::variant<FunctionExpressionNumber,
FunctionExpressionBinaryOperator,
FunctionExpressionMultiOperator,
FunctionExpressionMinus,
FunctionExpressionFunction>
m_function_expression;

FunctionExpressionImpl(size_t index,
std::variant<FunctionExpressionNumber,
FunctionExpressionBinaryOperator,
FunctionExpressionMultiOperator,
FunctionExpressionMinus,
FunctionExpressionFunction> function_expression);

// Give access to the constructor.
template<typename HolderType, typename Hash, typename EqualTo>
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<FunctionExpressionNumber,
FunctionExpressionBinaryOperator,
FunctionExpressionMultiOperator,
FunctionExpressionMinus,
FunctionExpressionFunction>&
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);
Expand Down
143 changes: 81 additions & 62 deletions include/loki/details/pddl/repositories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,68 +49,87 @@
namespace loki
{

using RequirementsRepository = SegmentedRepository<RequirementsImpl, UniquePDDLHasher<const RequirementsImpl*>, UniquePDDLEqualTo<const RequirementsImpl*>>;
using TypeRepository = SegmentedRepository<TypeImpl, UniquePDDLHasher<const TypeImpl*>, UniquePDDLEqualTo<const TypeImpl*>>;
using VariableRepository = SegmentedRepository<VariableImpl, UniquePDDLHasher<const VariableImpl*>, UniquePDDLEqualTo<const VariableImpl*>>;
using TermRepository = SegmentedRepository<TermImpl, UniquePDDLHasher<const TermImpl*>, UniquePDDLEqualTo<const TermImpl*>>;
using ObjectRepository = SegmentedRepository<ObjectImpl, UniquePDDLHasher<const ObjectImpl*>, UniquePDDLEqualTo<const ObjectImpl*>>;
using AtomRepository = SegmentedRepository<AtomImpl, UniquePDDLHasher<const AtomImpl*>, UniquePDDLEqualTo<const AtomImpl*>>;
using LiteralRepository = SegmentedRepository<LiteralImpl, UniquePDDLHasher<const LiteralImpl*>, UniquePDDLEqualTo<const LiteralImpl*>>;
using ParameterRepository = SegmentedRepository<ParameterImpl, UniquePDDLHasher<const ParameterImpl*>, UniquePDDLEqualTo<const ParameterImpl*>>;
using PredicateRepository = SegmentedRepository<PredicateImpl, UniquePDDLHasher<const PredicateImpl*>, UniquePDDLEqualTo<const PredicateImpl*>>;
using FunctionExpressionRepository =
SegmentedRepository<FunctionExpressionImpl, UniquePDDLHasher<const FunctionExpressionImpl*>, UniquePDDLEqualTo<const FunctionExpressionImpl*>>;
using FunctionRepository = SegmentedRepository<FunctionImpl, UniquePDDLHasher<const FunctionImpl*>, UniquePDDLEqualTo<const FunctionImpl*>>;
using FunctionSkeletonRepository =
SegmentedRepository<FunctionSkeletonImpl, UniquePDDLHasher<const FunctionSkeletonImpl*>, UniquePDDLEqualTo<const FunctionSkeletonImpl*>>;
using ConditionLiteralRepository =
SegmentedRepository<ConditionLiteralImpl, UniquePDDLHasher<const ConditionLiteralImpl*>, UniquePDDLEqualTo<const ConditionLiteralImpl*>>;
using ConditionAndRepository = SegmentedRepository<ConditionAndImpl, UniquePDDLHasher<const ConditionAndImpl*>, UniquePDDLEqualTo<const ConditionAndImpl*>>;
using ConditionOrRepository = SegmentedRepository<ConditionOrImpl, UniquePDDLHasher<const ConditionOrImpl*>, UniquePDDLEqualTo<const ConditionOrImpl*>>;
using ConditionNotRepository = SegmentedRepository<ConditionNotImpl, UniquePDDLHasher<const ConditionNotImpl*>, UniquePDDLEqualTo<const ConditionNotImpl*>>;
using ConditionImplyRepository =
SegmentedRepository<ConditionImplyImpl, UniquePDDLHasher<const ConditionImplyImpl*>, UniquePDDLEqualTo<const ConditionImplyImpl*>>;
using ConditionExistsRepository =
SegmentedRepository<ConditionExistsImpl, UniquePDDLHasher<const ConditionExistsImpl*>, UniquePDDLEqualTo<const ConditionExistsImpl*>>;
using ConditionForallRepository =
SegmentedRepository<ConditionForallImpl, UniquePDDLHasher<const ConditionForallImpl*>, UniquePDDLEqualTo<const ConditionForallImpl*>>;
using ConditionRepository = SegmentedRepository<ConditionImpl, UniquePDDLHasher<const ConditionImpl*>, UniquePDDLEqualTo<const ConditionImpl*>>;
using EffectRepository = SegmentedRepository<EffectImpl, UniquePDDLHasher<const EffectImpl*>, UniquePDDLEqualTo<const EffectImpl*>>;
using ActionRepository = SegmentedRepository<ActionImpl, UniquePDDLHasher<const ActionImpl*>, UniquePDDLEqualTo<const ActionImpl*>>;
using AxiomRepository = SegmentedRepository<AxiomImpl, UniquePDDLHasher<const AxiomImpl*>, UniquePDDLEqualTo<const AxiomImpl*>>;
using OptimizationMetricRepository =
SegmentedRepository<OptimizationMetricImpl, UniquePDDLHasher<const OptimizationMetricImpl*>, UniquePDDLEqualTo<const OptimizationMetricImpl*>>;
using NumericFluentRepository = SegmentedRepository<NumericFluentImpl, UniquePDDLHasher<const NumericFluentImpl*>, UniquePDDLEqualTo<const NumericFluentImpl*>>;
using DomainRepository = SegmentedRepository<DomainImpl, UniquePDDLHasher<const DomainImpl*>, UniquePDDLEqualTo<const DomainImpl*>>;
using ProblemRepository = SegmentedRepository<ProblemImpl, UniquePDDLHasher<const ProblemImpl*>, UniquePDDLEqualTo<const ProblemImpl*>>;

using PDDLTypeToRepository = boost::hana::map<boost::hana::pair<boost::hana::type<RequirementsImpl>, RequirementsRepository>,
boost::hana::pair<boost::hana::type<TypeImpl>, TypeRepository>,
boost::hana::pair<boost::hana::type<VariableImpl>, VariableRepository>,
boost::hana::pair<boost::hana::type<TermImpl>, TermRepository>,
boost::hana::pair<boost::hana::type<ObjectImpl>, ObjectRepository>,
boost::hana::pair<boost::hana::type<AtomImpl>, AtomRepository>,
boost::hana::pair<boost::hana::type<LiteralImpl>, LiteralRepository>,
boost::hana::pair<boost::hana::type<ParameterImpl>, ParameterRepository>,
boost::hana::pair<boost::hana::type<PredicateImpl>, PredicateRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionImpl>, FunctionExpressionRepository>,
boost::hana::pair<boost::hana::type<FunctionImpl>, FunctionRepository>,
boost::hana::pair<boost::hana::type<FunctionSkeletonImpl>, FunctionSkeletonRepository>,
boost::hana::pair<boost::hana::type<ConditionLiteralImpl>, ConditionLiteralRepository>,
boost::hana::pair<boost::hana::type<ConditionAndImpl>, ConditionAndRepository>,
boost::hana::pair<boost::hana::type<ConditionOrImpl>, ConditionOrRepository>,
boost::hana::pair<boost::hana::type<ConditionNotImpl>, ConditionNotRepository>,
boost::hana::pair<boost::hana::type<ConditionImplyImpl>, ConditionImplyRepository>,
boost::hana::pair<boost::hana::type<ConditionExistsImpl>, ConditionExistsRepository>,
boost::hana::pair<boost::hana::type<ConditionForallImpl>, ConditionForallRepository>,
boost::hana::pair<boost::hana::type<ConditionImpl>, ConditionRepository>,
boost::hana::pair<boost::hana::type<EffectImpl>, EffectRepository>,
boost::hana::pair<boost::hana::type<ActionImpl>, ActionRepository>,
boost::hana::pair<boost::hana::type<AxiomImpl>, AxiomRepository>,
boost::hana::pair<boost::hana::type<OptimizationMetricImpl>, OptimizationMetricRepository>,
boost::hana::pair<boost::hana::type<NumericFluentImpl>, NumericFluentRepository>,
boost::hana::pair<boost::hana::type<DomainImpl>, DomainRepository>,
boost::hana::pair<boost::hana::type<ProblemImpl>, ProblemRepository>>;
template<typename T>
using SegmentedPDDLRepository = SegmentedRepository<T, UniquePDDLHasher<const T*>, UniquePDDLEqualTo<const T*>>;

using RequirementsRepository = SegmentedPDDLRepository<RequirementsImpl>;
using TypeRepository = SegmentedPDDLRepository<TypeImpl>;
using VariableRepository = SegmentedPDDLRepository<VariableImpl>;
using TermRepository = SegmentedPDDLRepository<TermImpl>;
using ObjectRepository = SegmentedPDDLRepository<ObjectImpl>;
using AtomRepository = SegmentedPDDLRepository<AtomImpl>;
using LiteralRepository = SegmentedPDDLRepository<LiteralImpl>;
using ParameterRepository = SegmentedPDDLRepository<ParameterImpl>;
using PredicateRepository = SegmentedPDDLRepository<PredicateImpl>;
using FunctionExpressionNumberRepository = SegmentedPDDLRepository<FunctionExpressionNumberImpl>;
using FunctionExpressionBinaryOperatorRepository = SegmentedPDDLRepository<FunctionExpressionBinaryOperatorImpl>;
using FunctionExpressionMultiOperatorRepository = SegmentedPDDLRepository<FunctionExpressionMultiOperatorImpl>;
using FunctionExpressionMinusRepository = SegmentedPDDLRepository<FunctionExpressionMinusImpl>;
using FunctionExpressionFunctionRepository = SegmentedPDDLRepository<FunctionExpressionFunctionImpl>;
using FunctionExpressionRepository = SegmentedPDDLRepository<FunctionExpressionImpl>;
using FunctionRepository = SegmentedPDDLRepository<FunctionImpl>;
using FunctionSkeletonRepository = SegmentedPDDLRepository<FunctionSkeletonImpl>;
using ConditionLiteralRepository = SegmentedPDDLRepository<ConditionLiteralImpl>;
using ConditionAndRepository = SegmentedPDDLRepository<ConditionAndImpl>;
using ConditionOrRepository = SegmentedPDDLRepository<ConditionOrImpl>;
using ConditionNotRepository = SegmentedPDDLRepository<ConditionNotImpl>;
using ConditionImplyRepository = SegmentedPDDLRepository<ConditionImplyImpl>;
using ConditionExistsRepository = SegmentedPDDLRepository<ConditionExistsImpl>;
using ConditionForallRepository = SegmentedPDDLRepository<ConditionForallImpl>;
using ConditionRepository = SegmentedPDDLRepository<ConditionImpl>;
using EffectLiteralRepository = SegmentedPDDLRepository<EffectLiteralImpl>;
using EffectAndRepository = SegmentedPDDLRepository<EffectAndImpl>;
using EffectNumericRepository = SegmentedPDDLRepository<EffectNumericImpl>;
using EffectCompositeForallRepository = SegmentedPDDLRepository<EffectCompositeForallImpl>;
using EffectCompositeWhenRepository = SegmentedPDDLRepository<EffectCompositeWhenImpl>;
using EffectCompositeOneofRepository = SegmentedPDDLRepository<EffectCompositeOneofImpl>;
using EffectRepository = SegmentedPDDLRepository<EffectImpl>;
using ActionRepository = SegmentedPDDLRepository<ActionImpl>;
using AxiomRepository = SegmentedPDDLRepository<AxiomImpl>;
using OptimizationMetricRepository = SegmentedPDDLRepository<OptimizationMetricImpl>;
using NumericFluentRepository = SegmentedPDDLRepository<NumericFluentImpl>;
using DomainRepository = SegmentedPDDLRepository<DomainImpl>;
using ProblemRepository = SegmentedPDDLRepository<ProblemImpl>;

using PDDLTypeToRepository =
boost::hana::map<boost::hana::pair<boost::hana::type<RequirementsImpl>, RequirementsRepository>,
boost::hana::pair<boost::hana::type<TypeImpl>, TypeRepository>,
boost::hana::pair<boost::hana::type<VariableImpl>, VariableRepository>,
boost::hana::pair<boost::hana::type<TermImpl>, TermRepository>,
boost::hana::pair<boost::hana::type<ObjectImpl>, ObjectRepository>,
boost::hana::pair<boost::hana::type<AtomImpl>, AtomRepository>,
boost::hana::pair<boost::hana::type<LiteralImpl>, LiteralRepository>,
boost::hana::pair<boost::hana::type<ParameterImpl>, ParameterRepository>,
boost::hana::pair<boost::hana::type<PredicateImpl>, PredicateRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionNumberImpl>, FunctionExpressionNumberRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionBinaryOperatorImpl>, FunctionExpressionBinaryOperatorRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionMultiOperatorImpl>, FunctionExpressionMultiOperatorRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionMinusImpl>, FunctionExpressionMinusRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionFunctionImpl>, FunctionExpressionFunctionRepository>,
boost::hana::pair<boost::hana::type<FunctionExpressionImpl>, FunctionExpressionRepository>,
boost::hana::pair<boost::hana::type<FunctionImpl>, FunctionRepository>,
boost::hana::pair<boost::hana::type<FunctionSkeletonImpl>, FunctionSkeletonRepository>,
boost::hana::pair<boost::hana::type<ConditionLiteralImpl>, ConditionLiteralRepository>,
boost::hana::pair<boost::hana::type<ConditionAndImpl>, ConditionAndRepository>,
boost::hana::pair<boost::hana::type<ConditionOrImpl>, ConditionOrRepository>,
boost::hana::pair<boost::hana::type<ConditionNotImpl>, ConditionNotRepository>,
boost::hana::pair<boost::hana::type<ConditionImplyImpl>, ConditionImplyRepository>,
boost::hana::pair<boost::hana::type<ConditionExistsImpl>, ConditionExistsRepository>,
boost::hana::pair<boost::hana::type<ConditionForallImpl>, ConditionForallRepository>,
boost::hana::pair<boost::hana::type<ConditionImpl>, ConditionRepository>,
boost::hana::pair<boost::hana::type<EffectLiteralImpl>, EffectLiteralRepository>,
boost::hana::pair<boost::hana::type<EffectAndImpl>, EffectAndRepository>,
boost::hana::pair<boost::hana::type<EffectNumericImpl>, EffectNumericRepository>,
boost::hana::pair<boost::hana::type<EffectCompositeForallImpl>, EffectCompositeForallRepository>,
boost::hana::pair<boost::hana::type<EffectCompositeWhenImpl>, EffectCompositeWhenRepository>,
boost::hana::pair<boost::hana::type<EffectCompositeOneofImpl>, EffectCompositeOneofRepository>,
boost::hana::pair<boost::hana::type<EffectImpl>, EffectRepository>,
boost::hana::pair<boost::hana::type<ActionImpl>, ActionRepository>,
boost::hana::pair<boost::hana::type<AxiomImpl>, AxiomRepository>,
boost::hana::pair<boost::hana::type<OptimizationMetricImpl>, OptimizationMetricRepository>,
boost::hana::pair<boost::hana::type<NumericFluentImpl>, NumericFluentRepository>,
boost::hana::pair<boost::hana::type<DomainImpl>, DomainRepository>,
boost::hana::pair<boost::hana::type<ProblemImpl>, ProblemRepository>>;

extern PDDLTypeToRepository create_default_pddl_type_to_repository();

Expand Down
Loading

0 comments on commit d3a2a24

Please sign in to comment.