Yesterday while trying to fall asleep I started thinking about how to solve the problem below and realized I couldn’t come up with a good algorithm. This is not a school assignment even if it might look like one, I just want to find an answer. 🙂
Basically let’s imagine a work schedule for employees in a store. The program should generate schedule suggestions based on a set of requirements.
The requirements are:
- Only one employee works any given week.
- An employee can’t work two weeks in a row.
- There should be a way to prevent an employee from getting
scheduled to work a certain week (vacation). - The distribution should be as even as possible, i.e. if we have
employees A, B and C they should get approximately the same ammount
of weeks off and those weeks should be as evenly distributed as
possible.
What would be the best way to attack this problem? Perhaps functional programming is better for solving this?
EDIT: Now I know this type of problems is called “resource constrained scheduling”. Is a bit hard to goole for this as “scheduling” often refers to things like scheduled tasks or threading. For the people who still think I’m asking for homework solutions (despite me explicitly claiming otherwise above), you can check out my previous questions, I think they clearly indicate I’m not a student…
Even though it seems as if this is homework, I prefer to believe you.
Here is what I’ve come up with:
For example:
The output is (seems reasonable to me):