diff --git a/include/mp/flat/constr_2_expr.h b/include/mp/flat/constr_2_expr.h index 21d0be6ab..41123a84d 100644 --- a/include/mp/flat/constr_2_expr.h +++ b/include/mp/flat/constr_2_expr.h @@ -284,7 +284,10 @@ class Constraints2Expr { /// Convert objectives void ConvertObjectivesWithExpressions() { - auto& objs = MPD( get_objectives() ); + auto& objs_emulated = MPD( get_emulated_objectives() ); + auto& objs_original = MPD( get_objectives() ); + auto& objs + = objs_emulated.size() ? objs_emulated : objs_original; for (size_t iobj=0; iobj& + get_emulated_objectives() const { return obj_new_; } + /// Retrieve emulated objectives + std::vector& + get_emulated_objectives() { return obj_new_; } + /// Is MOManager active? /// This is relevant after initialization via /// ConsiderEmulatingMultiobj(). @@ -138,17 +145,20 @@ class MOManager { obj_new_tolr_.reserve(pr_map.size()); for (const auto& pr_level: pr_map) { const auto& i0_vec = pr_level.second; - obj_new_.push_back(obj_orig.at(i0_vec.front())); - obj_new_.back().set_sense(obj_orig.front().obj_sense()); // "Legacy" obj:multi:weight + const auto& obj_orig_1st = obj_orig.at(i0_vec.front()); + const auto objwgt_1st = objwgt.at(i0_vec.front()); + obj_new_.push_back(obj_orig_1st); + obj_new_.back().set_sense(obj_orig.front().obj_sense()); // "Legacy" obj:multi:weight obj_new_.back().set_sense_true(obj_orig.front().obj_sense_true()); - obj_new_.back().GetLinTerms() *= objwgt.at(i0_vec.front()); // Use weight - obj_new_.back().GetQPTerms() *= objwgt.at(i0_vec.front()); + obj_new_.back().GetLinTerms() *= objwgt_1st; // Use weight + obj_new_.back().GetQPTerms() *= objwgt_1st; obj_new_tola_.push_back(objtola.at(i0_vec.front())); obj_new_tolr_.push_back(objtolr.at(i0_vec.front())); + assert (!obj_orig_1st.HasExpr()); // should be before NL conversion for (auto i0i=i0_vec.size(); --i0i; ) { // Add next objective with weight and sense factor double sensef - = (obj_orig.at(i0_vec.front()).obj_sense() == obj_orig.at(i0_vec[i0i]).obj_sense()) + = (obj_orig_1st.obj_sense() == obj_orig.at(i0_vec[i0i]).obj_sense()) ? 1.0 : -1.0; auto lt1 = obj_orig.at(i0_vec[i0i]).GetLinTerms(); lt1 *= sensef * objwgt.at(i0_vec[i0i]); @@ -156,6 +166,7 @@ class MOManager { qt1 *= sensef * objwgt.at(i0_vec[i0i]); obj_new_.back().GetLinTerms().add(lt1); obj_new_.back().GetQPTerms().add(qt1); + assert (!obj_orig.at(i0_vec[i0i]).HasExpr()); // Max the tolerances obj_new_tola_.back() = std::max(obj_new_tola_.back(), objtola.at(i0_vec[i0i])); obj_new_tolr_.back() = std::max(obj_new_tolr_.back(), objtolr.at(i0_vec[i0i])); @@ -290,6 +301,7 @@ class MOManager { } } + private: MOManagerStatus status_ {MOManagerStatus::NOT_SET}; std::vector obj_new_; // ranked aggregated objectives diff --git a/include/mp/flat/nl_expr/model_api_base.h b/include/mp/flat/nl_expr/model_api_base.h index a2adbea29..25ceeb104 100644 --- a/include/mp/flat/nl_expr/model_api_base.h +++ b/include/mp/flat/nl_expr/model_api_base.h @@ -289,7 +289,8 @@ class BasicExprModelAPI /// or for the implicit InitExpression(). Expr GetInitExpression(int i_expr) { /// FlatConverter should have marked all expressions; - assert(i_expr < (int)is_expr_stored_.size()); + MP_ASSERT_ALWAYS(i_expr < (int)is_expr_stored_.size(), + "unexpected expression index"); // if (i_expr >= (int)is_expr_stored_.size()) { // is_expr_stored_.resize(int(i_expr*1.3)+1); // expr_stored_.resize(int(i_expr*1.3)+1);