Pinned topic 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);
}
}
}
}
}

Re: how to create an array of 5 dimension.
20110527T08:16:43ZThis is the accepted answer. This is the accepted answer.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 6dimensional array here: You have 5 nested loops and in the innermost loop you create an array.
#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. 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 6dimensional array here: You have 5 nested loops and in the innermost loop you create an array.
<pre class="java dw" dataeditorlang="java" datapbcklang="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.Updated on 20140325T01:10:39Z at 20140325T01:10:39Z by ironman 
Re: how to create an array of 5 dimension.
20151006T07:24:51ZThis is the accepted answer. This is the accepted answer. SystemAdmin
 20110527T08: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 6dimensional array here: You have 5 nested loops and in the innermost loop you create an array.
<pre class="java dw" dataeditorlang="java" datapbcklang="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?
Thanks in advance
Roni

Re: how to create an array of 5 dimension.
20151007T17:50:28ZThis is the accepted answer. This is the accepted answer. Roni.Mohammad
 20151006T07:24:51Z
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?
Thanks in advance
Roni
Actually I figured it out. Memory was not allocated across the dimension properly