0

I am still a beginner with constraint programming and I am currently trying to implement a nurse scheduling problem in Python which is similar to the example provided on Google OR-Tools.

However, in my scheduling problem, there are multiple patients that each have the same number of shifts on each day but at different time points during the day. The constraint I am trying to implement should ensure that a given nurse is not assigned to shifts that overlap each other in time. For example, if patient X has a shift from 10-12 AM and patient Y a shift from 9-11 AM, a given nurse should only be assigned to one of these shifts. How would one go about implementing this?

My approach was to create two separate lists (or a tuple list combining them):

(1) One to define the duration of each shift, shift_duration (a list of elements each representing the duration of a shift in hours)

(2) One to define the shifts starting time, shift_starting_point (a list of elements ranging from 0 to 24 each representing a shift) in another list (typewise similar to shift_requests in the example).

I was trying to apply the AddNoOverlap method from the Job Shop Problem, but I could not figure out how to combine them into a hard constraint rule using this method. I also don't know whether that approach makes a lot of sense. I'd appreciate any help - thanks!

MichlF
  • 139
  • 1
  • 8

1 Answers1

2

I would start with the easy approach:

for each conflicting pair of shifts (a, b):
  for each nurse n:
    model.AddBoolOr([assign_a_n.Not(), assign_b_n.Not()])

I know this is quadratic, but it is simple.

Laurent Perron
  • 8,594
  • 1
  • 8
  • 22