Skip to content

Commit

Permalink
fixes move operator for Model
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Oct 9, 2023
1 parent f101ec4 commit 9311cac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/include/modeling/models/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Var> m_objective;
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions lib/src/modeling/models/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9311cac

Please sign in to comment.