Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Convert an Int Array to a String Array

    Posted 01/22/17 07:32 AM

    Originally posted by: pineapple365


    hello everyone, as the attachments. I want to let nbArray2 to another array which is constructed by string index called Demand[Markets][Products][Levels] .

    Do you know how to transfer that?

    Thank you very much.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Convert an Int Array to a String Array

    Posted 01/23/17 03:07 AM

    Hi,

    {string} Market={"M"};
    {string} Product={"M"};
    {string} Level={"M"};

    int nbArray2[Market][Product][Level]=[[[5]]];

    int Demand[m in Market][p in Product][l in Level]=nbArray2[m][p][l];

    execute
    {
    writeln(Demand);
    }

    gives

    [[[5]]]

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Convert an Int Array to a String Array

    Posted 01/23/17 08:53 AM

    Originally posted by: pineapple365


    Thanks very much! But there is a new problem, input data is in an Excel file, Excel can only storage a 2-Dimensional data, so I should create a middle parameter called nb2 to read data from excel and then convert nb2( 2-Dimensional ) to nbArray( 3-Dimensional ) . But  my code seems not work. Could you please give me more suggestion?

    Regards.

    // test.mode

    {string} Market={"M"};
    {string} Product={"M"};
    {string} Level={"M"};

    //nb2 is reading 2-dimensional data from Excel 
    int nb2[Market][Product*Level]= ...;
    //convert 2-dimensional array to 3-dimensional array
    int nbArray2[Market][Product][Level]= nb2[Market][Product*Level];
    int Demand[m in Market][p in Product][l in Level]=nbArray2[m][p][l];
    execute
    {
    writeln(Demand);
    }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    // test.dat
    Market = 2;
    Product = 2;
    Level = 3;

    SheetConnection sheetInput("3DimArray.xls");

    // If the data elements are in a 2 dimensional array
    nb2 from SheetRead(sheetInput,"data!B17:G18");

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Convert an Int Array to a String Array

    Posted 01/24/17 04:06 AM

    Hi,

    have you had a look at the Tech Note http://www-01.ibm.com/support/docview.wss?uid=swg21401340

    Reading a 3-dimensional array from an Excel spreadsheet

    ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Convert an Int Array to a String Array

    Posted 01/24/17 04:31 AM

    Originally posted by: pineapple365


    Alex, I have read that instruction and got known that {string}*{string} does not work. So I change the data type to int(int Markets =...;) , and success in 3-dimensional data convertion. Thank you for your following. Thanks very much.

    regards.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Convert an Int Array to a String Array

    Posted 01/15/19 01:12 AM

    Originally posted by: MOBEA93


    Hi pineapple365,

    I have the exact same issue and I try to declare my sets in Integer type instead of strings as you said  but still it does not work.

    Could you please share your last mod file or explain a little bit more how you switch from string to int ?

     

    Thanks in Advance,

    Regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Convert an Int Array to a String Array

    Posted 01/15/19 03:20 AM

    Hi,

    you could try ord : https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.ide.help/OPL_Studio/opllang_quickref/topics/tlr_oplf_ord.html

    And .mod

    /***** SETS *****/
    {int} Nc=...; //Set of customers
    {int} Np=...;// Set of plants
    {int}K=...;//set of items

    /***** PARAMETERS *****/
    int nbCustomers =...;
    int nbProducts=...;
    int nbPeriods=...;


    int nb1[1..nbCustomers*nbProducts*nbPeriods] = ...;// matrix of demand
    int d[m in 1..nbCustomers, p in 1..nbProducts,s in 1..nbPeriods]=nb1[s+nbPeriods*(p-1)+nbProducts*nbPeriods*(m-1)];//Array demand of a customer for a specific item  at time periodZ

     

    int demand[m in Nc][p in K][s in 1..nbPeriods]=d[ord(Nc,m)+1][ord(K,p)+1][s];

    execute{
        write(demand);
    };

    and .dat

    Nc={1,2,3};
    Np= {1,2};
    K={1,2,3};

    //demand of a customer for a specific item  at time period
    nbCustomers =3;
    nbProducts=3;
    nbPeriods=5;

    SheetConnection sheetInput("SCIPdata1.xlsx");
    nb1 from SheetRead(sheetInput,"Sheet2!D1:D45");

    regards

     

    https://www.linkedin.com/pulse/loptimisation-faire-plus-avec-moins-un-zoo-des-bus-et-alex-fleischer-1/


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Convert an Int Array to a String Array

    Posted 01/15/19 08:06 AM

    Originally posted by: MOBEA93


    Hello,

    It's working perfectly, thank you so much . Shy

    Regards
     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer