Modelling squared euclidean distance in objective function (C-API)
AnsweredI want to implement the following objective function in the C-API:
min (x²-1) + (y²-1)
As far as I see it in the documentation I would need to reformulate the objective function to
min x²-2x+1 + y²-2y+1
using the objective Attribute for the linear terms and GRBaddqpterms for the quadratic values. In that case I would need to add as well the constant value after the optimization, which is no problem of course. But I am curious if there is a more "elegant" way of incorporating this in the objective function?
-
Hi Christian,
I'm guessing you have a typo and your objective is meant to be \(\min \quad (x-1)^2 + (y-1)^2 \)
You can add a constant to the objective like so:
error = GRBsetdblattr(model, "ObjCon", 2.0);
This is also a valid alternative:
\[\begin{align*} \min \quad w^2 + z^2 \\ w = x-1 \\ z = y-1 \end{align*}\]
- Riley
0
Please sign in to leave a comment.
Comments
1 comment