【发布时间】:2020-09-16 04:03:27
【问题描述】:
我有一个模型从 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命令的实现——最好的方法是什么。
期待您的帮助,
【问题讨论】:
-
我发布了第一部分的答案,但我不清楚
next()函数在你的情况下应该为块b产生什么。你能详细说明一下吗? -
谢谢丹尼尔,它很有帮助。我在您的回答下方发表了评论
-
更多细节也可以在问题stackoverflow.com/questions/62989416/…