0

How can I read 1 dim data from excel into 3 dim data in ILOG CPLEX?

I can already read 3 dim data from excel into ILOG by using the workaround with a 2 dim array.

But how can I read Excel data like 3;4;5;6;7 into 3 dim ILOG format like

x = #[

   1: #[

      1: [3]

      2: [4]

      3: [5]

      4: [6]

      5: [7]

      ]#

   ]#;
Tom
  • 2,734
  • 2
  • 22
  • 39

1 Answers1

0

You can first read everything into a flat array and then fill a 3-dimensional array from this flat data. Like so:

range I = 0..1;
range J = 0..2;
range K = 0..3;

int flat[0..card(I) * card(J) * card(K)-1] = [
                1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
               11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
               21, 22, 23, 24 ];

int dim3[i in I][j in J][k in K] = flat[i * card(J) * card(K) +
                                        j * card(K) +
                                        k];

execute { writeln(dim3); }

This prints

 [[[1 2 3 4]
             [5 6 7 8]
             [9 10 11 12]]
         [[13 14 15 16]
             [17 18 19 20]
             [21 22 23 24]]]
Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22