cplex - 如何在具有可变列长度的 Cplex 中进行 SheetRead?
问题描述
在我的 .dat 文件中,我想用 Excel 工作表中的列值填充数组。根据问题,值的数量不同,这意味着可能有来自 A1:A10 或来自 A1:A20 的值。该数字在另一个 Excel 单元格中指定,也用作模型中的变量,因此也可以读取。我现在如何以正确的大小读取数组?也许字符串连接会起作用。我搜索类似:
numberRows from SheetRead(DataSource, "Data!B1");
input = "Data!A1:A" + numberRows;
variable from SheetRead(DataSource, input);
在 CPLEX 中是否有类似的可能?
解决方案
OPL EXCEL中的示例:https ://github.com/AlexFleischerParis/oplexcel/blob/main/mainvariablesheetreadstring.mod
主要思想是依靠 main 来更新将在 SheetRead 中使用的字符串。
main
{
var source = new IloOplModelSource("variablesheetreadstring.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
var opl = new IloOplModel(def,cplex);
var data1=new IloOplDataElements();
data1.paramread="params!A2";
data1.parambuses="buses!A2:B3";
data1.paramwrite="buses!E2:F3";
opl.addDataSource(data1);
var data2 = new IloOplDataSource("variablesheetreadstring.dat");
opl.addDataSource(data2);
opl.generate();
if (cplex.solve()) {
writeln("OBJ = " + cplex.getObjValue());
opl.postProcess();
} else {
writeln("No solution");
}
opl.end();
}
或者您可能会依赖一个不那么微妙的想法:读取所有单元格然后解析。
推荐阅读
- git - 为什么 git 会与我自己在同一分支的提交产生冲突?
- powershell - 无法使用 powershell 执行 Jenkins 作业
- database - 如何使用 Heroku 运行 pg_dumpall?
- python - ffmpeg 创建的 mp4 无法与 IPython.display.Video 一起播放
- jasper-reports - 如何在子数据集中将一个字段引用到另一个字段?
- r - 使用 R 从数据帧和过滤结果进行连续正或负计算
- r - 在条形图顶部添加频率
- html - 如何修复滚动时消失的 div?
- javascript - 如何使用 Rails 路由从 React 前端重定向?
- c - 使用 fscanf 后什么都没有读取