Teacher time schedule algorithm

安稳与你 提交于 2019-12-02 14:10:41

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)

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

This is a mapping problem: you need to map to every hour in a week and every teacher an activity (teach to a certain class or free hour ).

Split the problem:

  1. Create the list of teachers, classes and preferences then let the user populate some of the preferences on a map to have as a starting point.
  2. Randomly take one element from the list and put it at a random free position on the map if it doesn't cross any sanity checks until the list is empty. If at any certain iteration you can't place an element on the map without crossing a sanity check shift two positions on the map and try again.
  3. When the map is filled, try shifting positions on the map to optimize the result.

In steps 2 and 3 show each iteration to the user: items left in the list, positions on the map and the next computed move and let the user intervene.

I did not try this, but this would be my initial approach.

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.

Answering my own question:

The FET project mentioned by gnud uses this algorithm:

Some words about the algorithm: FET uses a heuristical algorithm, placing the activities in turn, starting with the most difficult ones. If it cannot find a solution it points you to the potential impossible activities, so you can correct errors. The algorithm swaps activities recursively if that is possible in order to make space for a new activity, or, in extreme cases, backtracks and switches order of evaluation. The important code is in src/engine/generate.cpp. Please e-mail me for details or join the mailing list. The algorithm mimics the operation of a human timetabler, I think.

Link


Following up the "Constraint Based Reasoning" lead by Stringent Software on Wikipedia lead me to these pages which have an interesting paragraph:

Solving a constraint satisfaction problem on a finite domain is an NP-complete problem in general. Research has shown a number of polynomial-time subcases, mostly obtained by restricting either the allowed domains or constraints or the way constraints can be placed over the variables. Research has also established relationship of the constraint satisfaction problem with problems in other areas such as finite model theory and databases.

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.

Andrew

I'm not sure if this covers the same ground as @Stringent Software's answer (as the name is slightly different), but I have a couple of very good friends who are researching the area of Constraint Programming. Creating timetables is one application of their research.

Dr Chris Jefferson created a program called Minion that you can download from SourceForge, and is a very fast brute force constraint problem solver written in C++

One of the worst open source webpages ever, but the project looks promising: http://www.lalescu.ro/liviu/fet/

A web-based aproach:
phpScheduleIt (not school-specific)

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.

Genetic Algorithms are very well suited to problems such as this. Once you come up with a decent representation of the chromosome (in this case, probably a vector representing all of the available class slots) you're most of the way there.

Don't worry about maintaining sanity checks during the mutation phase. Mutation is random. Sanity and preference checks both belong in the selection phase. A failed sanity check would drastically lower the fitness of an individual, while a failed preference would only mildly lower the fitness.

Incompatible requirements are a different problem altogether. If they're completely incompatible, you'll get a population that doesn't converge on anything useful.

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.

Yes, I think this is NP complete - or at least to find the optimal solution is NP complete.

I worked on a similar problem in college when i told a friend's father (who was a teacher) that I could solve his scheduling problems for him if he did not find a suitable program for it (this was back in 1990 or so)

I had no idea what I got myself into. Luckily for us all I had to do was find one solution that fit the constraints. But in my testing I was always worried about determining IF there was a solution at all. He never had too many constraints and the program used different heuristics and back tracking. It was a lot of fun.

I think Bill Gates also worked on a system like this in high school or college for his high school. Not sure though.

Good luck. All my notes are gone and I never got around to implementing a solution that I could market. It was a specialty project that I re-coded as I learned new languages (Basic, Scheme, C, VB, C++)

Have fun with it

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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!