简体   繁体   English

如何在 cplex 上以更紧凑的方式编写此代码?

[英]how can I write this code in a more compact way on cplex?

How can I write this code in a more compact way on CPLEX?如何在 CPLEX 上以更紧凑的方式编写此代码?

forall (j in J)
    

    forall (i in I1)
      
      {
      
      if ( macc [i][j] == 1 || 2 || 4 || 5 || 7 || 11 || 12 ||  13 || 14 || 15 || 16 || 17 || 18 || 19) {
        
        y[i][j][m] == 1;
        
              }
         else {
           
           if (macc [i][j] == 3) {
             
             y[i][j][3] == 1 || y[i][j][4] == 1;
            
           }
    }            

you can use "in" with data in an if condition:您可以在 if 条件下对数据使用“in”:

{int} s={1,2,4,5,7,11,12,13,14,15,16,17,18,19};
int m=2;
dvar int x;

subject to

{
  if (m in s) x==2;
  
}

works fine工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 Cplex 中的“无解决方案”错误 - How can I fix "No solution" error in Cplex 如何使我的程序更有效和紧凑地找到阵列中第N个最常见的元素? - How can I make my procedure for finding the Nth most frequent element in an array more efficient and compact? 我怎样才能更有效地编写这个算法? 以降低时间复杂度的方式? - how can i write this algorithm more efficiently ? in a way that reduce time complexity? 如何更有效地编写这种组合算法? - How can I write this combinatorics algorithm more efficiently? 如何让这段代码找到一个更有效的和? - How can I make this code to find a pair with a sum more efficient? 如何使此代码更高效? Java算法 - How can I make this code more efficient? Java algorithm 我如何为两个未排序的 arrays 代码编写此代码? - How can i write this for two unsorted arrays code? 我想知道这是否是一种很好的编程习惯,否则我如何才能更好,更高效地编写程序 - I want to know if this is a good programming practise else how can i write the program more optimal and efficient 如何向 CPLEX 循环添加约束? - How do I add a constraint to the CPLEX loop for? 有没有更优雅的方式来写这种情况? - is there more elegant way to write this condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM