Teacher time schedule algorithm

2019-03-07 19:37发布

This is a problem I've had on my mind for a long time. Being the son of a teacher and a programmer, it occurred to me early on... but I still haven't found a solution for it.

So this is the problem. One needs to create a time schedule for a school, using some constraints. These are generally divided in two categories:

Sanity Checks

  • A teacher cannot teach two classes at the same time
  • A student cannot follow two lessons at the same time
  • Some teachers must have at least one day off during the week
  • All the days of the week should be covered by the time table
  • Subject X must have exactly so-and-so hours each week
  • ...

Preferences

  • Each teacher's schedule should be as compact as possible (i.e. the teacher should work all hours for the day in a row with no pauses if possible)
  • Teachers that have days off should be able to express a preference on which day
  • Teachers that work part-time should be able to express a preference whether to work in the beginning or the end of the school day.
  • ...

Now, after a few years of not finding a solution (and learning a thing or two in the meanwhile...), I realized that this smells like a NP-hard problem.

Is it proven as NP-hard?

Does anyone have an idea on how to crack this thing?

Looking at this question made me think about this problem, and whether genetic algorithms would be usable in this case. However it would be pretty hard to mutate possibilities while maintaining the sanity check rules. Also it's not clear to me how to distinguish incompatible requirements.


A small addendum to better specify the problem. This is applied to Italian school style classrooms where all students are associated in different classes (for example: year 1 section A) and the teachers move between classes. All students of the same class have the same schedule, and have no choice over which lessons to attend.

12条回答
爷、活的狠高调
2楼-- · 2019-03-07 19:51

I've tackled similar planning/scheduling problems in the past and the AI technique that is often best suited for this class of problem is "Constraint Based Reasoning".

It's basically a brute force method like Laurenty suggested, but the approach involves applying constraints in an efficient order to cause the infeasible solutions to fail fast - to minimise the computation required.

Googling "Constraint Based Reasoning" brings up a lot of resources on the technique and its application to scheduling problems.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-03-07 19:55

i see that this problem can be solved by Prolog program by connecting it to a database and the program can make the schedule given a set of constraints read abt "Constraint satisfaction Problem prolog"

查看更多
Animai°情兽
4楼-- · 2019-03-07 19:58

This reminds me of this blog post about scheduling a conference, with a video explanation here.

How I would do it:

Have the population include two things:

  • Who teaches what class (I expect the teachers to teach one subject).
  • What a class takes on a specific time slot.

This way we can't have conflicts (a teacher in 2 places, or a class having two subjects at the same time).

The fitness function would include:

  • How many time slots each teacher gives per week.
  • How many time slots a teacher has on the same day (They can't have a full day of teaching, this too must be balanced).
  • How many time slots of the same subject a class has on the same day (They can't have a full day of math!).

Maybe take the standard deviation for all of them since they should be balanced.

查看更多
相关推荐>>
5楼-- · 2019-03-07 19:58

I think you might be missing some constraints.

One would prefer where possible to have teachers scheduled to classes for which they are certified.

One would suspect that the classes that are requested, and the expected headcount in each would be significant.

I think the place to start would be to list all of your constraints, figure out a data structure to represent them.

Then create some sort of engine to that builds a trial solution, then evaluates it for fitness according to the constraints.

You could then throw the fun genetic algorithms part at it, and see if you can get the fitness to increase over time as the genes mix.

Start with a small set of constraints, and increase them as you see success (if you see success)

There might be a way to take the constraints and shoehorn them together with something like a linear programming algorithm.

I agree. It sounds like a fun challenge

查看更多
Anthone
6楼-- · 2019-03-07 20:04

I am one of the developer that works on the scheduler part of a student information system. During our original approach of the scheduling problem, we researched genetic algorithms to solve constraint satisfaction problems, and even though we were successful initially, we realized that there was a less complicated solution to the problem (after attending a school scheduling workshop)

Our current implementation works great, and uses brute force with smart heuristics to get a valid schedule in a short amount of time. The master schedule (assignment of the classes to the teachers) is first built, taking in consideration all the constraints that each teacher has while minimizing the possibility of conflicts for the students (based of their course requests). The students are then scheduled in the classes using the same method.

Doing this allows you to have the machine build a master schedule first, and then have a human tweak it if needed.

The scheduler current implementation is written in perl, but other options we visited early on were Prolog and CLIPS (expert system)

查看更多
Melony?
7楼-- · 2019-03-07 20:04

Good luck. Being the son of a father with this sort of problem is what took me to the research group that I ended up in ...


When I was a kid my father scheduled match officials in a local sports league, this had a similarly long list of constraints and I tried to write something to help. When I got to University I even used it as my final year project eventually settling on a Monte Carlo implementation (using a Simulated Annealing model).

The basic idea is that if it's not NP, it's pretty close, so rather than assuming there is a solution, I would set out to find the best within a given timeframe. I would weight all the constraints with costs for breaking them: sanity checks would have huge costs, the preferences would have lower costs (but increasing for more breaks, so breaking it once would be less than half the cost of breaking it twice).

The basic idea is that I started with a 'random' solution and costed it; then made changes by swapping a small number of assignments, re-valued it and then, probalistically accepted or declined the change.

After thousands of iterations you inch closer to an acceptable solution.

Believe me, though, that this class of problems has research groups churning out PhDs so you're in very good company.

You might also find some interest in the Linear Programming arena, e.g. simplex and so on.

查看更多
登录 后发表回答