10#include "idol/mixed-integer/modeling/variables/Var.h"
11#include "idol/mixed-integer/modeling/variables/VarVersion.h"
12#include "idol/mixed-integer/modeling/variables/TempVar.h"
15#include "idol/mixed-integer/modeling/annotations/impl_Annotation.h"
16#include "idol/mixed-integer/modeling/constraints/QCtrVersion.h"
17#include "idol/mixed-integer/modeling/constraints/QCtr.h"
18#include "idol/mixed-integer/modeling/constraints/TempQCtr.h"
19#include "idol/mixed-integer/modeling/constraints/SOSCtrVersion.h"
20#include "idol/mixed-integer/modeling/constraints/SOSCtr.h"
29 template<
unsigned int Start>
35template<
unsigned int Start>
36class idol::impl::IdProvider {
37 unsigned int m_max_id = Start;
38 std::list<unsigned int> m_free_ids;
40 void free(
unsigned int t_id) { m_free_ids.emplace_back(t_id); }
42 unsigned int create() {
43 if (m_free_ids.empty()) {
47 auto result = m_free_ids.back();
48 m_free_ids.pop_back();
53class idol::impl::Env {
54 unsigned int m_max_object_id = 0;
56 IdProvider<1> m_model_ids;
57 IdProvider<0> m_annotation_ids;
59 std::list<Versions<VarVersion>> m_variables;
60 std::list<Versions<CtrVersion>> m_constraints;
61 std::list<Versions<QCtrVersion>> m_qconstraints;
62 std::list<Versions<SOSCtrVersion>> m_sosconstraints;
64 template<
class T,
class VersionT,
class ...ArgsT>
65 ObjectId<VersionT> create(std::string t_name,
const std::string& t_default_name, std::list<Versions<VersionT>>& t_container, ArgsT&& ...t_args) {
66 const unsigned int id = m_max_object_id++;
67 std::string name = t_name.empty() ? t_default_name +
'_' + std::to_string(
id) : std::move(t_name);
68 t_container.emplace_front(-1, std::forward<ArgsT>(t_args)...);
69 return { t_container.begin(), id, std::move(name) };
72 unsigned int create_model_id() {
return m_model_ids.create(); }
74 void free_model_id(const ::idol::Model& t_model);
76 unsigned int create_annotation_id() {
return m_annotation_ids.create(); }
78 void free_annotation_id(
const impl::Annotation& t_annotation);
80 template<
class T,
class ...ArgsT>
81 void create_version(
const Model& t_model,
const T& t_object,
unsigned int t_index, ArgsT&& ...t_args) {
82 t_object.create_version(t_model, t_index, std::forward<ArgsT&&>(t_args)...);
86 void remove_version(
const Model& t_model,
const T& t_object) {
87 t_object.remove_version(t_model);
91 bool has_version(
const Model& t_model,
const T& t_object)
const {
92 return t_object.is_in(t_model);
96 const auto& version(
const Model& t_model,
const T& t_object)
const {
97 return t_object.versions().get(t_model);
101 auto& version(
const Model& t_model,
const T& t_object) {
102 return const_cast<T&
>(t_object).versions().get(t_model);
105 ObjectId<VarVersion> create_var(std::string t_name, TempVar&& t_temp_var) {
106 return create<Var>(std::move(t_name),
"x", m_variables, std::move(t_temp_var));
109 ObjectId<CtrVersion> create_ctr(std::string t_name, TempCtr&& t_temp_ctr) {
110 return create<Ctr>(std::move(t_name),
"c", m_constraints, std::move(t_temp_ctr));
113 ObjectId<QCtrVersion> create_qctr(std::string t_name, TempQCtr&& t_temp_ctr) {
114 return create<QCtr>(std::move(t_name),
"c", m_qconstraints, std::move(t_temp_ctr));
117 ObjectId<SOSCtrVersion> create_sosctr(std::string t_name,
bool t_is_sos1, std::vector<Var>&& t_vars, std::vector<double>&& t_weights) {
118 return create<SOSCtr>(std::move(t_name),
"sos", m_sosconstraints, t_is_sos1, std::move(t_vars), std::move(t_weights));
124 Env(
const Env&) =
delete;
125 Env(Env&&) noexcept = delete;
127 Env& operator=(const Env&) = delete;
128 Env& operator=(Env&&) noexcept = delete;
137 const auto& operator[](const T& t_object)
const {
138 return t_object.versions().get_default();
178 friend class impl::Annotation;