Originally posted by: ecnirp
Hi,
I'm solving a problem with column generation. At some point, I want to take the master problem called mpModel and change all variables' type to ILOBOOL from ILOFLOAT. I then want to solve the integer program and retrieve the solution. Cplex does seem to be solving the integer program correctly (and to optimality), but when I try to print out the optimal objective function value and variable values, it gives me fractional values. Here is some of the code:
IloModel model1(env); //create a new model
IloCplex cplex1(model1); //create cplex object
model1.add(mpModel); //copy the current model
for (int b=0; b< (*data).NoBlocks; b++)
for (int p=0; p < (*pcol)[b].size; p++)
model1.add(IloConversion(env, MU[b][p], ILOBOOL));
for (int w=0; w<(*wcol).size; w++)
model1.add(IloConversion(env, LAMBDA[w], ILOBOOL));
cplex1.exportModel("MIPnew.lp");
cplex1.solve();
ofstream outfileSOL("IntegerSolution.txt");
outfileSOL << "Objective Function value: " << cplex1.getObjValue() << endl << endl;
for (int w=0; w < (*wcol).size; w++)
outfileSOL << "LAMBDA[" << w << "]=" << cplex1.getValue(LAMBDA[w]) << endl;
for (int b=0; b < (*data).NoBlocks; b++)
for (int p=0; p < (*pcol)[b].size; p++)
outfileSOL << "MU[" << b << "][" << p << "]=" << cplex1.getValue(MU[b][p]) << endl;
The strange thing is that when I check IntegerSolution.txt, I do not see integer values, and the objective is not the optimal integer solution objective function value. However, if I solve MIPnew.lp using the interactive optimizer, the solution file gives me integer values.
Any idea what is going on?
I am especially surprised because when I created the following example (which mimics my code above), it prints out integer values from cplex1.
IloModel model(env);
IloCplex cplex(model);
IloNumVar x(env);
IloNumVar y(env);
model.add(IloMinimize(env,x + y));
model.add(x >=0.5);
model.add(y >= 0.25);
cplex.solve();
cout << "Objective function value: " << cplex.getObjValue() << endl;
cout << "x: " << cplex.getValue(x) << endl;
cout << "y: " << cplex.getValue(y) << endl << endl;
IloModel model1(env);
IloCplex cplex1(model1);
model1.add(model);
model1.add(IloConversion(env, x, ILOBOOL));
model1.add(IloConversion(env, y, ILOBOOL));
cplex1.solve();
cout << "Objective function value: " << cplex1.getObjValue() << endl;
cout << "x: " << cplex1.getValue(x) << endl;
cout << "y: " << cplex1.getValue(y) << endl;
#CPLEXOptimizers#DecisionOptimization