Skip to content

Commit

Permalink
MP2NL: replace obj #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Oct 29, 2024
1 parent 14d7aad commit 3b6df84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 14 additions & 6 deletions solvers/mp2nl/mp2nlmodelapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,28 @@ void MP2NLModelAPI::AddVariables(const VarArrayDef& vad) {


void MP2NLModelAPI::SetLinearObjective( int iobj, const LinearObjective& lo ) {
assert(iobj == (int)obj_info_.size());
obj_info_.push_back(
MakeItemInfo(lo, StaticItemTypeID::ID_LinearObjective, false));
assert(iobj == (int)obj_info_.size()
|| (!iobj && 1==obj_info_.size())); // replacing objective
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);
}

void MP2NLModelAPI::SetQuadraticObjective(int iobj, const QuadraticObjective& qo) {
assert(iobj == (int)obj_info_.size());
assert(iobj == (int)obj_info_.size()
|| (!iobj && 1==obj_info_.size())); // replacing objective
/// @todo ?
throw std::runtime_error("Quadratic objective not supported");
}

void MP2NLModelAPI::SetNLObjective( int iobj, const NLObjective& nlo ) {
assert(iobj == (int)obj_info_.size());
obj_info_.push_back(MakeItemInfo(nlo, StaticItemTypeID::ID_NLObjective, false));
assert(iobj == (int)obj_info_.size()
|| (!iobj && 1==obj_info_.size())); // replacing objective
auto ii = MakeItemInfo(nlo, StaticItemTypeID::ID_NLObjective, false);
if (iobj == (int)obj_info_.size())
obj_info_.push_back(std::move(ii));
else obj_info_[iobj] = std::move(ii);
}


Expand Down
10 changes: 10 additions & 0 deletions solvers/mp2nl/mp2nlmodelapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,16 @@ class MP2NLModelAPI
: disp_(disp), p_item_(pitem), f_logical_(fLogical)
// no storing, itemID_(iid), exprID_(eid)
{ }
/// Copy construct
ItemInfo(const ItemInfo& ii)
: ItemInfo(ii.disp_, ii.p_item_, ii.f_logical_) { }
/// operator=
ItemInfo& operator=(const ItemInfo& ii) {
assert(&disp_==&ii.disp_);
p_item_ = ii.p_item_;
assert(f_logical_==ii.f_logical_);
return *this;
}
/// Get dispatcher
BasicItemDispatcher& GetDispatcher() const { return disp_; }
/// Get &item
Expand Down

0 comments on commit 3b6df84

Please sign in to comment.