constraint-programming

Constraint programming


I try to code my scheduling problem in IBM CPLEX ILOG. Here I get an error

The function noOverlap does not exist according to picture

Can you help me with this?

fo

int N=...; 
int M=...; 
int R=...; 
// Data Structures
range Jobs = 0..N; // Including dummy job 0
range Machines = 1..M;
range Resources = 1..R;

// Parameters (to be defined based on your data)
int processingTime[Jobs][Machines] = ...;
int readyTime[Jobs] = ...;
int setupTime[Jobs][Jobs][Machines] = ...;
i
// Decision Variables
dvar interval Xim[Jobs][Machines] optional size processingTime[N][M]; // Optional interval for each job on each machine
dvar interval Zi[Jobs] size processingTime[N][M]; // Interval for each job i
dvar sequence seqMachines[Machines] in all(i in Jobs, j in Machines : machineEligibility[i][j] == 1) Xim[i][j]; // Sequence of jobs on each machine

// Decision Expressions
dexpr int Cmax = max(i in Jobs) endOf(Zi[i]);

// Objective
minimize Cmax;

// Constraints
subject to {
 
  forall(p in precedenceConstraints)
    endBeforeStart(Zi[p.pred], Zi[p.succ]);

  // Constraint (9): Job start times
  forall(i in Jobs, j in Machines : machineEligibility[i][j] == 1)
    startOf(Xim[i][j]) >= readyTime[i] + typeOfPrev(seqMachines[j], Xim[i][j], 0, 0, setupTime[typeOfPrev(seqMachines[j], Xim[i][j], 0, 0)][i][j]);

  // Constraint (10): Cumulative resource constraint
  forall(v in Resources)
    cumulative(Zi, resourceNeed[Jobs][v], resourceAvail[v]);

// Constraint (11): Machine usage constraint
forall(m in Machines)
  cumulative(all(i in Jobs : machineEligibility[i][m] == 1) pulse(Xim[i][m], 1), 1);


  // Constraint (12): Earliest start time of a job
  // Constraint (12): Earliest start time of a job based on precedence
// Constraint (12): Earliest start time of a job based on precedence
forall(i in Jobs)
    startOf(Zi[i]) >= max(p in precedenceConstraints: p.succ == i) endOf(Zi[p.pred]);


  // Constraint (13): Cmax greater than or equal to lower bound
  Cmax >= LB;
}

// Execute and print results
execute {
  cp.startNewSearch();
  while (cp.next()) {
    writeln("Solution:");
    for(var i in Jobs) {
      if (cp.isPresent(Zi[i]))
        writeln("Job ", i, ": Start = ", cp.startOf(Zi[i]), ", End = ", cp.endOf(Zi[i]));
    }
  }
  cp.endSearch();
}


// Ready times for each job readyTime = [0, 1, 2];

// Setup times required for switching from job i to job j on each machine setupTime = [ [[0, 0, 0], [0, 1, 2], [0, 1, 1]], // From job 0 to others on machines 1 and 2 [[0, 0, 0], [0, 1, 2], [0, 1, 1]], // From job 1 to others on machines 1 and 2 [[0, 0, 0], [0, 1, 2], [0, 1, 1]] // From job 2 to others on machines 1 and 2 ];

// Resource needs for each job resourceNeed = [ [0], // Job 0 (dummy) [2], // Job 1 [1] // Job 2 ];

// Availability of each resource type resourceAvail = [3]; // Total available units of the resource

// Machine eligibility matrix (1 if eligible, 0 otherwise) machineEligibility = [ [1, 1], // Job 0 (dummy job) eligible on all machines [1, 0], // Job 1 eligible on machine 1 [0, 1] // Job 2 eligible on machine 2 ];

// Precedence constraints (assuming no specific precedence in this example) precedenceConstraints = {<1, 2>};

// Lower bound for Cmax (Example value) LB = 5;


Solution

  • The following works:

    .mod

    using CP;
    int N=...; 
    int M=...; 
    int R=...; 
    // Data Structures
    range Jobs = 0..N; // Including dummy job 0
    range Machines = 0..M;
    range Resources = 1..R;
    
    // Parameters (to be defined based on your data)
    int processingTime[Jobs][Machines] = ...;
    int readyTime[Jobs] = ...;
    int setupTime [Jobs][Jobs][Machines]= ...;
    int resourceNeed[Jobs][Resources] = ...;
    int resourceAvail[Resources] =...;
    int machineEligibility[Jobs][Machines] = ...; // 1 if eligible, 0 otherwise
    int LB = ...; // Lower bound for Cmax
    tuple Precedence {int pred; int succ;}
    setof(Precedence) precedenceConstraints = ...; // Define precedence constraints
    
    // Decision Variables
    dvar interval Xim[Jobs][Machines] optional size processingTime[N][M]; // Optional interval for each job on each machine
    dvar interval Zi[Jobs] size processingTime[N][M]; // Interval for each job i
    dvar sequence seqMachines[Machines] in all(i in Jobs, j in Machines : machineEligibility[i][j] == 1) Xim[i][j]; // Sequence of jobs on each machine
    
    // Decision Expressions
    dexpr int Cmax = max(i in Jobs) endOf(Zi[i]);
    
    // Objective
    minimize Cmax;
    
    // Constraints
    subject to {
      // Constraint (3): Each job is assigned to exactly one eligible machine
      forall(i in Jobs)
        alternative(Zi[i], all(j in Machines : machineEligibility[i][j] == 1) Xim[i][j]);
    
      // Constraint (4): Presence of dummy job
      forall(j in Machines)
        presenceOf(Xim[0][j]);
    
      // Constraint (6): Dummy job is the first job
    //  forall(j in Machines)
    //    first(seqMachines[j], Xim[0][j]);
    
      // Constraint (7): No overlap and setup times
      forall(j in Machines)
        noOverlap(seqMachines[j]);
    
      // Constraint (8): Precedence relations
      forall(p in precedenceConstraints)
        endBeforeStart(Zi[p.pred], Zi[p.succ]);
    
      // Constraint (9): Job start times
      forall(i in Jobs, j in Machines : machineEligibility[i][j] == 1)
        startOf(Xim[i][j]) >= readyTime[i] + typeOfPrev(seqMachines[j], Xim[i][j], 0, 0)+ setupTime[typeOfPrev(seqMachines[j], Xim[i][j], 0, 0)][i][j];
    
    //  // Constraint (10): Cumulative resource constraint
    //  forall(v in Resources)
    //    cumulative(Zi, resourceNeed[0][v], resourceAvail[v]);
    //
    //// Constraint (11): Machine usage constraint
    //forall(m in Machines)
    //  cumulative(all(i in Jobs : machineEligibility[i][m] == 1) pulse(Xim[i][m], 1), 1);
    
    
      // Constraint (12): Earliest start time of a job
      // Constraint (12): Earliest start time of a job based on precedence
    // Constraint (12): Earliest start time of a job based on precedence
    forall(i in Jobs)
        startOf(Zi[i]) >= max(p in precedenceConstraints: p.succ == i) endOf(Zi[p.pred]);
    
    
      // Constraint (13): Cmax greater than or equal to lower bound
      Cmax >= LB;
      
      
    }
    
    // Execute and print results
    execute {
      cp.startNewSearch();
      while (cp.next()) {
        writeln("Solution:");
        for(var i in Jobs) {
          if (cp.isPresent(Zi[i]))
            writeln("Job ", i, ": Start = ", cp.startOf(Zi[i]), ", End = ", cp.endOf(Zi[i]));
        }
      }
      cp.endSearch();
    }
    

    .dat

    N = 3; M = 2; R = 1; 
    
    processingTime = [ [0, 0]]; //, // Dummy job 0 [3, 4], // Job 1 [2, 3] // Job 2 ]; 
    
    readyTime = [0, 1, 2]; 
    
    setupTime = [ [[0, 0, 0], [0, 1, 2], [0, 1, 1]],
     [[0, 0, 0], [0, 1, 2], [0, 1, 1]], 
    [[0, 0, 0], [0, 1, 2], [0, 1, 1]] ];
    
     resourceNeed = [ [0]]; // Job 0 [2], // Job 1 [1] // ]; 
    
    resourceAvail = []; 
    
    machineEligibility = [ [1, 1], [1, 0], [0, 1] ]; 
    
    precedenceConstraints = {<1, 2>}; 
    
    LB = 5;