Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

How to initialize a 3D array?

  • 1.  How to initialize a 3D array?

    Posted Thu February 20, 2014 09:25 PM

    Originally posted by: TracyLLL


    Hi There~
     
    I am new to CPLEX studio and have a 3D array, say VtS[1..4][1..2][1..3], which I initialize as follows:
     
    VtS=[
    [ [0.0981,0.3415], 
      [0.0781,0.2733], 
      [0.1088,0.3191], 
      [0.0869,0.3222] ],
    [ [0.0981,0.3415], 
      [0.0688,0.2391], 
      [0.1088,0.1088], 
      [0.0762,0.1128] ],
    [ [0.0981,0.3415], 
      [0.0781,0.2733], 
      [0.1088,0.3191], 
      [0.0869,0.3222] ]
    ];
     
    But I kept getting the following error and warnings:
     
    error info:
    "Exception from IBM ILOG Concert: IloIntRangeI::getValue(IloInt index): index is out of bound."
     
    Warnings:
    Array "VtS[1][1]" partially initialized, expecting 3 items, found 2.
    Array "VtS[1][2]" partially initialized, expecting 3 items, found 2.
     
    According to the Langurage Reference Manual pp40:
     
    /* .mod file */
    int a[1..2][1..3] = ...;
    /* .dat file */
    a = [
    [10, 20, 30],
    [40, 50, 60]
    ];
    initializes a two-dimensional array by giving initializations for the one-dimensional arrays
    of its first dimension.
     
    I am not sure if I understand the last sentence correctly: the 1st dimension is for row, 2nd for colume,
    and so on.
     
    I know one solution is to reduce the dimension to 2D and initialize them separatly, but it's kinda
    cumbersome for my modeling. 
     
    Any input is appreciated. Thanks a lot!
     

    Tracy


    #ConstraintProgramming-General
    #DecisionOptimization


  • 2.  Re: How to initialize a 3D array?

    Posted Fri February 21, 2014 11:50 AM

    Originally posted by: rdumeur


    Hi,

    Please check the range of each dimension of your array.

    Your first dimension is 1..4 but you give only 3 items.

    Your second dimension is 1..2 but you give 4 items such as

     [0.0981,0.3415], 
      [0.0781,0.2733], 
      [0.1088,0.3191], 
      [0.0869,0.3222] ],
    

    The third dimension is 1..3 but you only give couples such as : [0.0981,0.3415],

    I hope this helps.

        Cheers,


    #ConstraintProgramming-General
    #DecisionOptimization


  • 3.  Re: How to initialize a 3D array?

    Posted Sat February 22, 2014 11:54 PM

    Originally posted by: TracyLLL


    Thank you rdumeur. It worked!

    Now I know that the sequence of dimension is from most outside to most inside.


    #ConstraintProgramming-General
    #DecisionOptimization


  • 4.  Re: How to initialize a 3D array?

    Posted Sat May 17, 2014 04:31 PM

    Originally posted by: khadeejah


    i didnt get how the sequence is working, for example, if i have X [a] [b][c], and  a[10, 20, 30, 40, 50] , b[ 2, 4], c [5,7];

    how can i write it in data file in CPLex OPl?

     


    #ConstraintProgramming-General
    #DecisionOptimization