How make to correctly logical implication in CP's Cplex

55 views Asked by At

I'm new to CPLEX, and I'm doing a project using CP.

I have a multilist A that has 4 arguments : one Operation o, one Surgeon s, one Room r and one Time t

A[o,s,r,t] == 1 if and only if the operation o is done by the surgeon s in the room r and starts at time t

and I want to say that each operation can only be done once, so in the constraints, I wrote :

forall(o in Operations,s in Surgeons,r in Rooms,t in Times,s2 in Surgeons,r2 in Rooms,t2 in Times){
  ((s!=s2 || r!=r2 || t!=t2) && A[o,s,r,t] == 1) => A[o,s2,r2,t2]==0;
  //if an operation is done with some settings, it can't be done with any other settings 
 }  

The logic is there but I feel like I'm asking CPLEX to do 7 nested loops, how to do that more efficiently ?

2

There are 2 answers

0
Alex Fleischer On

Instead of logical constraints

forall(o in Operations,s in Surgeons,r in Rooms,t in Times,s2 in Surgeons,r2 in Rooms,t2 in Times){
  ((s!=s2 || r!=r2 || t!=t2) && A[o,s,r,t] == 1) => A[o,s2,r2,t2]==0;
  //if an operation is done with some settings, it can't be done with any other settings 
 }  

you could use slicing

forall(o in Operations,s in Surgeons,r in Rooms,t in Times,s2 in Surgeons,r2 in Rooms,t2 in Times:((s!=s2 || r!=r2 || t!=t2) ){
   (A[o,s,r,t] == 1) => (A[o,s2,r2,t2]==0);
  //if an operation is done with some settings, it can't be done with any other settings 
 }  
0
FalC On

Is it possible for you to make "Sums" ? I'm not using your exact syntax, but something like this :

forall(o in Operations){
   sum(sum(sum(A[o,s,r,t] for t in Times) for r in Rooms) for s in Surgeons) == 1
}

By doing so, we assert that each Operation o, is done only once, by a single surgeon, in a single room, at a given time.