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.
-
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
Please sign in to leave a comment.
Comments
1 comment