8

I have been trying for some time solve a scheduling problem for a pool that I used to work at. This problem is as follows...

There are X many lifeguards that work at the pool, and each has a specific number of hours they would like to work. We hope to keep the average number of hours away from each lifeguards desired number of hours as low as possible, and as fair as possible for all. Each lifeguard is also a college student, and thus will have a different schedule of availability.

Each week the pool's schedule of events is different than the last, thus a new schedule must be created each week.

Within each day there will be so many lifeguards required for certain time intervals (ex: 3 guards from 8am-10am, 4 guards from 10am-3pm, and 2 guards from 3pm-10pm). This is where the hard part comes in. There are no clearly defined shifts (slots) to place each of the lifeguards into (because of the fact that creating a schedule may not be possible provided the availability of the lifeguards plus the changing weekly pool schedule of events).

Therefore a schedule must be created from a blank slate provided only with...

  • The Lifeguards and their information (# of desired hours, availability)
  • The pool's schedule of events, plus number of guards required to be on duty at any moment

The problem can now be clearly defined as "Create a possible schedule that covers the required number of guards at all times each day of the week AND be as fair as possible to all lifeguards in scheduling."

Creating a possible schedule that covers the required number of guards at all times each day of the week is the part of the problem that is a necessity and must be completely solved. The second half about being as fair as possible to all lifeguards significantly complicates the problem leading me to believe I will need an approximation approach, since the possible number of way to divide up a work day could be ridiculous, but sometimes may be necessary as the only possible schedule may be ridiculous for fairness.

Edit: One of the most commonly suggested algorithms I find is the "Hospitals/Residents problem", however I don't believe this will be applicable since there are no clearly defined slots to place workers.

yiati
  • 972
  • 1
  • 13
  • 27
  • 6 years later, and this article by Google OR-Tools is extremely relevant https://developers.google.com/optimization/scheduling/employee_scheduling – yiati Sep 04 '19 at 22:28

2 Answers2

10

One way to solve this is with constraint programming - the Wikipedia article provides links for several constraint programming languages and libraries. Here is a paper describing how to use constraint programming to solve scheduling problems.

Another option is to use a greedy algorithm to find a (possibly invalid) solution, and to then use local search to make the invalid solution valid, or else to improve the sub-optimal greedy solution. For example, start by assigning each lifeguard their preferred hours, which will result in too many guards being scheduled for some slots and will also result in some guards being assigned a ridiculous number of hours; then use local search to un-assign the guards with the most hours from the slots that have too many guards assigned.

Zim-Zam O'Pootertoot
  • 17,440
  • 4
  • 38
  • 67
  • Constraint programming seems to be the best solution here to me now (at least after reading up on it now for a couple minutes). The people at the pool seem to pull out their hair each week trying to make a schedule that works while keeping the guards happy. It seems that constraint problems tend to be NP-Hard. – yiati Jun 17 '13 at 04:30
  • 1
    @yiati This is the generalized assignment problem, which means that it's NP-hard unless the cost function is trivial – Zim-Zam O'Pootertoot Jun 17 '13 at 04:36
  • @Zim-ZamO'Pootertoot I have a similar problem to schedule resources to a work pattern, I have 5 employees, they all work under a fixed cyclic pattern 4 3 3 4, means 4 days work, 3 days off, 3 days work, 4 days off, now the constraint is each day minimum 3 employees working. I got headache for few days but still dont know where to start, could you please give a guide, thanks. – Saorikido Jan 21 '16 at 04:04
  • @Z.Neeson I don't know if it will be possible to satisfy your constraint with that schedule - you have 5 employees and each employee is working 50% of the time, so on average during each 14 day cycle you'll only have 2.5 employees working. Is it possible to assign extra days / fewer off days to an employee or anything like that? – Zim-Zam O'Pootertoot Jan 21 '16 at 07:46
  • @Zim-ZamO'Pootertoot Yes you are right, I didn't clarify the problem, the resources obviously not enough for one cycle, actually this is the problem we are facing, the pattern is fixed (i don't know why they prefer this pattern ...), so now, we have two options to meet the daily minimum working resources, either hire more employees to work on the same pattern (4334) or hire some part time employees to fill up the vacancy, salaries are all daily based salary, so how to spend min money to get the optimal solution/combination? – Saorikido Jan 22 '16 at 02:01
  • 1
    @Zim-ZamO'Pootertoot Current department is a small department just few people, in worst case we can iterate through all the cases to find the optimal solution, but for other departments (they have their own working pattern), some of them have more than 60 resources working under shift, so we have to find a way to solve this pulling hair problem. – Saorikido Jan 22 '16 at 02:13
  • @Zim-ZamO'Pootertoot In my mind, this problem would be, each employee will have a different starting offset of the pattern sequence, so what's the best offsets combination to get minor vacancies? I'm not sure if a correct hypothesis... – Saorikido Jan 22 '16 at 02:28
  • 1
    @Z.Neeson I suspect that given a 14-day work period your best solution is going to be to have N/14 employees start their work period on any given day, e.g. with 28 employees you would have 2 start their work period on day 1, 2 start on day 2, etc. I suggest that you write a simple greedy algorithm that assigns an equal distribution as well as an algorithm that assigns a random distribution, run the random algorithm a few thousand times, and see if it ever beats the equal distribution; if it doesn't then use the equal distribution, if it does then a cleverer solution may be called for – Zim-Zam O'Pootertoot Jan 22 '16 at 02:34
  • @Zim-ZamO'Pootertoot hmm.. make sense, let me give a try first, thank you very much. – Saorikido Jan 22 '16 at 02:44
4

You need to turn your fairness criterion into an objective function. Then you can pick from any number of workplace scheduling tools.For instance, you describe wanting to minimize the average difference between desired and assigned hours. However, I'd suggest that you consider minimizing the maximum difference. This seems fairer (to me) and it will generally result in a different schedule.

The problem, however, is a bit more complex. For instance, if one guard is always getting shorted while the others all get their desired hours, that's unfair as well. So you might want to introduce variables into your fairness model that represent the cumulative discrepancy for each guard from previous weeks. Also, a one-hour discrepancy for a guard who wants to work four hours a week may be more unfair than for a guard who wants to work twenty. To handle things like that, you might want to weight the discrepancies.

You might have to introduce constraints, such as that no guard is assigned more than a certain number of hours, or that every guard has a certain amount of time between shifts, or that the number of slots assigned to any one guard in a week should not exceed some threshold. Many scheduling tools have capabilities to handle these kinds of constraints, but you have to add them to the model.

Ted Hopp
  • 222,293
  • 47
  • 371
  • 489
  • I agree that I should definitely aim to minimize the maximum difference. I also see now how weighting them could definitely be an important factor I hadn't considered. – yiati Jun 17 '13 at 04:23
  • What kinds of scheduling tools already have these capabilities and/or what are these capabilities called so that I don't recreate the wheel here if it's not necessary? – yiati Jun 17 '13 at 04:41
  • @yiati - I don't know too much about existing tools, and I certainly can't recommend one over another. From [this discussion](http://aiconnect.ning.com/forum/topics/lifeguard-scheduling), it seems like whentowork.com does most of what you want. Some other tools are listed [here](https://en.wikipedia.org/wiki/Employee_scheduling_software) (they tend to be more heavy-duty personnel management packages) and you can Google "lifeguard scheduling" to find more resources. – Ted Hopp Jun 17 '13 at 05:01