首页 > 解决方案 > 在 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命令的实现——最好的方法是什么。

期待您的帮助,

标签: linear-programmingcplex

解决方案


您无法在阅读时过滤内容,因此您始终必须阅读所有内容。一旦你拥有了一切,你应该能够提取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); }

推荐阅读