diff --git a/lib/include/modeling/models/Model.h b/lib/include/modeling/models/Model.h index 7ca4b622..6cb8c4c9 100644 --- a/lib/include/modeling/models/Model.h +++ b/lib/include/modeling/models/Model.h @@ -41,6 +41,7 @@ namespace idol { class idol::Model : public Matrix { Env& m_env; const unsigned int m_id; + bool m_has_been_moved = false; ObjectiveSense m_sense = Minimize; Expr m_objective; @@ -72,8 +73,10 @@ class idol::Model : public Matrix { */ explicit Model(Env& t_env); + Model(Env& t_env, ObjectiveSense t_sense); + Model(const Model&) = delete; - Model(Model&&) noexcept = default; + Model(Model&&) noexcept; Model& operator=(const Model&) = delete; Model& operator=(Model&&) noexcept = delete; diff --git a/lib/src/modeling/models/Model.cpp b/lib/src/modeling/models/Model.cpp index 451e739e..345d868f 100644 --- a/lib/src/modeling/models/Model.cpp +++ b/lib/src/modeling/models/Model.cpp @@ -6,8 +6,35 @@ idol::Model::Model(Env &t_env) : m_env(t_env), m_id(t_env.create_model_id()) {} + +idol::Model::Model(idol::Env &t_env, idol::ObjectiveSense t_sense) : Model(t_env) { + set_obj_sense(t_sense); +} + + +idol::Model::Model(idol::Model && t_src) noexcept + : m_env(t_src.m_env), + m_id(t_src.m_id), + m_sense(t_src.m_sense), + m_objective(std::move(t_src.m_objective)), + m_rhs(std::move(t_src.m_rhs)), + m_variables(std::move(t_src.m_variables)), + m_constraints(std::move(t_src.m_constraints)), + m_optimizer(std::move(t_src.m_optimizer)), + m_optimizer_factory(std::move(t_src.m_optimizer_factory)) +{ + + t_src.m_has_been_moved = true; + +} + + idol::Model::~Model() { + if (m_has_been_moved) { + return; + } + for (const auto& var : m_variables) { m_env.remove_version(*this, var); }