10#include "idol/general/utils/Vector.h"
11#include "idol/general/utils/Pair.h"
12#include "idol/mixed-integer/modeling/annotations/Annotation.h"
13#include "idol/general/utils/exceptions/Exception.h"
18 template<
class T,
class CRTP>
25template<
class T,
class CRTP>
27 std::shared_ptr<ObjectId<T>> m_object_id;
29 [[nodiscard]]
auto& versions() {
return m_object_id->versions(); }
31 [[nodiscard]]
const auto& versions()
const {
return m_object_id->versions(); }
33 template<
class ...ArgsT>
34 void create_version(
const Model& t_model,
unsigned int t_index, ArgsT&& ...t_args)
const {
35 m_object_id->versions().create(t_model, t_index, std::forward<ArgsT>(t_args)...);
38 void remove_version(
const Model& t_model)
const {
39 m_object_id->versions().remove(t_model);
54 [[nodiscard]]
const std::string&
name()
const {
return m_object_id->name(); }
60 [[nodiscard]]
unsigned int id()
const {
return m_object_id->id(); }
67 [[nodiscard]]
bool is_in(
const Model& t_model)
const {
return m_object_id->versions().has(t_model); }
79 const auto& result = m_object_id->versions().template get_annotation<ValueT>(t_annotation.id());
83 if (t_annotation.has_default()) {
84 return t_annotation.default_value();
86 throw Exception(
"No value could be found and no default value was given for annotation " + t_annotation.name());
96 template<
class ValueT,
class ...ArgsT>
void set(
const Annotation<ValueT>& t_annotation, ArgsT&& ...t_args)
const { m_object_id->versions().template set_annotation<ValueT, ArgsT...>(t_annotation.id(), std::forward<ArgsT>(t_args)...); }
101 template<
class T,
class CRTP>
102 static std::ostream &operator<<(std::ostream &t_os,
const Object<T, CRTP> &t_var) {
103 return t_os << t_var.name();
108namespace idol::impl {
110 template<
class U,
unsigned int N,
unsigned int I = 0>
111 static ::idol::Vector<U, N - I> create_many(
const Dim<N>& t_dims,
const std::string& t_name,
const std::function<U(
const std::string& t_name)>& t_add_one) {
112 ::idol::Vector<U, N - I> result;
113 const unsigned int size = t_dims[I];
114 result.reserve(size);
115 for (
unsigned int i = 0 ; i < size ; ++i) {
116 const std::string name = t_name +
"_" + std::to_string(i);
117 if constexpr (I == N - 1) {
118 result.emplace_back( t_add_one(name) );
120 result.emplace_back( create_many<U, N, I+1>(t_dims, name, t_add_one) );
128#define IDOL_MAKE_HASHABLE(name) \
130struct std::hash<idol::name> { \
131 std::size_t operator()(const idol::name& t_variable) const { \
132 return std::hash<unsigned int>()(t_variable.id()); \
137struct std::equal_to<idol::name> { \
138 std::size_t operator()(const idol::name& t_a, const idol::name& t_b) const { \
139 return t_a.id() == t_b.id(); \
143struct std::less<idol::name> { \
144 std::size_t operator()(const idol::name& t_a, const idol::name& t_b) const { \
145 return t_a.id() < t_b.id(); \
149struct std::equal_to<idol::Pair<idol::name, idol::name>> { \
150 std::size_t operator()(const idol::Pair<idol::name, idol::name>& t_a, const idol::Pair<idol::name, idol::name>& t_b) const { \
151 return std::equal_to<idol::name>()(t_a.first, t_b.first) && std::equal_to<idol::name>()(t_a.second, t_b.second); \
const ValueT & get(const Annotation< ValueT > &t_annotation) const
void set(const Annotation< ValueT > &t_annotation, ArgsT &&...t_args) const
const std::string & name() const
bool is_in(const Model &t_model) const