Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  A question on float precision

    Posted 10/28/11 11:40 AM

    Originally posted by: JDalal


    I want to fix some variable x[i][j][k] values in my model.

    Say, I added to model:
    ilo_model.add(x[2][2][0]==0.456728911);
    After solving, CPLEX gives: x[2][2][0] == 0.456729

    I am looking for some way to stop that rounding up. Any suggestion??
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: A question on float precision

    Posted 10/28/11 06:15 PM

    Originally posted by: SystemAdmin


    Are you sure that the value is really 0.456729, or that it is just displayed like this? Displaying only 6 digits is the default for printf, so I wouldn't be surprised if the true value for your variable is equal to 0.456728911.

    But if this is not just a display issue: does the same happen if you fix both bounds of the variable, instead of adding a constraint?
    Tobias
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: A question on float precision

    Posted 10/29/11 03:12 AM

    Originally posted by: SystemAdmin


    Tobias is most probably correct. Since you use C++ I assume you are using operator<< to output the floating point value. The default number of digits after the decimal point for this operator is 6. The following example shows you how to change that:
    #include <iostream>
     
    int
    main(void)
    {
       double num = 0.456728911;
       std::cout << num << std::endl;
       std::streamsize old = std::cout.precision(20);
       std::cout << num << std::endl;
       std::cout.precision(old);
       return 0;
    }
    

    The second time the code prints 'num' it will print it with 20 digits after the point.
    There is one more thing to keep in mind here: Not every rational number can be represented exactly as a double precision floating point number. This means that the number that the compiler generates for '0.456728911' may be slightly different from 0.456728911 as it picks the closest number that can be represented as double precision floating point number. For example, my machine prints 0.45672891100000001519 in the second line. There is nothing you can do about that.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: A question on float precision

    Posted 10/29/11 09:03 AM

    Originally posted by: JDalal


    Thanks both of you. Yes, after using setprecision I checked that the value is actually not changed.
    #CPLEXOptimizers
    #DecisionOptimization