0
votes

I have this problem while trying to find a solution for a resource constraint scheduling problem. Whenever I put dvar as a condition in a forall loop or if condition I have the error that states "Decision variable (or expression) "S" not allowed".

range activity = 1..16;
dvar float+ S[activity];

dvar float+ rd[jobs];

forall (i in activity)
 forall (t in T:S[i]<=t<=S[i]+D[i]) //boolean b 
        b[i][t]==1;

forall (t in T)
  forall (k in R)
    sum (i in activity)b[i][t]*V[i][k]<=Rk[k];//human resources constraint

  forall (j in jobs)
  forall (t in T:rd[j]<=t<=S[maxact[j]])//boolean y
  y[j][t]==1;
2

2 Answers

0
votes

This is a very common mistake. The code you are writing is building the model for cplex. The cplex variables in your (dvars, like your S) usually do not have a value until the model has been solved, so you cannot use their value during the model building process. You need to restructure your problem and you will probably need to use additional bool or int variables or indicator constraints inside your model.

0
votes
range activity = 1..16; 
dvar float+ S[activity];
range jobs=1..3; 
range T=1..3; 
range R=1..4;
dvar boolean b[activity][T]; 
dvar boolean y[jobs][T]; 
int D[activity];
int Rk[R]; int V[activity][R]; int maxact[j in jobs]=1;

dvar float+ rd[jobs];

subject to { 
 forall (i in activity)  
  forall (t in T) //boolean b 
     ((S[i]<=t) &&(t<=S[i]+D[i])) => (b[i][t]==1);

 forall (t in T)   forall (k in R)
  sum (i in activity)b[i][t]*V[i][k]<=Rk[k];//human resources constraint

   forall (j in jobs)   forall (t in T)//boolean y  
 ((rd[j]<=t) &&
 (t<=S[maxact[j]])) =>  (y[j][t]==1); 
}

will work

regards