Originally posted by: Jernej1
Hello,
I am building a ILP model that I am interested in solving and examining all its solutions. The underlying problem is pretty much a (integer) partition problem with some constraints on partition sizes. By following the ilopopulate.cpp example, I have come up with the following code
static void refine(const unsigned d[CONF_SIZE]) {
unsigned i,j;
int status;
try {
IloModel model(env);
IloNumVarArray var(env);
IloRangeArray con(env);
IloCplex cplex(model);
cplex.setParam(IloCplex::Param::MIP::Pool::Intensity, 4);
cplex.setParam(IloCplex::Param::MIP::Limits::Solutions, SOLSBOUND);
cplex.setParam(IloCplex::Param::MIP::Limits::Populate, SOLSBOUND);
for (i = 0; i < 2*CONF_SIZE; i++) {
var.add( IloNumVar(env, 0, d[i], IloNumVar::Int));
var.add( IloNumVar(env, 0, d[i], IloNumVar::Int));
}
for (i = 0; i < CONF_SIZE; i++) {
con.add(var[2*i] + var[2*i+1] == d[i]);
}
for (i = 0; i < 2*CONF_SIZE; i++) {
IloExpr expr = (N-K+1)*var[i];
for (j = 0; j < K; j++) {
expr += var[i ^ (1<<j)];
}
con.add( expr >= 1<<(N-K) );
}
model.add(con);
cplex.populate();
int numsol = cplex.getSolnPoolNsolns();
for (i = 0; i < numsol; i++) {
IloNumArray vals(env);
cplex.getValues(vals, var, i);
}
} catch(IloException& e) {
std::cerr << "Concert exception caught: " << e << std::endl;
}
catch(...) {
std::cerr << "Unknown exception caught" << std::endl;
}
}
Unfortunately this example raises an exception due to the call to getValues, namely
Concert exception caught: IloExtractable 9 IloNumVarI has not been extracted by IloAlgorithm 0x3f0bf10
I have no idea why this error is being caused. Can someone help me understand how to use populate properly so that I can access all the feasible solutions of the modeled problem?
#CPLEXOptimizers#DecisionOptimization