Saturday, February 19, 2005

Duty Scheduling

Ok so the OC made my fellow disruptee come up with a WITS project, and we thought it'd be cool to do an automated duty scheduler for guard duty and COS. Really not an easy problem as the guy who used to do the scheduling spent quite a bit of time juggling duties around.

So let's break down the problem:
We want an algorithm that takes in the monthly guard duty schedule, which is a list of the tuple (date, number of guards), and a list of the people in my company and their points (person, points), and outputs the guard duty assignment, which is a list of the tuple (date, guard1, guard2, ... guardn), subject to the following constraints:

1. Fairness be maintained between the people in the company, to be achieved by point equalisation, where Mon-Thurs duties are worth 1 point, Fridays 2, and weekends 3 points.
2. There needs to be one COS everyday.
3. No one is to serve consecutive weekends
4. No one is to serve duties on 2 consecutive days (COS and guard included)

So we have here a scheduling problem, which I guess could reduce to a constraint satisfaction problem. On googling, typical solutions involve genetic algos, taboo search, and various optimisation techniques to find the global minimum, which satisfies the constraints, Not sure if that's going to be doable.

So currently I've thought of an idea which might serve as a good starting point.
We have 2 sorted lists, one of the duties of the month, sorted highest to lowest by their point-values, and the other, of the people in my company sorted lowest to highest by their number of points.
So we simply iterate through the duties of the month, from the head of the list, assigning the guy at the head of the people list to the duty if it satisfies the constraints. Once the duty has been assigned, we recalculate his points and reinsert him back into the list. If the constraints aren't satisfied, we move on to the next guy.
A simple greedy algorithm, but one that I suspect will have problems satisfying all the constraints, while filling up all the guard duties.

Another thing I've considered is randomisation with iteratively improving swaps to iron out all the conflicting duties.

What I really need now is some algorithmic meat, or some simliar solution that has already been implemented, and to decide whether the algorithm will necessarily obtain the best solution, or just be best effort, leaving the human to sort out the possible conflicts.

Any suggestions out there?

And does anyone out there know if it's better to use VB or Java for this? I'm developing for camp use so perhaps being able to compile into an executable might be a better idea. But oh man VB's a bloody ugly language. Or is there some other option?


3 Comments:

At 12:39 PM, Anonymous Anonymous said...

Hi Der Yao,

This is Greg writing. I wrote a scheduling program that had many hairy constraints for the VA Medical Center in Buffalo, NY using an integer program. It has worked fairly effectively. You might want to look into integer programming. A free implementation (student version) of the AMPL modeling language can be found at www.ampl.com. CPLEX is the solver you would want to use. If you are keen to see the way I've done this in AMPL, I can send you my files.

Greg

 
At 3:54 PM, Anonymous Anonymous said...

hi i was referred to this blog by a friend... thought i'd write some comments.

i second the recommendation of using vba in excel, not just for the reasons already mentioned. the speed and ease of implementation is practically unrivalled, partly due to the nature of vb, and also because of the simplicity of the i/o and api. although it is indeed painful to work with vb, the advantages far offset the problems. (i've secretly implemented some macros in my unit, and it's since sped up workflow by a whole bunch without encountering any problems ^_-)

regarding algos, i think the best way to do work is just to get down and try out what you think works, not much point thinking any more. i believe your simple (and not necessarily greedy) algo will actually satisify all the constraints, just include a few more features like committments, preferred groupings, medical statuses, etc. and let the computer do the work. don't bother optimising; no point spending much more time on what will run only at most a few times a month.

 
At 5:33 PM, Blogger 7-8 said...

This is great!

In future, if anybody asks what I'm doing for a living, I could simply cut and paste this link and it would explain it perfectly.

Anybody realises that we pay a 5 figure sum annually for the usage of CPLEX?

As always, modelling is the difficult part. It's not unusual to go to our internal customer who wants us to automate a schedule, and he will give what he thinks is the complete set of requirements, only for us to go back to him with a solution and he says, "oh, you can't have that either because..." and we feel like punching him in the face.

Sorry for ranting on your blog but an example of potential pitfalls.

 

Post a Comment

<< Home