Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  OPL script not saving float number accurately

    Posted 03/04/14 09:45 PM

    Originally posted by: Calvin Sun Hainan


    When I do a calculation for Math.ceil(a/(b*c)) within OPL script, it rounds up the result incorrectly.

    If I print the result for a/(b*c) - Math.floor(a/(b*c)), I can see this value: 2.273736754432321e-013.

    Within OPL script, we can only define var type and I guess the exact value of my float number "b" has been modified before it is passed to Math.ceil function. Does anyone have similar problem before. How do I solve this problem?

    I can write something like if a/(b*c) - Math.floor(a/(b*c)) < 1-e010, then do not use Math.ceil(x), but that is not so nice.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL script not saving float number accurately

    Posted 03/05/14 12:10 PM

    Hi,

    can you post a small example ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: OPL script not saving float number accurately

    Posted 03/05/14 09:15 PM

    Originally posted by: Calvin Sun Hainan


    CRF data:

    #SECURITY;Security_ID;Security_Description;Unit_Price_USD
    SECURITY;"ISIN:EUR";"EUR";1.37340000

    I used Double.parseDouble() to parse in the above Unit_Price_USD and then store it as a double value in java. In Java if I print the value out with ceil or floor it is OK. Then I use the java function provided by IBM IloOplDataHandler.addNumItem(Unit_Price_USD) to read the above value 1.3734 into OPL. It seems that the problem happens here when it converts the double value to float. In OPL, I have the following tuple:

    tuple TSecurity {key string securityId;string securityDescription;float unitPriceUsd;};

    When I try to do floor(unitPriceUsd * 10000) within OPL script, it gives me 13733.

    If I do a writeln (Math.ceil(s.unitPriceUsd * 10000) - s.unitPriceUsd * 10000); in OPL script. It gives me the following strange value.

    1.818989403545857e-012

     It looks to me OPL script is using 32-bit precision here.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL script not saving float number accurately

    Posted 03/06/14 05:09 AM

    Hi

    yes you re right the scripting uses 32 bits. So you should try to do the computations in the modeling part.

     

    int i=1234891261234;
    int j=i+1;

    execute
    {
    j;
    i;
    writeln("ok")
    }

    execute
    {
    j=i+1;
    i;
    writeln("ok2")
    }

     

    displays ok and then fails since i+1 is valid in OPL but not in scripting

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL script not saving float number accurately

    Posted 03/06/14 05:25 AM

    Originally posted by: Calvin Sun Hainan


    OK. Thanks. I will try to find a way to deal with it. Is there any plan to enhance OPL script to use 64 bits? OPL script is really useful as it can help write logics in a very shor time.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL script not saving float number accurately



  • 7.  Re: OPL script not saving float number accurately

    Posted 07/28/18 03:01 AM

    Originally posted by: Baby Bone


    I'm having problems with OPL .mod file not only with Math.floor, (e.g., I tested even the most simple Math.floor(5.3), and it returned a 0. 

    The reason I used Math.floor was actually because I needed the % function (to find the remainder), but it didn't work. It's returning a 0 no matter what the inputs are. Does any know why this might be the case? I'm using v12.8 on my Mac. 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: OPL script not saving float number accurately

    Posted 07/28/18 04:09 AM

    Hi

    execute
    {
    var a=Math.floor(5.3);
    writeln(a);
    }

    gives

    5

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer