1

I work in a residence hall at my college as an RA, and each night we need two RAs to be on call (able to respond to incidents and emergencies). Each month, RAs submit the nights they cannot be on call (due to a conflict of some sort). There are both male and female RAs. I am trying to come up with an effective algorithm to find the best arrangement of on-call nights for any particular month that satisfies the following requirements:

  • No RA is scheduled for a night he or she has listed as unavailable.
  • No RA is on-call more than a specified number of nights per month.
  • No RA is on-call twice within any given three-night span.
  • Each night has exactly two RAs on call.
  • Each night has, if possible, one male and one female RA on call.

Doing some research, I've found that this is a resource-constrained scheduling problem, and it is considered NP-complete. Therefore, I don't need to find the optimal solution, just any solution that works.

So far, I've considered the following approaches:

  • A simple 2d array of RAs x nights where each cell holds a boolean value answering whether or not that RA is on call for that night. I could hold the RAs in two priority queues (one male and one female) sorted by how many nights they've had so far, how long it has been since their last on call night, and simply iterate through the nights, selecting one RA from each queue, and then backtracking if I hit a dead end where nobody can work a particular night.
  • A tripartite graph with male RAs on one side, female RAs on another, and nights on the last side. In the solution, each night would have an edge to one male and one female RA. I would start with all edges connected and then remove edges until a solution is found.
  • Some sort of genetic approach using the above structures.

What sort of approach do you suggest I use? Is there something I haven't thought of that might work better? This is not a homework question; I am trying to develop a website that would make it easy for my staff and possibly other staffs on campus to submit date preferences and then generate a schedule that works for everybody.

Kevin
  • 661
  • 6
  • 14

2 Answers2

0

I recommend the 2d array, but instead of iterating through the nights in order from first to last you iterate through the nights in order from most to least constrained - in other words, start with the night that has the fewest RAs available due to conflicts. This heuristic could also apply to the tripartite graph if you go with that approach - it's basically a question of domain representation, the algorithm itself isn't affected at this point.

The question is what you do when you reach the last few nights and find that no RAs are available. At this point you would do a local search to attempt to reach a viable solution, for example you've selected RA1 for NightA but RA2 and RA3 were also available on that night, so you select RA2 or RA3 to see if that frees up RA1 for the night on which you did not have an available RA.

Zim-Zam O'Pootertoot
  • 17,888
  • 4
  • 41
  • 69
  • Thanks! Good idea with starting at the most-constrained night, I think that's what I was missing. How would you suggest performing the local search? I'm having trouble envisioning what sort of algorithm/data structure I would need to do that kind of backtracking. – Kevin Apr 20 '13 at 00:00
  • An unscheduled night has a set of RAs who could potentially be scheduled (they're "available" but they have conflicts because they've been scheduled within 3 days or whatever), so select one and remove the conflicts, e.g. unschedule them for the night that would violate the not-more-than-twice-in-three-days rule. Now fill the gap on THAT night with another RA using the same approach, and repeat until you unschedule an RA for a night on which you already have an available RA. – Zim-Zam O'Pootertoot Apr 20 '13 at 00:05
  • After you find a viable solution, you can iteratively improve it via local search to e.g. maximize the number of nights on which both a male and female are scheduled, or maximize the number of nights on which you have a backup RA in case one of the scheduled RAs get sick. – Zim-Zam O'Pootertoot Apr 20 '13 at 00:07
0

Using the binary variables mentioned, your problem can be formulated as an Integer Linear Program (ILP). If there are not more than a few thousand variables, this can probably be solved optimally by a solver such as GLPK. All constraints but the last one are already linear. For "Each night has, if possible, one male and one female RA on call", you can introduce another Boolean variable "x" for each night, have a constraint "sum of female RAs on call <= 1 + x", and then minimize the sum of x's, thereby allowing the constraint to be violated at a cost. If you provide the data to the solver in text format, this should also be not too hard to implement.

Falk Hüffner
  • 4,942
  • 19
  • 25