2
$\begingroup$

I have faced a little weird problem when I use Cplex to solve my test problem. Basically, some of my data are float numbers up to three decimal numbers (For instance, 0.627). But, when I print out the model using the exportModel command, I noticed that Cplex converts all the float numbers to numbers with much more degree of precision (For example, 0.627 to 0.626999974250793). As a result of this, Cplex gives me the wrong optimal solution. I'd be grateful if you could let me know what is the cause of this error and how I can prevent this convergence?

I should note that I use Concert technology C++.

$\endgroup$
5
  • 2
    $\begingroup$ 0.627 cannot be stored exactly in IEEE-754 floating point arithmetic. The decimal representation of the value that can actually be stored is 0.62699997425079345703125 . So numerically, everything is ok. $\endgroup$
    – T_O
    Jun 8, 2021 at 15:22
  • $\begingroup$ In what way is the optimal solution wrong (and by how much)? $\endgroup$
    – prubin
    Jun 8, 2021 at 15:45
  • $\begingroup$ Basically, the optimal objective value for the test instance I am dealing with, reported as 222 (It is a maximization problem). But, when I call Cplex, it reports 224 as the optimal objective value. When I use the original data that I have (with three decimal floating point) and verify the value of the decision variables given by Cplex, it gives the objective value of 126 !!! I also multiply all the float numbers by 1000. This time Cplex gives 223 as the optimal value $\endgroup$
    – Sam
    Jun 8, 2021 at 15:54
  • $\begingroup$ I just multiply all the float numbers by a very big number (100000000000), surprisingly Cplex reports the right optimal value (222) $\endgroup$
    – Sam
    Jun 8, 2021 at 15:59
  • $\begingroup$ I am still a bit confused. Is there any way to systematically avoid these sort of errors? $\endgroup$
    – Sam
    Jun 8, 2021 at 16:00

1 Answer 1

2
$\begingroup$

instead of exporting into a .lp you could export into a .sav filre and then you won't face those rounding issues.

SAV is a binary file format specific to CPLEX. This format is efficient for fast reading and writing of models and associated basis information. For example, it can effectively reduce read and write time for problems that are solved repetitively.

Tip: CPLEX includes the basis in a SAV file only if the problem currently in memory has been optimized and a basis exists.

This format also offers the advantage of being numerically accurate (to the same degree as your platform) in contrast to text file formats that may lose numerical accuracy. In other words, it provides a greater degree of precision in data. However, since a SAV file is binary, you cannot read nor edit it with your favorite text editor.

$\endgroup$
3
  • $\begingroup$ For the sake of clarity, would you mean that if I read the data from a .sav file, Cplex won't do conversions issues and I will work with exactly the same data I provided to it? $\endgroup$
    – Sam
    Jun 8, 2021 at 16:11
  • $\begingroup$ Yes that's it. Right $\endgroup$ Jun 8, 2021 at 16:23
  • $\begingroup$ Great, many thanks ! $\endgroup$
    – Sam
    Jun 9, 2021 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.