How to include scalars in the objective using c++
AnsweredHi,
I have a problem in which I want to minimize (Ax + B(y + 1)) where A and B are scalars and x,y are boolean variables. I am using the function
GRBaddvars(model, num_var, 0, NULL, NULL, NULL, objective, zlb, zub, zctype, colnames);
GRBsetintattr(model, GRB_INT_ATTR_MODELSENSE, GRB_MINIMIZE);
where objective is defined as:
objective = new double[num_var];
for (i = 0; i < num_var; i++)
objective[i] = 0.0;
for (r = 0; r < varX; r++) {
objective[X[r]] = A; //
}
for (r = 0; r < varY; r++) {
objective[Y[r]] = B; //
}
but I don´t know how to include the scalar B.
My current solution is that the objective is to minimize (Ax + By), so +B is missing. How can I include this in my current implementation?
Thanks.
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Laura,
There are 2 ways to achieve adding a constant to your objective.
You could use the setObjective method instead of setting the \(\texttt{obj}\) attribute for your variables.
The second approach, which probably fits your current code better, is to introduce a dummy variable with lower and upper bound equal to \(1\) and set its objective attribute to \(\texttt{B}\).
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments