CPLEX 中 endbefore start 的数组问题

Array issue with endbefore start in CPLEX

我正在尝试将 Endbeforestartconstraint 添加到我的约束编程问题中。但是,我收到一条错误消息,指出我的 end beforestart 不是数组类型。我不明白这一点,因为我几乎从 CPLEX 的 sched_seq 示例中复制了约束和数据,我只是将其更改为整数。

我尝试通过约束完成的是任务 3 和任务 1 将在任务 2 开始之前执行。

如何修复此约束的数组错误?

请在下面找到我的代码的相关部分

tuple Precedence {int pre;int post;};

{Precedence} Precedences = {<3,2>,<1,2>};

dvar interval task[j in Jobs] in release..due;
dvar interval opttask[j in Jobs][m in Machines] optional size duration[j][m];

dvar sequence tool[m in Machines] in all(j in Jobs) opttask[j][m]
dexpr int makespan = max(j in Jobs, m in Machines)(endOf(opttask[j][m]));
minimize makespan;
 
subject to {
  // Each job needs one unary resource of the alternative set s (28)
  forall(j in Jobs){
    alternative(task[j], all(m in Machines) opttask[j][m]);
     
    }     
  // No overlap on machines
  forall(j in Jobs)
    forall(p in Precedences)
    endBeforeStart(opttask[j][p.pre],opttask[j][p.post]);
   
   forall(m in Machines){
     noOverlap(tool[m],transitionTimes);
       }     
    
};

execute {
  writeln(task);

数据

nbMachines = 2;
nbJobs = 3;


duration = [
        [5,6], 
        [4,4],
        [5,8]
            ];

release = 1;

due = 30;

p.pre 或 p.post 中的值必须超出数组索引范围。

您的模型、范围或倒排索引存在多个错误。 另外,下次请 post 一个完整的程序来显示问题,而不仅仅是部分程序,这可能会帮助您更快地得到答案。 更正的程序:

using CP;

int nbMachines = 2;
int nbJobs = 3;


range Machines = 0..nbMachines-1;
range Jobs = 0..nbJobs-1;

int duration[Jobs][Machines] = [
        [5,6], 
        [4,4],
        [5,8]
            ];

            
int release = 1;
int due = 30;

tuple Precedence {int pre;int post;};

{Precedence} Precedences = {<2,1>,<0,1>};

dvar interval task[j in Jobs] in release..due;
dvar interval opttask[j in Jobs][m in Machines] optional size duration[j][m];

dvar sequence tool[m in Machines] in all(j in Jobs) opttask[j][m];

dexpr int makespan = max(j in Jobs, m in Machines)(endOf(opttask[j][m]));
minimize makespan;
 
subject to {
  // Each job needs one unary resource of the alternative set s (28)
  forall(j in Jobs){
    alternative(task[j], all(m in Machines) opttask[j][m]);
     
    }     
  // No overlap on machines
  forall(m in Machines)
    forall(p in Precedences)
    endBeforeStart(opttask[p.pre][m],opttask[p.post][m]);
};

execute {
  writeln(task);
  }