Skip to content

Commit

Permalink
MO emulator with NL objective #237 #239
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Nov 8, 2024
1 parent f33821f commit 502e5a9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
5 changes: 3 additions & 2 deletions include/mp/flat/converter_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ class FlatModel
template <class Backend>
void SetObjectiveTo(
Backend& backend, int i, const QuadraticObjective& obj) const {
if (obj.HasExpr())
if (obj.HasExpr()) {
assert(obj.GetQPTerms().empty()); // not mixing qudratics and expr
backend.SetNLObjective(i, obj);
else if (obj.GetQPTerms().size())
} else if (obj.GetQPTerms().size())
backend.SetQuadraticObjective(i, obj);
else
backend.SetLinearObjective(i, obj);
Expand Down
13 changes: 12 additions & 1 deletion include/mp/flat/converter_multiobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mp/valcvt-base.h"
#include "mp/error.h"
#include "mp/flat/obj_std.h"
#include "mp/flat/nl_expr/constr_nl.h"

namespace mp {

Expand Down Expand Up @@ -216,7 +217,17 @@ class MOManager {
auto diff = std::max( // Apply degradation tolerance
obj_new_tola_[i_current_obj_-1], std::fabs(lim) * obj_new_tolr_[i_current_obj_-1]);
lim += diff * (obj::MAX==obj_last.obj_sense() ? -1.0 : 1.0);
if (obj_last.GetQPTerms().size()) {
if (obj_last.HasExpr()) {
assert(obj_last.GetQPTerms().empty()); // not mixing QP and expression term
if (obj::MAX == obj_last.obj_sense())
MPD( AddConstraint(
NLConstraint{ obj_last.GetLinTerms(), obj_last.ExprIndex(),
{ lim, MPCD(Inf()) } } ) );
else
MPD( AddConstraint(
NLConstraint{ obj_last.GetLinTerms(), obj_last.ExprIndex(),
{ MPCD(MinusInf()), lim } } ) );
} else if (obj_last.GetQPTerms().size()) {
if (obj::MAX == obj_last.obj_sense())
MPD( AddConstraint(
QuadConGE{ { obj_last.GetLinTerms(), obj_last.GetQPTerms() }, lim } ) );
Expand Down
4 changes: 3 additions & 1 deletion include/mp/flat/obj_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class NLObjective : public LinearObjective {
};


/// Quadratic objective
/// Quadratic objective.
/// @note Should have no expression
/// but we check HasExpr() to see if it is an NLObjective really
class QuadraticObjective : public NLObjective {
QuadTerms qt_;
public:
Expand Down
3 changes: 2 additions & 1 deletion solvers/baronmp/baronmpcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ int BaronmpCommon::run(const std::vector<std::string>& args) {
exec_args.push_back(nullptr); // Null-terminate the argument list

if (execve(cmd_path.c_str(), exec_args.data(), environ) == -1) {
fmt::print(stderr, "execve failed: {}\n", strerror(errno));
fmt::print(stderr, "execve({}, ..., ...) failed: {}\n",
cmd_path.c_str(), strerror(errno));
exit(EXIT_FAILURE);
}
}
Expand Down
12 changes: 11 additions & 1 deletion test/end2end/cases/categorized/fast/multi_obj/modellist.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,15 @@
"ANYSOLVER_options": "obj:no=2"
},
"objective": 4.3333333333333333333
}
},
{
"name" : "obj_expr_01 obj:multi=2",
"tags" : ["linear", "integer", "multiobj"],
"options": {
"ANYSOLVER_options": "obj:multi=2 cvt:bigm=1e6"
},
"values": {
"_sobj[1]": 71.42954735,
"_sobj[2]": 218.1608589
} }
]
18 changes: 18 additions & 0 deletions test/end2end/cases/categorized/fast/multi_obj/obj_expr_01.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Nonlinear expressions in objectives

var x {1..3} >=-30 <=54;

s.t. X1LB: x[1] >=34;
s.t. X2LB: x[2] >= 2;

s.t. ConL1L: x[1] + 2*x[2] <= 137;

s.t. ConNL1: x[1] + x[3] - x[2]^1.5 >= -17;

suffix objpriority; ## To enable lexicographic optimization

maximize Obj1: -0.55*x[1] + 4*x[2] + log(abs(x[3] / x[2]) + 0.5)
suffix objpriority 2;

minimize Obj4: 5*x[2] + x[3] + x[2]^1.24
suffix objpriority 1;

0 comments on commit 502e5a9

Please sign in to comment.