Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Read/write in Excel spreadsheets

    Posted 06/16/15 01:50 PM

    Originally posted by: Kava


    Hi,
     
    I have just tried to create an example of a project similar to xsteel, where the data is read and written into an Excel file.
    It is an extremely simple model of a transportation problem:

    Model :

    // Sets
     {string} FACTORIES =...;
     {string} CLIENTS =...;
     // Data
     float cost[FACTORIES][CLIENTS] =...;
     float capacity[FACTORIES];
     float demand[CLIENTS] =...;
     // Variables
     dvar float+ Send[FACTORIES][CLIENTS];
     // Model
     minimize sum(i in FACTORIES, j in CLIENTS) cost[i][j]*Send[i][j];
     
         subject to {
         
         forall (i in FACTORIES) ctCap: sum(j in CLIENTS) Send[i][j] <= capacity[i];
         forall (j in CLIENTS) ctDem: sum(i in FACTORIES) Send[i][j] <= demand[j];
              
         }

    Data file:

     SheetConnection sheet("Distribution_Examples.xslx");
     
     FACTORIES from SheetRead(sheet,"Transport1!A9:A10");
     CLIENTS from SheetRead(sheet,"Transport1!B8:F8");
     
    cost from SheetRead(sheet,"Transport1!B9:F10");
    capacity from SheetRead(sheet,"Transport1!Capacity");
    demand  from SheetRead(sheet,"Transport1!Demand");

    Send to SheetWrite(sheet,"Transport1!Products_shipped");

     

    When I try to run Cplex, I always get an error  message "Distribution_Examples" file is not found". I have no clue what it can be. The Excel file is in the same folder as .mod and .dat files.

     

    PS xsteel examples does not work as well, when I replace its Excel file with a similar new Excel file.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Read/write in Excel spreadsheets

    Posted 06/16/15 02:58 PM

    Hi

    can you tr to replace

    SheetConnection sheet("Distribution_Examples.xslx");

    by an absolute path ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Read/write in Excel spreadsheets

    Posted 06/17/15 06:07 AM

    Originally posted by: Kava


    I tried an absolute path with no success Frown This is really weird...


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Read/write in Excel spreadsheets

    Posted 06/17/15 03:11 PM

    Hi,

    and if you run the oil example that reads an excel spreadsheet, what happens ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Read/write in Excel spreadsheets

    Posted 06/17/15 03:47 PM

    Originally posted by: Kava


    Strangely, the oil example worked well even when I had created a different .xslx file with a different name and just copied the data. It read data and wrote results in workbooks of this new file.

     

    When I did the same thing with xsteel example, i.e. created a different .xslx file with a different name and just copied the data, I got again the error "file not found".

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Read/write in Excel spreadsheets

    Posted 06/17/15 03:59 PM

    Hi,

    have you noticed that for oil you have a .xls and not an .xlsx ?

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Read/write in Excel spreadsheets

    Posted 06/17/15 04:18 PM

    Originally posted by: Kava


    Sure, but it works fine even if I create a new .xslx file.

     

    But when I try to do the same in my own project, I always get the "file not found" error.
     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Read/write in Excel spreadsheets

    Posted 06/18/15 02:21 AM

    Hi,

    can you zip your project and attach it here ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Read/write in Excel spreadsheets

    Posted 06/18/15 05:24 AM

    Originally posted by: Kava


    Sure. Thanks for helping !


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Read/write in Excel spreadsheets

    Posted 06/18/15 05:29 AM

    Hi,

    I see a clear discrepancy:

    in .dat SheetConnection sheet("Distribution_Examples.xslx");

    wheras the name of the file is Distribution_Examples.xlsx

    xslx is not xlsx!

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Read/write in Excel spreadsheets

    Posted 06/18/15 05:34 AM

    Originally posted by: Kava


    Oh my god :D

    I should have thought about that. You are right, now it works fine. Thanks a lot for help !


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Read/write in Excel spreadsheets

    Posted 03/15/19 09:38 AM

    Originally posted by: hhkkato


    Hi everyone

    I am a complete newbie to CPLEX OPL

    I have recently been trying to convert the model in the attached file into OPL code I have failed miserably

    Could someone show me how to set it up, especially in defining the data and decision variables?

    I will be glad to receive all the help as can be possibly available

    Thank you in advance


    #DecisionOptimization
    #OPLusingCPLEXOptimizer