在OPL中查找下一组编号 [英] Find next number for sets in OPL

查看:132
本文介绍了在OPL中查找下一组编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2套如下

jks - {<1 1> <1 2> <1 3> <2 1> <2 2> <2 3> <3 1> <3 2> <3 3>} 
benchPerjk - [{1 3} {1 3} {1 3} {1 3} {1 3} {1 3} {1 2 3} {1 2 3} {1 2 3}] 

我现在想在BenchPerjk中查找某个jks的下一个数字

I now want to find the next number in the benchPerjk for a certain jks

代码如下

tuple jk {
  int j;
  int k;
}

{jk} jks = { <t.j, t.k> | t in PitBlocksType };

{int} BenchPerjk[v in jks] = { t.i | t in PitBlocksType : t.j == v.j && t.k == v.k };




其中PitBlocksType来自以下数据:


Where the PitBlocksType come from the following data :

 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    (i)       (j)      (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    
    */




我之所以这样做,是因为我想使用BenchPerjk查找下一个i。用于在下面的代码中代替b.i + 1


The reason why I am lookng for this is I want to use the BenchPerjk to find the next i. for using in the code below in place of the b.i+1

如果i是连续的并且所有j存在于所有i中,则b.i + 1可以很好地工作, k。这意味着Benchperjk是否会

The b.i+1 works well if the i is continuous and all i is present for any set of j,k. Which means if Benchperjk would be

benchPerjk-[{1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3}]

benchPerjk - [{1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3} {1 2 3}]

但这不是我的数据。

{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 )  ) };

建议。

我尝试了以下代码,但是它附带了错误:

I have tried the following code but it comes up with errors :

{blockType} OntopPit[b1 in PitBlocksType] =
      {b | b in PitBlocksType: b1.i == next(BenchPerjk[< b.j , b.k>],b.i) &&
                        ((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 )  ) };

,但出现了两行错误
b.i :next()元素不存在。
数组项的无效初始化表达式:OntopPit [< P1,1,1,1>]

but came up with 2 lines of error "b.i" : next() element does not exist. Invalid initialization expression for array item: OntopPit[<"P1",1,1,1>]

推荐答案

您可以使用下一个:

tuple jk {
  int j;
  int k;
}

{jk} jks = {<1 ,1> ,<1 ,2>, <1 ,3>, <2, 1> ,<2 ,2> ,<2, 3>, <3, 1> ,<3, 2>, <3, 3>};

{int} BenchPerjk[jks] = [{1 ,3}, {1, 3}, {1, 3} ,{1 ,3}, {1, 3}, {1, 3}, {1 ,2 ,3} ,{1 ,2, 3} ,{1 ,2, 3}];

// Now suppose you want to get the next after 1 for <j,k> = <2,1>

int res=next(BenchPerjk[<2,1>],1);

execute
{
  writeln(res);
}

提供3

后来需要一些通用的东西:

Something more generic was later required:

tuple jk {
  int j;
  int k;
}

{jk} jks = {<1 ,1> ,<1 ,2>, <1 ,3>, <2, 1> ,<2 ,2> ,<2, 3>, <3, 1> ,<3, 2>, <3, 3>};

{int} BenchPerjk[jks] = [{1 ,3}, {1, 3}, {1, 3} ,{1 ,3}, {1, 3}, {1, 3}, {1 ,2 ,3} ,{1 ,2, 3} ,{1 ,2, 3}];

// Now suppose you want to get the next after 1 for <j,k> = <2,1>

int res=next(BenchPerjk[<2,1>],1);

execute
{
  writeln(res);
}

// And now as a generic function

{int} benches=union (jk in jks) BenchPerjk[jk];

int nextone[jk in jks][i in benches]=(i in BenchPerjk[jk])?((i!=last(BenchPerjk[jk]))?next(BenchPerjk[jk],i):-2):-1;



int res2=nextone[<2,1>][1];

execute
{
  writeln(res2);
}

给予

3
3

3 3

这篇关于在OPL中查找下一组编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆