Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

CPLEX OPL: Error in reading float from excel

  • 1.  CPLEX OPL: Error in reading float from excel

    Posted Fri March 02, 2018 01:47 PM

    Originally posted by: HendrikWijnant


    Dear all, 

    I recently started using CPLEX optimization studio for solving an MILP. While trying to read some float values from excel, I stumbled upon a problem. The problem is that CPLEX apparently changes some of these float values by a factor of 100 and leaves other unchanged. I tried to find why CPLEX does this on the internet or in the CPLEX and OPL guides but I could not find the answer anywhere. 
    So what happens is the following:
    Using Sheetread, I read some float values into a 2dimensional array of floats. for example values like:

    0,0033333
    0,0000625
    4,1666700
    8,3333300
    0,0001563

    CPLEX apparently reads these values like this:
     0,0033333
    0,0000625
    416,66700
    833,33300
    0,0001563

    The values > 1 are multiplied by 100 and I have absolutely no idea why. 

     

    This is my code:

     

    In the mod file:

    range rRows = 1..nRows;
    range rColumns = 1..9;
    float data[rRows][rColumns] = ...;

     

    In the data file:

    SheetConnection sheet2("Data_50i.xlsx");

       nRows from SheetRead(sheet2,"Lines");
      data from SheetRead(sheet2,"Input");

     

    I added the datafile in the attachments (it concerns column H, named as v[f])


     Is there anyone that has an idea on how this is possible?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: CPLEX OPL: Error in reading float from excel

    Posted Tue March 06, 2018 03:06 AM

    Hi,

    if I change your .mod into

    int nRows=...;
    range rRows = 1..nRows;
    range rColumns = 1..9;
    float data[rRows][rColumns] = ...;

    execute
    {
    writeln(data[65][8]);

    }

    I get

    4.167

    so why do you think you get 416 ?

    Which cplex version do you use ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: CPLEX OPL: Error in reading float from excel

    Posted Tue March 06, 2018 04:05 AM

    Originally posted by: HendrikWijnant


    Thanks a lot Alex for helping me.
    I just noticed that I uploaded the wrong excel file. Could you try it with this file. 

    Code .mod:

    int nRows = ...;
    range rRows = 1..nRows;
    range rColumns = 1..9;
    float data[rRows][rColumns] = ...;
     
    execute write_result {
      var file = new IloOplOutputFile("test.csv");
      file.writeln(data[65][8]);
     }

    Code .dat

     SheetConnection sheet("Data_50i.xlsx");

     nRows from SheetRead(sheet,"nRows");
     data from SheetRead(sheet,"Data");

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: CPLEX OPL: Error in reading float from excel

    Posted Tue March 06, 2018 04:35 AM

    Hi,

    in test.csv I get

    4.16667

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: CPLEX OPL: Error in reading float from excel

    Posted Tue March 06, 2018 04:54 AM

    Originally posted by: HendrikWijnant


    I found my problem. I opened the csv file using excel and excel apparently imported it incorrect.
    Thanks for your help Alex, I greatly appreciate it.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer