Availability constraints

2022-05-23
3 min read

This project is an answer project for StackOverflow per the following link.

https://stackoverflow.com/questions/47312013/google-or-tools-employee-scheduling-with-availability-constraint?rq=1

Specifications

I’m trying to add more constraints to the problem. For instance:

  1. Nurse A cannot work shifts 2 and 3 on Monday,
  2. Nurse B can only work shifts 1 and 3 across all days.

How would one go about implementing a constraint like this?

Implementation

We have implemented it ,based on the following project.
Maximum-length-series-of-shifts slow down solving speed

Basic Direction

It is not a good idea to write constraints for everything. We recommend following directions.

  1. Permanent rules should be constrained.
  2. Write shift/task schedule inputs for monthly rules as much as possible.
  3. Itemize table items on the staff property sheet by constraining the rules which may be used in the future or can not be handled by schedules.

It takes a certain amount of time and skill to constrain and debug constraints.
Once the system is up and running, it must be easily operated and maintained for even those unfamiliar with IT, by simply entering monthly schedules, and changing table items on the staff property sheet.

Nurse A cannot work shifts 2 and 3 on Monday,

Here, we assume;

Shift Description
shift 1 morning
shift 2 afternoon
shift 3 Night shift

Shift Aggregates

We can define A new shift label “Nan” , i.e., not afternoon and not night shift.

We can schedule "Nan" every Monday as follows.
Note we can utilize the label next month or for other staff.

Nurse B can only work shifts 1 and 3 across all days.

If the rule is permanent, we can achieve the constraint by uncheking the shift table for the staff below.

However, if the rule is likely to change in the future, we suggest not using the table above. Because, it would result an error at switching the shift on/off between last month and this month. (Note this is a hard constraint that does not accept any conflicts every day.) Therefore, we suggest using a staff property sheet as follows.

To make the table items above, we define following group properties.

Note we can utilize the table next month or for other staff.

To make the table item works as a constraint, we we add new constraints as follows.

We should revise the row constraints because staff may change by the change of the table.

Here ,we should define Not the group property as follows.

You can see your definitions in the applicable staff enumeration at the bottom of figure above.

In summary, changes to table items correspond to changes to constraints. Now you don’t have to add or change row/column constraints later. If possible, make choices in the table beforehand to anticipate possible future changes.

Solve it!

Solution

Project File

File → Open Project File from Github