I am working on redesigning of a code in which 6D array are created . This is required for Cplex linear calculation.
Now, there are API's which can support 1D or int variable in cplex also so its not important to have 6 dimension array. Only the mapping is important with the variable which will be required when retrieing it from another method.
Is there any way of replacing 6D array. This will also help in simplying the complexity of the code.
-> can i replace somehow the 6D array and store the variable in 1D array or int variable.. -> I tried HashMap with key as list and value as Integer but eventually it is taking more time because HashMap internally uses Array.
Sample code is:
int [][][][][][] testVariable = new int [2][2][3][5][2][2];
HashMap<List<Integer>, Integer> mapping = new HashMap<List<Integer>, Integer>();
int[] arrayAdd = new int[11111];
for (int a =0; a <= 2; a++) {
for (int l = 0; l < 2; l++) {
for (int y = 0; y < 3; y++) {
for (int r = 0; r < 5; r++) {
for(int oc=0; oc< 2; oc++){
for(int c=0; c< 2; c++){
// usual array of 6D
testVariable[a][l][y][r][oc][c]=count;
// FIRST METHOD ( Takes more time then Array)
LinkedList<Integer> listAdd = new LinkedList<Integer>();
listAdd.add(a);
listAdd.add(l);
listAdd.add(y);
listAdd.add(r);
listAdd.add(oc);
listAdd.add(c);
mapping.put(listAdd, count);
// second method .. this i am still testing but it doesnt make much sense)
arrayAdd[a + l + y + r + oc + c] = count;
// Arrays.fill(arrayAdd, count);
//System.out.println("Value of list is " + listAdd);
count ++;
}
}
}
}
}
}
int a =0; a <= 2; a++
is going to cause an index out of bounds exception. Usea < 2
like the other loops.testVariable
stores 240 total integers; why isarrayAdd
11111 elements long?