Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How to insert data for a multidimentional array in cplex v12.5?

  • 1.  How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 02:42 AM

    Originally posted by: khadeejah


    one of my input parameters is Axyz , where x,y, t are index sets.  ; where Axyz  unit is $/meter square/week

    In the mod. file, x and y are string and t (which is periods) is int.

     

    {string} Xprod = ...;
    {string} Ystages = ...;

    int   Nbperiods = ...;
    range periods   = 1..Nbperiods;

     

    Any suggestions?


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 05:17 AM

    Originally posted by: SebastianFink


    Hi,

    according to the doc at

    http://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_datastructures_arrays.html

    and

    http://www.ibm.com/support/knowledgecenter/SSSA5P_12.5.0/ilog.odms.ide.help/OPL_Studio/opllangref/topics/opl_langref_data_init_arrays.html

     

    you can define

    int a[Xprod][yStages][periods] = ...; 

    in your model and something like

    a = [

    [ [ 1, 2, 3], [4, 5, 6]],

    [ [ 5, 3, 2], [4, 3, 8]]

    ];

    in your .dat file. This variant is without indexing. You can also use the indexed declaration described in the second link, remember to change the outer brackets from "["/"]" to "#["/"]#" and use "key : value" syntax.

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 05:45 AM

    Originally posted by: khadeejah


    If IF A[x][y][z] & x=1...2, y=1.....6, z=1.....12
    How to write this in the data file??

    in the mod file its, 

    float  Axyz   [prod][stages][periods]= ...;

     

    still i'm not clear about how to do its .dat file!!


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 06:25 AM

    Originally posted by: SebastianFink


    I'm not sure I understand your question, but you can write

     Axyz = [

    [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],

    ... , // 6 rows in total (because the second index y=1..6)

     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]

    ];

    in your .dat file to initialize the array.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 08:19 AM

    Originally posted by: khadeejah


    I mean that X, y, and Z are sets , each one includes the number of elements i mentioned. 

    x includes two elements , y includes 6 elements, z includes 12 elements.

    what you wrote now is only for Y and Z , what about X. 

    Did you get my point?

     

     

     

     

     

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/23/16 08:39 AM

    Originally posted by: SebastianFink


    Sorry, my mistake. I lost part of the initialization when copying. Also, I've highlighted the brackets for the additional dimension in blue - I hope it's clearer now

     Axyz = [

    [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],

    ... , // 6 rows in total (because the second index y=1..6)

     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]],

    [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],

    ... , // 6 rows for the second index in x

     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]

    ];

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 03:15 AM

    Originally posted by: khadeejah


    in the same context of the previous question, ICist= Axyz

    ICist :is the  inventory cost for product i in stage s by the end of period t. its value for i=1 differs than that for i=2 , but for the same i,  ICist  is the same per stage and period.

    ICist, for i=1....> equals to 0.125. and for i=2...> equals to 0.375, so i place it in the data file as shown:

     

    ICist= [[0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125]],
            
           [[0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375]];

    what i did is that i repeated the value for the 24 periods for the six stages for the same product, 

    And when i ran the model it gave that error:

    Data item "0.125" unexpected for "float [ ][stages][periods]".

     

    ANY suggestions, or what i'm doing wrong that created such an error!


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 03:58 AM

    Hi,

    can you attach your .mod And .dat ?

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 04:10 AM

    Originally posted by: khadeejah


    sorry for the stupid question: how can i attach it directly from the workspace!


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 04:15 AM

    Hi,

    simply use "attach a file " with the .mod And .dat that are in the right run configuration.

    Or zip the full directory And then attach.

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 04:32 AM

    Originally posted by: khadeejah


    I thought there' s adirect way of attachment, i copy and pasted them into two word documents, and here they are attached.

    Thanks


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 04:47 AM

    Hi,

    let me address and fix ICist:

    This is a 3D array so you should start with [[[ in the .dat!

    ICist=[

    [[0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125],
            [0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125,0.125]],
     ,       
           [[0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375],
            [0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375,0.375]]
            ];

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 05:12 AM

    Originally posted by: khadeejah


    Thanks alot, 

    Why when i made the following run, i had this error for :

    alphaif= [[3,2.8,0,0],
             [3,2.8,0,0]];

     invalid array size expecting 2!!

     

    however its written for two i (2 products) and 4 columns (4 fabric elements). so why its wrong!!

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 05:18 AM

    Originally posted by: khadeejah


    i removed the second bracket , and then i had this error :

    Data item 3 unexpected for float [fabric][MTo][periods]!


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: How to insert data for a multidimentional array in cplex v12.5?

    Posted 11/27/16 01:13 PM

    Hi,

    alphaif= [[3,2]
             [2.8,2]];

    would work better

    regards


    #CPLEXOptimizers
    #DecisionOptimization