Search code examples
cplexopl

Resource-Constrained Project Scheduling Problem (RCPSP) Implementation in OPL for CPLEX


I would appreciate any guidance on correcting my mistakes. I'm attempting to implement the RCPSP model by Pritsker et al. (1969). Link : Here

// Example data
range J = 1..5;
range R = 1..3;
range T = 1..10;
int P[J] = [0,1,2,3,4]; 
int d[J] = [1, 1, 3, 5, 2];
int EF[J] = [1, 2, 1, 1, 1];
int LF[J] = [2, 3, 4, 6, 2];
int Tbar = sum(j in J) d[j];

// Resource usage matrix
int u[J][R] = [[1, 0, 2],
               [1, 1, 1], 
               [1, 1, 0],  
               [2, 0, 3],  
               [1, 1, 2]]; 

// Resource availability
int a[R]= [1,2,3];

// Decision Variables
dvar boolean x[J][T];

dexpr int CT = sum(j in J, t in EF[j]..LF[j])t*x[j][t];
minimize CT;

subject to {
  forall(j in J)
    sum (t in EF[j]..LF[j]) x[j][t] == 1;
  forall(j in J, i in J)
    sum (t in EF[j]..LF[j]) (t - d[j]) * x[j][t] - sum (t in EF[i]..LF[i]) t * x[i][t] >= 0;    
  forall(r in R, t in 1..Tbar) {
    sum(j in J) u[j][r] * sum(q in max(t, EF[j])..min(t + d[j] - 1, LF[j])) x[j][q] <= a[r];
  }
}


Solution

  • max should be maxl!

    If I write

    subject to {
      forall(j in J)
        ct1:sum (t in EF[j]..LF[j]) x[j][t] == 0;
      forall(j in J, i in J)
        ct2:sum (t in EF[j]..LF[j]) (t - d[j]) * x[j][t] - sum (t in EF[i]..LF[i]) t * x[i][t] >= 0;    
      forall(r in R, t in 1..Tbar) {
        ct3:sum(j in J) u[j][r] * sum(q in maxl(t, EF[j])..minl(t + d[j] - 1, LF[j])) x[j][q] <= a[r];
      }
    }  
    

    then I get a solution