Search code examples
optimizationconstraintscplexjob-schedulingconstraint-programming

Array issue with endbefore start in CPLEX


I am trying to add an Endbeforestartconstraint to my contrained programming problem. However, I receive an error saying that my end beforestart is not an array type. I do not understand this as I almost copied the constraint and data from the sched_seq example in CPLEX, I only changed it to integers.

What I try to accomplish with the constraint, is that task 3 and task 1 will be performed before task 2 will start.

How I can fix the array error for this constraint?

Please find below the relevant parts of my code

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);

dat.

nbMachines = 2;
nbJobs = 3;


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

release = 1;

due = 30;

Solution

  • There are several errors in your model, on ranges or on inverted indices. Also, next time, please post a complete program showing the problem, not just a partial one, this may help you to get quicker answers. A corrected program:

    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);
      }