I am trying to write a program to help scheduling shifts for the employees of a small business. There are 28 shifts that needs to be assigned to 28 employees (so this means that each person gets a shift per week). Each employee can provide a set of preferred shifts, so my idea was to procede as follows: 1) first assign the preferred shift to those employees that provided only one preference 2) after step #1, go back and assign each remaining shift to the first person whose preferences match said shift

Is this a smart way to approach this problem? If not, can you help me understand what is wrong and/or point me towards some literature that may help me with that?


2 Answers 2


The supposed algorithm will not work, because it contains no collision handling. But there is a simple way to extend it to make it at least produce some solution:

  • in step 1, if there are collisions for a shift, throw a dice among the employees which attend for the same shift, and pick one

  • in step 2, the same

  • add a step 3: distribute all remaining employees among the remaining shifts randomly

You could also try a slightly different approach: don't separate step 1 and 2. Instead, start with all shifts which are given as first preference by at least one employee, no matter if they gave one or more preferences. Then,

  • throw a dice among those employees to decide who gets the shift.

  • remove that shift from the preference list of each employee where it occurs

  • repeat this until the the preference lists of all employees became empty

  • finally, distribute all remaining employees among the remaining shifts at random.


It sounds like you are trying to solve the "Nurse Scheduling Problem" (NSP), although your problem seems to be a simplified version of it. There are many articles written about how to find feasible solutions to the problem. If you want something up and running fast, you could try to use Google's python package, which can be found here: Employee Scheduling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.