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);
}
}
}
}
}
Topic

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