Search code examples
cplex

cplex Is it possible to get an integer solution?


I am using Ilog Cplex with Visual C++ 2015 to solve my MILP problem. We know that CPLEX Optimizers implement conventional floating-point arithmetic to represent numbers. I have the following questions. (1) Is it possible to get an exact integer solution from solver without using the function IloRound ? Does cplex.setParam(IloCplex::EpInt, 0) work? I found some integer variables are 0.999999... even when I use cplex.setParam(IloCplex::EpInt, 0). (2) When I get a optimal solution, I Assign some integer variables to an int type array directly without using the function IloRound. Then I fix these variables to values in this int type array using the setBounds function and rerun the model solving. I repect a same optimal solution. But somethimes the reruning is infeasible. What is the correct way to do it?


Solution

  • In order to convert the floating point values for integer variables to actual integer values you must use some sort of rounding. Or maybe even better use a function like lrint(). In C++, if you convert a floating value to an integral value then the values is truncated, not rounded. That means that a value like 0.999999 will be converted to 0 instead of 1. That can then of course lead to infeasibility. So in order to write robust code, you should use a function that explicitly converts from floating point to integers, no matter whether the floating point values are exactly integral or not.

    Setting EpInt to 0 should prevent CPLEX from returning slightly fractional values for integer variables. However, this applies only to the presolved model. When uncrushing the solution, small fractionalities can creep into the solution.

    It may also be that this is caused by bad numbers in your problem data. You should check whether your model has slightly fractional numbers that should actually be integer, has a wide range of coefficients, etc. In order to check that you can set the DataCheck parameter to 2 and see whether the modeling assistance feature produces any warnings in the log.