【问题标题】:Reading a 3-dimensional array from an Excel (IBM ILOG CPLEX)从 Excel 中读取 3 维数组 (IBM ILOG CPLEX)
【发布时间】:2017-08-09 16:10:53
【问题描述】:

假设我有一个带有两个选项卡的 Excel 工作簿。两个选项卡都包含一个二维矩阵,如

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

如何在 IBM ILOG 的 3 维数组中获取这两个选项卡? IBM 官方支持页面再也找不到主题Reading a 3-dimensional array from an Excel。这是一个死链接。有人可以帮我吗?它应该可以像这样使用arrayExample。不是元组或数组以外的任何东西。

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

【问题讨论】:

  • 该链接刚刚对我有用。也许再试一次,或者使用不同的浏览器,或者在清除缓存之后。

标签: arrays excel cplex ilog


【解决方案1】:

如果您仍然无法访问该链接,以下是该技术说明中的信息:

答案:

使用中间数组(1 或 2 维)来 通过调用指令 SheetRead() 读取所有数据。然后 初始化你的 3 维数组:

模型文件(.mod):

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

// 如果数据元素按列组织

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)];

//如果数据元素在二维数组中

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)];

数据文件(.dat)

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

注意:电子表格和数据库表中的数据通常是 二维。所以3维数组不能存储在 本机电子表格或数据库表。

【讨论】:

    猜你喜欢
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多