Topic
  • 3 replies
  • Latest Post - ‏2014-05-17T20:31:27Z by khadeejah
TracyLLL
TracyLLL
2 Posts

Pinned topic How to initialize a 3D array?

‏2014-02-21T02:24:35Z |
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

  • rdumeur
    rdumeur
    26 Posts
    ACCEPTED ANSWER

    Re: How to initialize a 3D array?

    ‏2014-02-21T16:50:04Z  

    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,

  • rdumeur
    rdumeur
    26 Posts

    Re: How to initialize a 3D array?

    ‏2014-02-21T16:50:04Z  

    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,

  • TracyLLL
    TracyLLL
    2 Posts

    Re: How to initialize a 3D array?

    ‏2014-02-23T04:53:43Z  
    • rdumeur
    • ‏2014-02-21T16:50:04Z

    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

    <pre class="html dw" data-editor-lang="js" data-pbcklang="html" dir="ltr"> [0.0981,0.3415], [0.0781,0.2733], [0.1088,0.3191], [0.0869,0.3222] ], </pre>

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

    I hope this helps.

        Cheers,

    Thank you rdumeur. It worked!

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

  • khadeejah
    khadeejah
    7 Posts

    Re: How to initialize a 3D array?

    ‏2014-05-17T20:31:27Z  

    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?