Getting the value of a GRBVar in C++ before optimization
AnsweredHello,
I have a 2d dynamically created array of GRBVar and i want to get the value in order to add a new constraint to my model before i call the model.optimize() function. Is there any way to achieve it?
void pickup_delivery_same(GRBVar*** x, GRBVar** z, GRBModel& model)
{
for (int i = 0; i < customers; i++)
{
GRBLinExpr expr = 0.0;
for (int j = 0; j < customers; j++)
{
if (z[i][j].get(GRB_DoubleAttr_X) == 1) // HERE IS THE ERROR
{
for (int k = 0; k < vehicles; k++)
{
for (int l = 1, p = 1; l <= customers && p <= customers; l++, p++)
{
expr += x[l][i][k] - x[p][j][k];
}
}
}
}
model.addConstr(expr == 0);
}
}
I've tried to use the model's method get with attribute GRB_DoubleAttr_X but this throws me an error with number 10005.
0
-
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. -
The X attribute is the value of a previously found feasible solution point. This attribute won't be available and will result in an error as long as no feasible solution has been found. To find a feasible solution, you have to run the optimization for at least some time to find at least one feasible solution point. Thus, accessing this attribute before calling model.optimize() will not work.
0
Post is closed for comments.
Comments
2 comments