views:

113

answers:

4

I'm lost here. Here's the problem and I think it's NP-hard. A center is staffed with a finite number of workers with the following conditions:

  1. There are 3 shifts per day with 2 people in each shift
  2. Each employee works for 5 days straight and then 2 days off with only one shift per day

So the problem is: how many workers do we need if the center remains active every day and a feasible schedule?

Update:

Thanks for all the great answers. The closest I've come to (with a randomized brute-force algorithm) is the following:

X       3       0
1       0       3
2       3       1
2       1       3
0       1       2
0       2       1
3       0       2

I've simplified the problem into batches of 2 people (0-3 represent 4 batches) in the hopes of getting a feasible solution. X refers to a shift which has not been assigned (which was not the initial goal but it looks like there may not be an alternative).

A: 

3 shifts x 7 days = 21

this does not divide evenly by 5 nor 2 - so your constraints will not allow a complete filling of the slots.

Randy
What if you're scheduling for more than 7 days?
Alan
i think immediately, the schedules will not line up. you can try a simple experiment by writing down on a calendar: for coverage on the first shift only, you cannot fill the requirement with 2 employees, because of the 2 day gaps - if you intorduce a third, then someone must either have more than 2 days off, or there are more than 3 people working in one shift.further, if you assume the third guys moves to another shift on his extra days, he has 3 days capacity, which does not line up with other shifts 2 day gaps. (total of 4 days needed)
Randy
+2  A: 

3 shifts per day * 2 people per shift * (7 days per week / 5 working days per person) = 8.4 people (9 if part time is not an option).

btreat
This logic works for me. 3 shifts per day * 2 slots per shift= 6 shifts = 42 shifts in a 7 day week. Each employee can work a max of 5 shifts per week. 42/5 = 8.4.Am I missing something subtle (or not so subtle)?
labratmatt
Jacob
@Jacob You asked "how many workers," not "how to generate a schedule." If you're looking to generate a schedule, maybe you can clarify that in your original posting?
labratmatt
Unless I'm missing something, a schedule with a whole number of people is possible over a 5 week period, but not within a single week.
btreat
@btreat: check my answer for an example of a schedule with a one week period; this said this schedule is somewhat unfair, whereby not all workers have the same workload. I concur that 5 weeks (or maybe 7 weeks?) should be sufficient to introduce a fair schedule where all workers work the same amount in a given period. Fairness can be hard to measure, when it comes to having the same sets of number of consecutive days of rest or work, not to mention that in real life, not all days are equal (workers value the weekend as rest days to be w/ family) and also folks need vacation.
mjv
@labramatt: My apologies, I assumed I had mentioned that.
Jacob
+3  A: 

The constraints cannot be respected exactly as expressed in the question.
That's because the numbers don't add up (or rather "divide up").

Consequently, the problem should be reworded to require

  • exactly 3 shifts per day
  • exactly 2 workers per shift
  • workers work a maximum of 5 consecutive days
  • workers rest a minimum of 2 consecutive days

With the introduction of the minimum and maximum qualifiers, the minimum number of workers required is 9 (again assuming no part-time worker).
Note that although 9 appears to be a absolute minimum, given the need to cover 42 shifts per week (3 * 2 * 7) with workers who can cover a maximum of 5 shifts per week (5 work days 2 rest days = a week), there is no assurance that 9 would be sufficient given the consecutive work and/or rest day requirements.

This is how I figure...
8 workers isn't enough, and the following 9 workers line-up, is an example of such a schedule.
To make things easy, I assigned all workers except for worker #1 and #9, to an optimal schedule of exactly a 5 days-on and 2 days-off schedule; #1 and #9 work less. Of course many other arrangements would work (maybe this is what the OP sensed when he hinted at an NP-complete problem). Also, the schedule is such that each week's schedule is exactly the same for everyone, but that could also be changed (maybe introducing some fairness, by having all workers have a lighter week every once in a while, but this BTW can lead to some difficulties of respecting the requirement of 5 maximum work days).
The sample schedule shows two consecutive weeks to help see the consecutive work or rest days, but as said, all weeks are the same for every one.

                              Max Conseq Ws   Min Conseq Rs
Worker #1   RRWWWRW RRWWWRW         3              2
Worker #2   WWWWWRR WWWWWRR         5              2
Worker #3   WWWRRWW WWWRRWW         5              2
Worker #4   WWWRRWW WWWRRWW         5              2
Worker #5   WRRWWWW WRRWWWW         5              2
Worker #6   WRRWWWW WRRWWWW         5              2
Worker #7   RWWWWWR RWWWWWR         5              2
Worker #8   RWWWWWR RWWWWWR         5              2
Worker #9   WWRRRRW WWRRRRW         3              3

Nb of Ws    6666666 6666666

The tally at the bottom shows exactly 6 workers per day (respecting the need to cover 3 shifts with 2 workers each), the max and min columns on the right show that the maximum consecutive work and minimum consecutive rest requirements are respected.

mjv
+1 - Thanks for a great answer but the continuous 5 days requirement must stick. Looks like it's not possible, perhaps and compromises need to be made. I have a solution (8 people), which seems feasible except that one shift is not covered. Maybe it'll have to do.
Jacob
@Jacob: understandingly, an 8 worker team will be short by 2 shifts per week: we have 42, i.e. 3 * 2 * 7 shifts to cover, whereby 8 workers on a 5on/2off schedule cover only 40 (8 * 5) shifts per week. When adding one (or several) workers to this 8 team basis, we then provide for _more_ than 42 shifts per week, introducing either the need for some (or all) workers to rest more or work less or to have more than 2 workers per shift, some of the time. `42 is just not divisble by 5` and that is the fundamental impediment to solving the problem with _exactly_ 5-on/2-off individual schedules.
mjv
@mjv: One shift can work (see example) if you lump two workers into one batch and assume they have the same schedule. Then you have 21 shifts to cover over 5 working days which let's us survive with a loss of 21-(4*5) = 1 shift.
Jacob
@mjv: And thank you for the complete answer (possible solution and proof that no optimal solution exists within these constraints).
Jacob
@mjv: I get it now, you mean 2 shifts are lost counting the 2 workers who won't be working on that day. Agreed - I was thinking of unmanned shifts (since each shift needs two people anyway; 1 person is not enough per shift).
Jacob
@Jacob: Right! I'm at fault for using the word "shift" loosely, sometimes from the _workplace_'s standpoint (eg: "there are 3 shifts per day, each using two workers") and sometimes from the _worker_'s standpoint, i.e. meaning a "time slot" on the schedule (eg: "each worker can cover 5 shifts per week"). At any rate you now seem to understand both this ambiguous use of the word as well as the bigger issue.
mjv
@mjv: Exactly!!
Jacob
A: 

OK - even though you have an answer, let me take a shot.

Let's take the general problem: 7 days x 3 shifts = 21 different shifts to fill There are 7 possible employee schedules expressed as days on (1) & days off (0)

MTWTFSS 0011111 1001111 1100111 1110011 1111001 1111100 0111110

We want to minimize the number of scheduled employees that matches the number of required hours.

I have a matrix of number of employees of each type per shift and that number is an integer variable. My optimization model is:

Min (number of employees)

Subject to: sum of (# of emp sched * employee schedule) = staff required for each shift

and

number of employees scheduled is integer

You can change the = sign in the first constraint to a >=. Then you'll get a feasible solution with extra staff. You can solve this in Excel with the basic SOLVER addin.

Let's say I need four employees for each day on a shift but I'm willing to tolerate extra staff.

A solution using the schedules above is:

Number of staff by schedule type: 0,2,0,2,0,2,0

Schedule types 0011111,1001111,1100111,1110011,1111001,1111100,0111110

(In other words 2 with schedules 1001111, 2 with schedules 1111001, and 2 more with schedules 1111100)

This results in one day (Monday) with two extra staff and 4 employees on all the other days.

Of course, this isn't a unique solution. There are at least 6 other solutions with two extra staff members. Constraint programming would be a better and much faster approach since there will often be many feasible schedules.

Grembo
Thanks, but if this works, how would this get me a schedule?
Jacob