I'm using DOcplex for Python to build a constraint programming model. The problem is surgery allocation, and it works fine until I add a specific constraint.
I need to calculate a value to assign to my variable F, and for that I also need the values inside an array called CPAffi. The position of the value to be taken is given by the value of the expression M[p] * len(second) + S[p]
, where M[p]
is an integer variable that represents the ID of the main surgeon attending for patient p and S[p]
is another integer variable which represents the ID of the secondary surgeon attending patient p. T[P]
is the starting time of operation of patient p. If any of these variables take a negative value, patient p is not allocated, but this shouldn't be a problem since I use if_then()
to ensure M[p]
is equal to the values in surgeon, that is, [0..10], before using mdl.element()
to search in the array. In another constraint I establish that if M[p]
is negative, S[p]
and T[p]
must also be negative.
for p in patient:
for s in surgeon:
for d in range(1,nDay+1):
mdl.add(mdl.if_then(mdl.logical_and(M[p] == s, mdl.logical_and(S[p] >= 0,mdl.logical_and(T[p]//len(slot) >= d-1, T[p]//len(slot) < d))), F[p][s][d] == (mdl.element(CPAffi, M[p] * len(second) + S[p]))))
This works fine for instances where al patients are allocated to a surgery, but when one patient isn't, then the model turns infeasible. I have tried for hours to fix this problem, but with no results, and after experimenting with everything, I noticed that when I replace F[p][s][d] == (mdl.element(CPAffi, M[p] * len(second) + S[p]))
with, say, F[p][s][d] == 10
(an arbitrary number) the model is feasible again. So, when my variable M[p] takes a negative value, mdl.element()
stops working; that would make sense, if only I wasn't using if_then()
to ensure M[p] takes a number between 0 and len(surgeon)
. So, is this a bug? Is there something I'm not seeing? Please help, I have been trapped in this situation for weeks now.