在OPL模型中跳过表中的缺失数据 [英] Skip Missing data from table in OPL model
问题描述
我有一个模型,可以从excel文件中读取数据。以下是模型的一部分。
I have a model reading data from an excel file. Below is part of the model.
我使用下面的代码读取数据,如下所示
I use the below code to read data as below
tuple blockType {
string id;
int i;
int j;
int k;
};
{blockType} PitBlocksType = ...;
从excel中读取数据的快照是
A snap shot of the data being read from excel is
Block Id Bench(i) Strip(j) Block(k)
P52 1 5 3
P135 2 5 3
P210 3 5 3
P374 8 5 3
P487 9 5 3
以上是在j = 5和k = 3。因此,块ID被视为连续的。 Bench或i在数据中从1到9不等。 i,j,k表示类似3D空间中的数据,其中i是垂直轴或z轴,j和k表示x和y方向。正如您在上面的序列中看到的那样,i出现1-3并从4-7丢失,然后再次出现8和9而不是全部出现1到9。这给我带来了问题。
The above is a selection of data filtered in excel for j=5 and k=3. Hence the Block Id is seen an contiguous. The Bench or i varies from 1 to 9 in the data. i, j, k represent data like in a 3D space where i is the vertical axis or z axis, and j and k represent in the x and y direction. As you can see in the sequence above i is present for 1-3 and missing from 4-7, then again present for 8 and 9 instead of being present for all 1 to 9..this is creating me problem.
我正在模型中运行一段代码,假定我是连续的,因此对于上述数据,我的模型失败。我希望我的模型也能够处理此类数据。我试图查看for-下一个循环对您有帮助。.但是我不这么认为。
I am running a piece of code in my model which assumes that i is continuous and hence my model fails for this above data. I want my model to be able to tackle this type of data as well. I was trying to see would a for - next loop be of help here..but I don't think so. What is the best way to handle this.
{blockType} OntopPit[b1 in PitBlocksType] =
{b | b in PitBlocksType: b1.i == b.i +1 &&
((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 ) ) };
在模型的上面部分中,我使用b1.i == bi +1查找所有i值,但是有时bi +1不在数据中-如我们在上面的快照中所见。
In the above part of the model I am using the b1.i == b.i +1 finds all i value, but sometimes the b.i +1 is not present in the data - as we saw in the above snapshot.
当某个i丢失时,我希望代码考虑下一个i,例如4如果缺少5,则查找6,依此类推。我无法在模型中创建它。
When a certain i is missing I want the code to consider the next i, say 4 is missing then look for 5, if 5 is also missing look for 6 and so on. I am not able to create this in the model.
请提出您的建议。
推荐答案
而不是+1,您可以在集合中使用下一个:
Instead of +1 you could use next in a set:
tuple jk
{
int j;
int k;
}
{jk} jks={<5,3>};
{int} BenchPerjk[jks]=[{1,2,3,8,9}];
int succ3=next(BenchPerjk[<5,3>],3);
execute
{
writeln(succ3);
}
给予
8
这篇关于在OPL模型中跳过表中的缺失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!