Skip to content

Commit

Permalink
MP2NL: replace obj type #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Nov 28, 2024
1 parent 2d40f2f commit 58f9b37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion solvers/mp2nl/mp2nlmodelapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void MP2NLModelAPI::SetLinearObjective( int iobj, const LinearObjective& lo ) {
auto ii = MakeItemInfo(lo, StaticItemTypeID::ID_LinearObjective, false);
if (iobj == (int)obj_info_.size())
obj_info_.push_back(std::move(ii));
else obj_info_[iobj] = std::move(ii);
else
obj_info_[iobj] = std::move(ii);
}

void MP2NLModelAPI::SetQuadraticObjective(int iobj, const QuadraticObjective& qo) {
Expand Down
13 changes: 12 additions & 1 deletion solvers/mp2nl/mp2nlmodelapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,9 @@ class MP2NLModelAPI
enum class StaticItemTypeID {
ID_None,
ID_LinearObjective,
ID_ObjFirst = ID_LinearObjective,
ID_NLObjective,
ID_ObjLast = ID_NLObjective,

ID_LinConRange,
ID_LinConLE,
Expand Down Expand Up @@ -1384,7 +1386,8 @@ class MP2NLModelAPI
ii.f_marked_, std::move(ii.lin_part_ext_)) { }
/// operator=(&&)
ItemInfo& operator=(ItemInfo&& ii) noexcept {
assert(&disp_==&ii.disp_);
assert (&disp_==&ii.disp_ // same type, just moving;
|| (IsObjective() && ii.IsObjective())); // or, replace obj
p_item_ = ii.p_item_;
assert(f_logical_==ii.f_logical_);
f_marked_ = ii.f_marked_;
Expand All @@ -1410,6 +1413,14 @@ class MP2NLModelAPI
/// Get static item type ID, if any
StaticItemTypeID GetStaticTypeID() const
{ return GetDispatcher().GetStaticItemTypeID(); }
/// Is an objective?
bool IsObjective() const {
return IsItemTypeStatic()
&& (StaticItemTypeID::ID_LinearObjective
==GetStaticTypeID()
|| StaticItemTypeID::ID_NLObjective
==GetStaticTypeID());
}
/// Get expression type ID, if any
ExpressionTypeID GetExprTypeID() const
{ return GetDispatcher().GetExpressionTypeID(); }
Expand Down

0 comments on commit 58f9b37

Please sign in to comment.