Appointments scheduling algorithm [duplicate] - algorithm

This question already has answers here:
Best Fit Scheduling Algorithm
(4 answers)
Closed 9 years ago.
I have the following problem to solve, perhaps you could give me some ideas regarding the problem - solving approach:
There are:
8 classrooms
16 teachers
201 students
149 parents
241 appointments (most of the parents need to see multiple teachers, either because the have more than one child or because one child is being taught by two or more teachers)
2 days.
For each day:
7 classrooms are available for 20 hours per day.
1 classroom is available for 10 hours per day.
Each teacher occupies one classroom
Each appointment lasts for one hour
Further constrains:
- For each parent, all appointments must be sequential (having at maximum 1 hour pause)
- Each parent should have to visit the school one day only.
- For each teacher, all appointments within the day must be sequential (having at maximum 2 hours pause)
- Out of the 16 teachers, 3 can only be present one of the two days.
I'm trying to find an approach to produce the appointments schedule, obviously without having to calculate all possible variations until all the requirements are met. Any ideas?

You need to define your constraints a bit more; i.e., what is the relationship between students and teachers? What is the relationship between students and parents? Do parents have to have individual appointments, or are the parents of a single student allowed to meet with a single teacher together?
I'd approach this with an initial (in testing) naive approach; just pick your highest constrained resource (looks like the teachers that can only be present for one of the two days), schedule those using the first available resources, and then continue through the set of resources, scheduling them using the first available resources that match their constraints and see if you can schedule the entire set. If not, you need to find your limiting resource(s), and apply some heuristics to your matching to find the best way to optimize those limited resources.
It's a bit of a tricky problem; have fun!

Take a look at the curriculum course track of ITC2007 and it's implementation in Drools Planner or unitime. Both of them use meta-heuristics such as tabu search and simulated annealing.

Related

Algorithm development and optimization

I have this problem:
You need to develop a meal regime based on the data entered by the user. We have a database with the meals and their prices (meals also have a mark whether they are breakfast, cause on breakfast we eat smth different from lunch and dinner most often). The input receives the amount of money (Currency is not important) and the number of days. At the output, we must get a meal regime for a given number of days. Conditions:
Final price does not differ from the given one by more than 3%.
meals mustn't repeat more than once every 5 days.
I found this not effective solution: We are looking for an average price per day = amount of money / number of days. Then, until we reach the given number of days, we iterate throught each breakfast, then lunch and dinner (3 for loops, 2 are nested) and if price is not too different, then we end the search and add this day to the result list. So the design now looks like this:
while(daysCounter < days){
for(){
for(){
for(){
}
}
It looks scary, although there is not a lot of data (number of meals is about 150). There are thoughts that it is possible to find a more effective solution. Also i think about dynamic programming, but so far there are no ideas how to implement it.
Dynamic programming won't work because a necessary part of your state is the meals from the last 5 days. And the number of possibilities for that are astronomical.
However it is likely that there are many solutions, not just a few. And that it is easy to find a working solution by being greedy. Also that an existing solution can be improved fairly easily.
So I'd solve it like this. Replace days with an array of meals. Take the total you want to spend. Divide it up among your meals, in proportion to the median price of the options for that meal. (Breakfast is generally cheaper than dinner.) And now add up that per meal cost to get running totals.
And now for each meal choose the meal you have not had in the last 5 days that brings the running total of what has been spent as close as possible to the ideal total. Choose all of your meals, one at a time.
This is the greedy approach. Normally, but not always, it will come fairly close to the target.
And now, to a maximum of n tries or until you have the target within 3%, pick a random meal, consider all options that are not eaten within the last or next 5 days, and randomly pick one (if any such options exist) that brings the overall amount spent closer to the target.
(For a meal plan that is likely to vary more over a long period, I'd suggest trying simulated annealing. That will produce more interesting results, but it will also take longer.)

How to set OptaPlanner Constraints for school timetabling in my below case?

I am a beginner of OptaPlanner I have to execute the example but our requirement is different as below.
In our case assigning lesson as a different time slot, for example in std-10 have a total of 4 hours and its time slot is 1 hour per lecture and subjects are fixed, and same 4 hours in std-7 have 5 lecture and also its subjects are fixed and its time slot is 45 minutes so how I can manage it using constraint? Is there any example to refer it to get some idea? Please help!
Thanks in advance!
There's basically two approaches:
Like the conference scheduling example in optaplanner-examples (zip download): create 2 LessonTypes and create separate timeslots for each LessonType. Then add a hard constraint - or even a #ValueRangeProvider on entity like that example does - to never put a Lesson of LessonType "Lab (2 hours)" in a timeslot of LessonType "conf talk (1 hour)". It does a similar approach for rooms.
This works well if your room+timeslot combinations are assigned to a LessonType (not a lesson) in advance (before solving), otherwise it doesn't. For conference scheduling, that is always the case.
Like the maintenance scheduling quickstart (optaplanner-quickstarts on github) use a timegrain pattern (explained in docs) for maximum flexibility, but at a higher complexity cost.

How to design an algorithm to put elements into groups with constraints?

I was given a task of putting students into groups (to prepare a coding camp), but with several constraints. Though I've finished the task by hand, I'd like to know is there already exist some algorithms for tasks like this, or how can I design such an algorithm.
Background: 40 students in total, with these attributes:
gender: F/M
grade: Year 1/2
school: School 1/School 2/...
early assessment result: Rank from 1 to 40
Constraints: All of them needs to be satisfied.
Exactly 4 people per group
Each group needs to have at least a girl
Each group needs to have at least a Year 2 student
4 group members needs to come from 4 different schools
Each group needs to have at least a student who ranked top 10 in early assessment
What I'm expecting:
The Best: An existing algorithm/program for these kind of problems
Or, An algorithm for this specific problem
Or at least, Some ideas of creating an algorithm for this specific problem
My thoughts:
Since I've successed in making groups by hand, I know that such a solution indeed exists for my current dataset. But if I need an algorithm to find a solution for me, it should first try to check whether a solution even exists, by check if the number of girl / Year 2 students is greater than 10 (with pigeonhole principle), and some other conditions. And obviously, Constraint 5 is the easiest, and can provide a base solution for the rest. However, I still can not find a systematic way of doing it. Perhaps bruteforce and randomization can help? I'm not sure.
And sorry, since the data is confidential, I can not post it.
Update: After consulting a friend, here is a possible method:
First put the top 1 to 10 into 10 different groups.
Then iterate through groups. If the only person in the group is a boy/girl, try to add a girl/boy from a different school.
Then the problem size is reduced from 2^40 to 2^20, making bruthforce a viable solution.

A specific scheduling algorithm

The question I have concerns a hobby project that I'm working on to help out my wife with her work.
I realize that the problem I'm facing is quite similar to what's been answered on SO in numerous threads. However, I can't seem to find any thread that would address one little specific difference that I need to count in.
Here's a detailed description of the problem:
A teacher has numerous students that she teaches. Each student needs to have two lessons every week at least two days apart (i.e. Monday + Wednesday, Tuesday + Thursday etc.). The lessons are individual meaning there's only one student and the teacher in a class at a time. The teacher needs to have exactly one lunch break every day. The lunch break can be any time between two classes - the only condition is: a day cannot start or end in a lunch break. Each student provides their availability during a week (a list of possible time slots they can attend the class).
So far, this looks like a "regular" scheduling problem that there's bunch of material available online on.
But here's the catch: students are in different age meaning their lesson takes either 30 or 45 minutes. Younger students' lesson takes 30 minutes and olders' - 45 minutes. The goal of the algorithm is to find the optimal weekly schedule for the teacher. By optimal I mean a schedule where the teacher needs to spend least amount of time in school - all lessons back to back with no need for the teacher to wait for another student.
My first attempt was to come with all possible permutations of students' classes, lunch breaks and week days but for a 3 student schedule I came up with 13! permutations (that's roughly around 6 bln permutations). Here's why 13:
3 students - 2 classes each
4 lunch breaks (a 4 day week to keep the numbers small)
3 day breaks (a "night" so to speak)
The above gave me 13 elements to try in different permutations. However, after calculating the factorial I gave that up - 6 bln permutations will not be tried in any reasonable time on a "regular" machine. And that's just counting 3 students, the real-life data will be closer to 9 or 10. Obviously, the nonsense permutations (2 "nights" in a row, 2 classes for the same student on the same day and so on) would be thrown right away but still...
That was when I realized I'm not going to do this inventing the wheel by myself.
I did some research and came across Hopcroft-Karp algorithm. However I don't think it can be applied in a mixed timespan slots scenario (30/45 minute lessons). Am I wrong? Then I found some info on genetic algorithms. However, again I am not sure if they can take the mixed timespan condition into account?
I would greatly appreciate any pointers as to which directions my research should go.

Algorithm to find the best possible available times

Here is my scenario,
I run a Massage Place which offers various type of massages. Say 30 min Massage, 45 min massage, 1 hour massage, etc. I have 50 rooms, 100 employees and 30 pieces of equipment.When a customer books a massage appointment, the appointment requires 1 room, 1 employee and 1 piece of equipment to be available.
What is a good algorithm to find available resources for 10 guests for a given day
Resources:
Room – 50
Staff – 100
Equipment – 30
Business Hours : 9AM - 6PM
Staff Hours: 9AM- 6PM
No of guests: 10
Services
5 Guests- (1 hour massages)
3 Guests - (45mins massages)
2 Guests - (1 hour massage).
They are coming around the same time. Assume there are no other appointment on that day
What is the best way to get ::
Top 10 result - Fastest search which meets all conditions gets the top 10 result set. Top ten is defined by earliest available time. 9 – 11AM is best result set. 9 – 5pm is not that good.
Exhaustive search (Find all combinations) - all sets – Every possible combination
First available met (Only return the first match) – stop after one of the conditions have been met
I would appreciate your help.
Thanks
Nick
First, it seems the number of employees, rooms, and equipment are irrelevant. It seems like you only care about which of those is the lowest number. That is your inventory. So in your case, inventory = 30.
Next, it sounds like you can service all 10 people at the same time within the first hour of business. In fact, you can service 30 people at the same time.
So, no algorithm is necessary to figure that out, it's a static solution. If you take #Mario The Spoon's advice and weight the different duration massages with their corresponding profits, then you can start optimizing when you have more than 30 customers at a time.
Looks like you are trying to solve a problem for which there are quite specialized software applications. If your problem is small enough, you could try to do a brute force approach using some looping and backtracking, but as soon as the problem becomes too big, it will take too much time to iterate through all possibilities.
If the problem starts to get big, look for more specialized software. Things to look for are "constraint based optimization" and "constraint programming".
E.g. the ECLIPSe tool is an open-source constraint programming environment. You can find some examples on http://eclipseclp.org/examples/index.html. One nice example you can find there is the SEND+MORE=MONEY problem. In this problem you have the following equation:
S E N D
+ M O R E
-----------
= M O N E Y
Replace every letter by a digit so that the sum is correct.
This also illustrates that although you can solve this brute-force, there are more intelligent ways to solve this (see http://eclipseclp.org/examples/sendmore.pl.txt).
Just an idea to find a solution:
You might want to try to solve it with a constraint satisfaction problem (CSP) algorithm. That's what some people do if they have to solve timetable problems in general (e.g. room reservation at the University).
There are several tricks to improve CSP performance like forward checking, building a DAG and then do a topological sort and so on...
Just let me know, if you need more information about CSP :)

Resources