linear-programming - 在 OPL 过滤器中,从具有 i,j,k 的元组中读取一组 i,j 的 k
问题描述
我有一个模型从 excel 文件中读取数据。下面是模型的一部分。
我使用下面的代码读取数据如下
tuple blockType {
string id;
int i;
int j;
int k;
};
{blockType} PitBlocksType = ...; // Read from excel table which contains several rows, a short example below
/*
Example below
Block Id Bench(i) Strip(j) Block(k)
P1 1 1 1
P2 1 1 2
P3 1 1 3
P7 3 1 1
P8 3 1 2
P9 3 1 3
P10 1 2 1
P11 1 2 2
P12 1 2 3
P16 3 2 1
P17 3 2 2
P18 3 2 3
P19 1 3 1
P20 1 3 2
P21 1 3 3
P22 2 3 1
P23 2 3 2
P24 2 3 3
P25 3 3 1
P26 3 3 2
P27 3 3 3
*/
tuple jk {
string ids;
int j;
int k;
}
{jk} jks=...; // from the above table reading only the j,k : There are multiple occurrences of the same j,k - Not sure if this is the best method
{int} BenchPerjk[jks]= ?????? ; // Here I want to read all i for each set of jks
//int succ3=next(BenchPerjk[<id, 5,3>],3); // I want to use something like this below
{blockType} OntopPit[b1 in PitBlocksType] =
{b | b in PitBlocksType: b1.i == next(BenchPerjk[b.id, b.j ,b.k],b.i) && // This is giving an error
((b1.k == b.k-1 ) ||
(b1.k == b.k+1 ) ||
(b1.k == b.k ) ) &&
((b1.j == b.j-1 ) ||
(b1.j == b.j+1 ) ||
(b1.j == b.j ) ) };
上面有 2 个问题 - 一个是如何通过从表中过滤每组 jk 的数据来读取 BenchPerjk[jks]。
第二个问题是代码中Next命令的实现——最好的方法是什么。
期待您的帮助,
解决方案
您无法在阅读时过滤内容,因此您始终必须阅读所有内容。一旦你拥有了一切,你应该能够提取jks
如下:
tuple jk {
int j;
int k;
}
{jk} jks = { <t.j, t.k> | t in PitBlocksType };
execute { writeln(jks); }
{int} BenchPerjk[v in jks] = { t.i | t in PitBlocksType : t.j == v.j && t.k == v.k };
execute { writeln(BenchPerjk); }
推荐阅读
- javascript - 什么时候应该处理 express 错误
- android - 活动开启两次
- vba - VBA(?)如何提取链接和插入的图像的文件名 - Word 2013
- webpack - Webpack4 不会对我的页面条目执行主模块
- hibernate - 带有 JPA 的 WildFly 时区
- asp.net - 如何对对象的属性进行排序并填充到 ArrayList
- c++ - 在源代码中添加 Visual Leak Detector 的 vld.h 头文件用于内存泄漏
- odoo - 如何在odoo 9中使many2many字段可排序?
- git - Visual Studio 2017 中的 Cordova 应用程序
- python - 突然的模块导入问题