【问题标题】:OPL CPLEX If statement usage with booleanOPL CPLEX If 语句与布尔值一起使用
【发布时间】:2021-06-25 09:28:15
【问题描述】:

我是 CPLEX OPL 的初学者。这是我的一段代码:

forall(e in employee, d in day:1<=d<=19, t in task, p in period)
(x[e][d][p][t]==0)=>(x[e][d+7][p][t]+x[e][d+8][p][t]+x[e][d+9][p][t]==2);

其中x[e][d][p][t] 是一个布尔决策变量。这是代码的一小部分。这样的结构写代码行吗?

如果您能帮助我,我将不胜感激。

【问题讨论】:

    标签: if-statement boolean cplex opl


    【解决方案1】:

    只要你确定 d+7 在天数内,就可以了。

    例如:

    range day =1..20;
    range task=1..3;
    range period=1..20;
    range employee=1..10;
    
    
    dvar boolean x[employee][day][period][task];
    subject to
    {
    
    forall(e in employee, d in day:1<=d<=19, t in task, p in period:(d+9) in day) 
    
    (x[e][d][p][t]==0)=>(x[e][d+7][p][t]+x[e][d+8][p][t]+x[e][d+9][p][t]==2);
    
    }
    

    工作正常

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 1970-01-01
      • 2018-04-17
      • 2012-02-09
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      相关资源
      最近更新 更多