dwave-examples / nurse-scheduling

A demo of a nurse scheduling model
Apache License 2.0
45 stars 38 forks source link
bqm constraint-satisfaction-problem healthcare hybrid-solution intermediate optimization

Open in GitHub Codespaces Linux/Mac/Windows build status

Nurse Scheduling

This is a demo of a nurse scheduling model developed by Ikeda, Nakamura and Humble (INH).

The nurse scheduling problem seeks to find an optimal assignment for a group of nurses, under constraints of scheduling and personnel. INH developed a model which is a simplified representation of a real-world nursing facility.

In the general nurse scheduling problem, there are three types of constraints, which are mentioned here to provide background for INH's constraints. These types of constraints, in the general problem, are:

1) Both upper and lower limits on the number of breaks. 2) The number of nurses on duty for each shift slot. 3) For each individual nurse, upper and lower limits on the time interval between days of duty.

These three types of constraints combine to ensure sufficient nurses on duty at all times, without overworking any particular nurse.

INH formulated a QUBO from a simplification of these constraints, discussed below, that tries to achieve reasonable results for nurse scheduling.

INH's three types of constraints are:

1) "hard shift" constraint: requires that at least one nurse is assigned for each working day.

2) "hard nurse" constraint: requires that no nurse works two or more consecutive days.

3) "soft nurse" constraint: promotes that all nurses should have roughly even work schedules.

This demo seeks to obtain reasonable results for a nurse schedule, based on INH's model. Our implementation attempts to find a schedule for a number n_nurses of nurses and a number n_days of days that satisfies the following conditions:

Running the demo results in the following output, at the command-line:

Building binary quadratic model...

Sending problem to hybrid sampler...

Building schedule and checking constraints...

    Hard shift constraint: Satisfied
    Hard nurse constraint: Satisfied
    Soft nurse constraint: Unsatisfied

Schedule:

Nurse  2         X        X     X     X    
Nurse  1      X        X           X     X 
Nurse  0   X        X        X             
           0  1  2  3  4  5  6  7  8  9  10 

Schedule saved as schedule.png.

The results show the following:

An image of the schedule (shown below) is saved to the file schedule.png.

Example Schedule

Usage

To run the demo, run the command

python nurse_scheduling.py

Code Overview

Here is a general overview of the Nurse Scheduling code:

Note that the total of the three constraint sums should equal the energy.

Code Specifics

Some notes on the code:

References

Ikeda, K., Nakamura, Y. & Humble, T.S. Application of Quantum Annealing to Nurse Scheduling Problem. Sci Rep 9, 12837 (2019). https://doi.org/10.1038/s41598-019-49172-3

License

Released under the Apache License 2.0. See LICENSE file.