Topic
• 3 replies
• Latest Post - ‏2015-10-07T17:50:28Z by Roni.Mohammad
7929 Posts

# Pinned topic how to create an array of 5 dimension.

‏2011-05-27T07:48:53Z |
I want to know how to create an array of 5 dimension.
I tried with this solution but it didn't work:
"typedef IloArray<IloBoolVarArray> IloBoolVarArrayArrayArrayArrayArray;
typedef IloArray<IloBoolVarArray> IloBoolVarArrayArrayArrayArray;
typedef IloArray<IloBoolVarArray> IloBoolVarArrayArrayArray;
typedef IloArray<IloBoolVarArray> IloBoolVarArrayArray;
typedef IloArray<IloBoolVarArray> IloBoolVarArray;
.......
IloNumVarArrayArrayArrayArrayArray x(env,nb_tache);
for ( i = 0; i < nb_tache+1 ; i++)
{
x[i] = IloNumVarArrayArrayArrayArrayArray(env, nb_tache);
for ( j = 1; j < nb_avion+1 ; j++)
{
x[i][j] = IloNumVarArrayArrayArrayArray(env, nb_avion);
for ( k = 0; k < nb_tache+1 ; k++)
{
x[i][j][k] = IloNumVarArrayArrayArray(env, nb_tache);
for ( l = 1; l < nb_avion+1 ; l++)
{
x[i][j][k][l] = IloNumVarArrayArray(env, nb_avion);
for ( m = 1; m < nb_vehicule+1 ; m++)
{
x[i][j][k][l][m] = IloNumVarArray(env, nb_vehicule, 0, 1, ILOINT);

}
}
}
}
}
Updated on 2011-05-27T08:16:43Z at 2011-05-27T08:16:43Z by SystemAdmin
7929 Posts

#### Re: how to create an array of 5 dimension.

‏2011-05-27T08:16:43Z
OK, your code has several flaws:
• You are defining types called IloBoolVarArray... but are using types called IloNumVarArray...
• All your IloBoolVarArray... types are the same.
• You are in fact trying to create a 6-dimensional array here: You have 5 nested loops and in the innermost loop you create an array.
I changed your code so that it at least compiles:
```#include <ilcplex/ilocplex.h>

int
main(void)
{
IloEnv env;
int i, j, k, l, m;
int nb_tache = 2, nb_avion = 2, nb_vehicule = 2;
typedef IloArray<IloNumVarArray> IloNumVarArrayArray;
typedef IloArray<IloNumVarArrayArray> IloNumVarArrayArrayArray;
typedef IloArray<IloNumVarArrayArrayArray> IloNumVarArrayArrayArrayArray;
typedef IloArray<IloNumVarArrayArrayArrayArray> IloNumVarArrayArrayArrayArrayArray;
typedef IloArray<IloNumVarArrayArrayArrayArrayArray> IloNumVarArrayArrayArrayArrayArrayArray;

IloNumVarArrayArrayArrayArrayArrayArray x(env,nb_tache);

for ( i = 0; i < nb_tache+1 ; i++)
{
x[i] = IloNumVarArrayArrayArrayArrayArray(env, nb_tache);
for ( j = 1; j < nb_avion+1 ; j++)
{
x[i][j] = IloNumVarArrayArrayArrayArray(env, nb_avion);
for ( k = 0; k < nb_tache+1 ; k++)
{
x[i][j][k] = IloNumVarArrayArrayArray(env, nb_tache);
for ( l = 1; l < nb_avion+1 ; l++)
{
x[i][j][k][l]  = IloNumVarArrayArray(env, nb_avion);
for ( m = 1; m < nb_vehicule+1 ; m++)
{
x[i][j][k][l][m] = IloNumVarArray(env, nb_vehicule, 0, 1, ILOINT);

}
}
}
}
}

return 0;
}
```

It is up to you to decide whether you want 5 or 6 dimensions.

Depending on how familiar you are with C++ and templates it may be an option to use recursive templates instead of the typedefs you are doing. I explained that here.

Be careful: You are creating dense arrays here. This may result in large memory requirements. You may want to consider using a sparse implementation (which can also be done nicely by recursive templates, I think) that does not allocate space for variables that will not be used in the model.
Updated on 2014-03-25T01:10:39Z at 2014-03-25T01:10:39Z by iron-man
21 Posts

#### Re: how to create an array of 5 dimension.

‏2015-10-06T07:24:51Z
OK, your code has several flaws:
• You are defining types called IloBoolVarArray... but are using types called IloNumVarArray...
• All your IloBoolVarArray... types are the same.
• You are in fact trying to create a 6-dimensional array here: You have 5 nested loops and in the innermost loop you create an array.
I changed your code so that it at least compiles:
<pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">#include <ilcplex/ilocplex.h> int main(void) { IloEnv env; int i, j, k, l, m; int nb_tache = 2, nb_avion = 2, nb_vehicule = 2; typedef IloArray<IloNumVarArray> IloNumVarArrayArray; typedef IloArray<IloNumVarArrayArray> IloNumVarArrayArrayArray; typedef IloArray<IloNumVarArrayArrayArray> IloNumVarArrayArrayArrayArray; typedef IloArray<IloNumVarArrayArrayArrayArray> IloNumVarArrayArrayArrayArrayArray; typedef IloArray<IloNumVarArrayArrayArrayArrayArray> IloNumVarArrayArrayArrayArrayArrayArray; IloNumVarArrayArrayArrayArrayArrayArray x(env,nb_tache); for ( i = 0; i < nb_tache+1 ; i++) { x[i] = IloNumVarArrayArrayArrayArrayArray(env, nb_tache); for ( j = 1; j < nb_avion+1 ; j++) { x[i][j] = IloNumVarArrayArrayArrayArray(env, nb_avion); for ( k = 0; k < nb_tache+1 ; k++) { x[i][j][k] = IloNumVarArrayArrayArray(env, nb_tache); for ( l = 1; l < nb_avion+1 ; l++) { x[i][j][k][l] = IloNumVarArrayArray(env, nb_avion); for ( m = 1; m < nb_vehicule+1 ; m++) { x[i][j][k][l][m] = IloNumVarArray(env, nb_vehicule, 0, 1, ILOINT); } } } } } return 0; } </pre>
It is up to you to decide whether you want 5 or 6 dimensions.

Depending on how familiar you are with C++ and templates it may be an option to use recursive templates instead of the typedefs you are doing. I explained that here.

Be careful: You are creating dense arrays here. This may result in large memory requirements. You may want to consider using a sparse implementation (which can also be done nicely by recursive templates, I think) that does not allocate space for variables that will not be used in the model.

Hi,

Is this code obsolete? I was trying to run it but it does not run. It shows some memory problem. When I was debugging, it shows following error  "Unhandled exception at 0x00007FF7F065163C in Test2.exe: 0xC0000005: Access violation writing location 0x0000000000000000."

Actually, I am having trouble to create a five dimensional array based on above example. I am having problem even though I want to create 5x5x5x5x2 size array. I am using cplex 1262 with visual studio 2013. Any idea?

Roni

21 Posts

#### Re: how to create an array of 5 dimension.

‏2015-10-07T17:50:28Z

Hi,

Is this code obsolete? I was trying to run it but it does not run. It shows some memory problem. When I was debugging, it shows following error  "Unhandled exception at 0x00007FF7F065163C in Test2.exe: 0xC0000005: Access violation writing location 0x0000000000000000."

Actually, I am having trouble to create a five dimensional array based on above example. I am having problem even though I want to create 5x5x5x5x2 size array. I am using cplex 1262 with visual studio 2013. Any idea?