So.. someone recently asked me to make a timetable for them and I agreed. When I sat down to do it I realized it was harder than I thought. It's just a timetable to give shifts to 4 people for either day or night.
I thought of something like this:
for Monday to Saturday {
for(i=0;i<people.length;i++){
if (person[i].available()){
person.worksDay()
person is now not available.
}
}
for(i=0;i<people.length;i++){
if (person[i].available()){
person[i].worksNight()
person[i] is now not available.
}
}
}
So the idea behind this algorithm is that for each day, a person is assigned to a day or night shift. A person is available if they haven't JUST worked a shift and they aren't on holidays. It's for Monday to Saturday. As you can probably tell, given persons A,B,C,D the assignment would look like this (if no one is on holidays):
Mon A B
Tue C D
Wed A B
Th C D
Fri A B
Sat C D
This works I guess but it's a bit obvious. The person who asked me wanted to see different options. Is there a better way about doing this to see more than just this option? Or is there even a program that does this for you?
Brute force is pointless.
Use a framework such as Drools Planner, Choco, JGap, cpsolver, ... to solve it for you. Some of those frameworks (including Drools Planner) allow you to easily switch optimization algorithms and include tools to determine the best one to use for your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With