Originally posted by: snOm3ad
Hello,
I have a huge number of constraints that need to be added to a model in the form of lazy constraints, now as far as I know there are two ways to do this. Using the 'IloCplex::addLazyConstraints' method or create your own callback class either by hand or by means of the macros offered. My problem is that when I try to use the former method, I get an IloException thrown saying that the cut is invalid. Now according to the documentation this can happen whenever a cut is malformed, which can be one or more of the following cases:
-
A cut that uses variables that have not been extracted to the model is malformed.
-
A cut defined by an expression that is not linear is malformed.
-
A cut is also considered malformed when it has already been extracted for the invoking IloCplex object and is thus already a part of the model.
However, none of these seem to fit my case, what's more confusing is that when solving a small instance I can add these constraints directly to the model using 'IloModel::add' method with no problems whatsoever. Is there something I am missing? For context, here is a sample of the code I am using.
int const V = G.get_vertices();
IloRangeArray linking(env, V * V * V * V, -IloInfinity, 0);
linking.setNames("linking_avail_link");
for (int i = 0; i < V; ++i) {
for (int j = 0; j < V; ++j) {
for (int k = 0; k < V; ++k) {
for (int m = 0; m < V; ++m) {
if (i != j and k != m) {
// construct the cut expression
IloExpr cut { env };
cut += w[i][j][k][m];
cut -= y[k][m];
int const idx = utl::compute_index(i, j, k, m);
linking[idx].setExpr(cut);
cut.end();
}
}
}
}
}
//cplex.addLazyConstraints(linking); // Fails with IloCplex::InvalidCutException
model.add(linking); // succeeds!
#CPLEXOptimizers#DecisionOptimization