【问题标题】:in OPL Filter and read k for a set of i,j from a tuple having i,j,k在 OPL 过滤器中,从具有 i,j,k 的元组中读取一组 i,j 的 k
【发布时间】: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/…

标签: linear-programming cplex


【解决方案1】:

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

【讨论】:

  • 感谢 Daniel 的快速回复。我已经能够将 jks 和 BenchPerjk 报告为:jks - { } benchPerjk - [{1 3} {1 3} {1 3} {1 3} {1 3} {1 3} {1 2 3} {1 2 3} {1 2 3}]
  • 但是,我最初尝试使用代码 {blockType} OntopPit[b1 in PitBlocksType] = {b | PitBlocksType 中的 b: 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 ) ) }; // 在此我想用 BenchPerjk 中的下一个 i 替换 b.i+1。我需要使用 Next 命令。你能建议吗
  • b.i+1 可以很好地生成 OntopPit,如果我有连续的 i 喜欢所有 i = 1,2,3 存在于所有 j,k 集合。但是,正如您将在某些 j 组的数据中看到的那样,k i 只有 1 和 3,缺少 2 个
  • 我试过 {b | b in PitBlocksType: b1.i == next(BenchPerjk[],b.i) && .........我可以运行它,但出现两行错误“b.i”:下一个() 元素不存在。第 2 行:数组项的初始化表达式无效:OntopPit[].
猜你喜欢
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
  • 1970-01-01
  • 2014-11-25
  • 1970-01-01
  • 1970-01-01
  • 2020-01-10
  • 1970-01-01
相关资源
最近更新 更多