Getting the value of a GRBVar in C++ before optimization
回答済みHello,
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
-
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
サインインしてコメントを残してください。
コメント
1件のコメント