【问题标题】:If else on the date in CPLEX OPLIf else 在 CPLEX OPL 中的日期
【发布时间】:2021-02-11 07:03:40
【问题描述】:

我想制作,如果总生产任务“i”*第 15 天的持续时间

Tuple Precedence {
  key int id;
  {int}   succs;
  int RelDate;
  int VolCost;
}
{Precedence} Precedences = ...;

tuple Mode {
  key int taskId;
  key int id;
  int pt;
  int costprod;
  int dmdIntRes [IntRes];
  int dmdExtRes [ExtRes];
}
{Mode} Modes = ...;

dvar interval Tasks [p in Precedences]in p.RelDate..EndMax   ; //in p.RelDate..EndMax in 0..EndMax
dvar interval mode[m in Modes] optional  size m.pt;
//dvar boolean m1 [m in Modes];

cumulFunction IntResUsage[r in IntRes] = 
  sum (m in Modes: m.dmdIntRes[r]>0) pulse(mode[m], m.dmdIntRes[r]);
  
cumulFunction ExtResUsage[r in ExtRes] = 
  sum (m in Modes: m.dmdExtRes[r]>0) pulse(mode[m], m.dmdExtRes[r]);
  
execute {
        cp.param.FailLimit = 10000;
}
 
minimize max(p in Precedences) endOf(Tasks[p]);
subject to {
  forall (p in Precedences, m in Modes) {
 
    alternative(Tasks[p], all(m in Modes: m.taskId==p.id) mode[m])

这是我的模式元组数据示例

Modes = {
  < 0, 1, 3,  700000,[ 2 ], [ 0 ]  >,
  < 0, 2, 2, 1060000,[ 2 ], [ 1 ] >,
  < 1, 1,24,   70313,[ 2 ], [ 0 ]  >,
  < 1, 2,20,   80357,[ 2 ], [ 1 ]  >,
  < 2, 1,24,  143750,[ 5 ], [ 0 ]  >,
  < 2, 2,20,  164286,[ 5 ], [ 1 ]  >,
  < 3, 1, 5, 1500000,[ 6 ], [ 0 ]  >,

【问题讨论】:

    标签: optimization scheduling cplex opl construction


    【解决方案1】:

    How to make a if and else in alternative function in OPL?中所说

    你可以依靠存在

    使用您的 .dat

    Modes = {
      < 0, 1, 3,  700000,[ 2 ], [ 0 ]  >,
      < 0, 2, 2, 1060000,[ 2 ], [ 1 ] >,
      < 1, 1,24,   70313,[ 2 ], [ 0 ]  >,
      < 1, 2,20,   80357,[ 2 ], [ 1 ]  >,
      < 2, 1,24,  143750,[ 5 ], [ 0 ]  >,
      < 2, 2,20,  164286,[ 5 ], [ 1 ]  >,
      < 3, 1, 5, 1500000,[ 6 ], [ 0 ]  >,
      };
    

    .mod

    using CP;
    
    int EndMax=100;
    range IntRes=1..1;
    range ExtRes=2..2;
    
    tuple Precedence {
      key int id;
      
    }
    {Precedence} Precedences = {<1>};
    
    tuple Mode {
      key int taskId;
      key int id;
      int pt;
      int costprod;
      int dmdIntRes [IntRes];
      int dmdExtRes [ExtRes];
    }
    {Mode} Modes = ...;
    
    dvar interval Tasks [p in Precedences]in 1..1000; 
    dvar interval mode[m in Modes] optional size m.pt;
    
    
    
     
    minimize max(p in Precedences) endOf(Tasks[p]);
    subject to {
      forall (p in Precedences, m in Modes) {
     
        alternative(Tasks[p], all(m in Modes: m.taskId==p.id) mode[m]);   
    }   
    
    // if then with presenceOf
      forall (p in Precedences)
          (lengthOf(Tasks[p])>=15) == presenceOf(mode[first(Modes)]);
    
    } 
    

    有效并且可以帮助您使用语法

    【讨论】:

      【解决方案2】:

      但我认为它有点理解,第 15 天就像日历一样。例如,如果在第 15 天 = 成本生产 500/天 * 持续时间

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-05
        • 2020-08-20
        相关资源
        最近更新 更多