Originally posted by: SystemAdmin
Given your approach, there could be 2 reasons for the difference in objective values.
Firstly, cplex1 essentially represents the model in memory and CPLEX would come with a certain optimal value for the same. cplex2, however is not the same model- it is the LP version of the model in memory. Since the LP format is a ASCII based format, certain variable values may be ever so slightly different in the higher orders of the decimals that could cause a difference in the solution path and the optimal value of the slightly different model, thus leading to the difference in objective values. To prevent this, you should write (and read) the model in the SAV format which is a binary format that preserves the numerical precision of the different co-efficients that are present in the model. Hence you should replace:
cplex.writeModel(
'enr.lp'); cplex.readModel(
'enr.lp');cplex2=cplex;
with
cplex.writeModel(
'enr.sav'); cplex.readModel(
'enr.sav');cplex2=cplex;
The second reason for the difference in objective values could be that CPLEX stops with the MIPGAP tolerance setting of (0.01%) in the default CPLEX parameter settings. Thus, any solution which is less than 0.01% from the optimal solution is considered optimal. Indeed, in the runs, if you check for the value of the relative mipgap tolerance of the solution (ans.miprelgap), it shows up as 9.9658e-005. Thus, it is possible that by writing out the model in a LP format, and then reading it again and solving it, the order of the variables could change leading to a different solution path with cplex2, and hence CPLEX could end up with a optimal solution with a slightly different relative mipgap which is also less than the 0.01% requirement. If you absolutely want to make sure that different Cplex object that represent the same model always have the same optimal value, then you will need to change the relative MIPGAP setting from its default value of 0.01% (1e-4) to 0 which will force CPLEX to always solve the model to absolute optimality. You should be able to change this setting by executing the following line of code:
cplex.Param.mip.tolerances.mipgap.Cur=0;
I hope this helps and explains the behavior.
#CPLEXOptimizers#DecisionOptimization