Felix Grossmann
Felix Grossmann

Reputation: 1314

Reading a 3-dimensional array from an Excel (IBM ILOG CPLEX)

Let's say I have an excel workbook with two tabs. Both tabs contain a 2-dimensional matrix like

# 1st tab       # 2nd tab
1 1 1           1 1 1
1 1 1           1 1 1
1 1 1           1 1 1

How can I get those two tabs in a 3-dimensional array in IBM ILOG? The official IBM support page cannot find the topic Reading a 3-dimensional array from an Excel anymore. This is a dead link. May anyone help me with this? It should be usable like this arrayExample. Not a tuple or anything else than an array.

int arrayExample[i][j][s] = [[[1,1,1], [1,1,1], [1,1,1]], [[1,1,1], [1,1,1], [1,1,1]]];

Upvotes: 1

Views: 1986

Answers (1)

rkersh
rkersh

Reputation: 4465

In case you still can't access that link, here is the information from that technote:

Answer:

Use an intermediate array (1 or 2 dimensions) to read all the data, by calling the instruction SheetRead(). Then initialize your 3-dimensional array:

The model file (.mod):

int nbMonths = ...;
int nbProducts = ...;
int nbLevels = ...;

// If the data elements are organized in columns

int nb1[1..nbMonths*nbProducts*nbLevels] = ...;
int nbArray[m in 1..nbMonths, p in 1..nbProducts,s in1..nbLevels]= nb1[s+nbLevels*(p-1)+nbProducts*nbLevels*(m-1)];

// If the data elements are in a 2-dimensional array

int nb2[1..nbMonths, 1..nbProducts*nbLevels] = ...;
int nbArray2[m in 1..nbMonths, p in 1..nbProducts,s in 1..nbLevels] =  nb2[m,s+nbLevels*(p-1)];

The data file (.dat)

SheetConnection sheetInput("3DimArray.xls", 0);
nb1 from SheetRead(sheetInput,"data!D2:D13");
nb2 from SheetRead(sheetInput,"data!B17:G18");

Note: Data in spreadsheets and database tables are usually 2-dimensional. So 3-dimensional arrays cannot be stored in spreadsheets or database tables natively.

Upvotes: 1

Related Questions