07.12.2019

School Timetable Generator Php

School Timetable Generator Php Rating: 5,1/10 2218 votes
Active4 years ago
  1. Timetable For School
  2. School Timetable Generator Software
  3. Mcmaster Mosaic

I've been wondering if there are known solutions for algorithm of creating a school timetable. Basically, it's about optimizing 'hour-dispersion' (both in teachers and classes case) for given class-subject-teacher associations. We can assume that we have sets of classes, lesson subjects and teachers associated with each other at the input and that timetable should fit between 8AM and 4PM.

I guess that there is probably no accurate algorithm for that, but maybe someone knows a good approximation or hints for developing it.

Fabien
5,2135 gold badges29 silver badges54 bronze badges
candcand

Web Application for Automatic Time Table Generation. Generate timetables for schools and colleges without any hindrance, directly from raw schedule. While generating a. School scheduling software for Mac, PC, tablet and phone. Create master school schedule and share. Free sign up. Unique automatic timetable generator. Generate a Submit Button from PHP in HTML Table - 3 replies How to print out only one row at a time from a database in php. - 1 reply how to display calendar through php in html table - 2 replies.

1,7282 gold badges13 silver badges13 bronze badges

16 Answers

This problem is NP-Complete!
In a nutshell one needs to explore all possible combinations to find the list of acceptable solutions. Because of the variations in the circumstances in which the problem appears at various schools (for example: Are there constraints with regards to classrooms?, Are some of the classes split in sub-groups some of the time?, Is this a weekly schedule? etc.) there isn't a well known problem class which corresponds to all the scheduling problems. Maybe, the Knapsack problem has many elements of similarity with these problems at large.

A confirmation that this is both a hard problem and one for which people perennially seek a solution, is to check this (long) list of (mostly commercial) software scheduling tools

Because of the big number of variables involved, the biggest source of which are, typically, the faculty member's desires ;-).., it is typically impractical to consider enumerating all possible combinations. Instead we need to choose an approach which visits a subset of the problem/solution spaces.
- Genetic Algorithms, cited in another answer is (or, IMHO, seems) well equipped to perform this kind of semi-guided search (The problem being to find a good evaluation function for the candidates to be kept for the next generation)
- Graph Rewriting approaches are also of use with this type of combinatorial optimization problems.

Rather than focusing on particular implementations of an automatic schedule generator program, I'd like to suggest a few strategies which can be applied, at the level of the definition of the problem.
The general rationale is that in most real world scheduling problems, some compromises will be required, not all constraints, expressed and implied: will be satisfied fully. Therefore we help ourselves by:

  • Defining and ranking all known constraints
  • Reducing the problem space, by manually, providing a set of additional constraints.
    This may seem counter-intuitive but for example by providing an initial, partially filled schedule (say roughly 30% of the time-slots), in a way that fully satisfies all constraints, and by considering this partial schedule immutable, we significantly reduce the time/space needed to produce candidate solutions.
    Another way additional constraints help is for example 'artificially' adding a constraint which prevent teaching some subjects on some days of the week (if this is a weekly schedule..); this type of constraints results in reducing the problem/solution spaces, without, typically, excluding a significant number of good candidates.
  • Ensuring that some of the constraints of the problem can be quickly computed. This is often associated with the choice of data model used to represent the problem; the idea is to be able to quickly opt-for (or prune-out) some of the options.
  • Redefining the problem and allowing some of the constraints to be broken, a few times, (typically towards the end nodes of the graph). The idea here is to either remove some of constraints for filling-in the last few slots in the schedule, or to have the automatic schedule generator program stop shy of completing the whole schedule, instead providing us with a list of a dozen or so plausible candidates. A human is often in a better position to complete the puzzle, as indicated, possibly breaking a few of the contraints, using information which is not typically shared with the automated logic (eg 'No mathematics in the afternoon' rule can be broken on occasion for the 'advanced math and physics' class; or 'It is better to break one of Mr Jones requirements than one of Ms Smith .. ;-) )

In proof-reading this answer , I realize it is quite shy of providing a definite response, but it none the less full of practical suggestions. I hope this help, with what is, after all, a 'hard problem'.

mjvmjv
61.4k12 gold badges91 silver badges144 bronze badges

It's a mess. a royal mess. To add to the answers, already very complete, I want to point out my family experience. My mother was a teacher and used to be involved in the process.

Turns out that having a computer to do so is not only difficult to code per-se, it is also difficult because there are conditions that are difficult to specify to a pre-baked computer program. Examples:

  • a teacher teaches both at your school and at another institute. Clearly, if he ends the lesson there at 10.30, he cannot start at your premises at 10.30, because he needs some time to commute between the institutes.
  • two teachers are married. In general, it's considered good practice not to have two married teachers on the same class. These two teachers must therefore have two different classes
  • two teachers are married, and their child attends the same school. Again, you have to prevent the two teachers to teach in the specific class where their child is.
  • the school has separate facilities, like one day the class is in one institute, and another day the class is in another.
  • the school has shared laboratories, but these laboratories are available only on certain weekdays (for security reasons, for example, where additional personnel is required).
  • some teachers have preferences for the free day: some prefer on Monday, some on Friday, some on Wednesday. Some prefer to come early in the morning, some prefer to come later.
  • you should not have situations where you have a lesson of say, history at the first hour, then three hours of math, then another hour of history. It does not make sense for the students, nor for the teacher.
  • you should spread the arguments evenly. It does not make sense to have the first days in the week only math, and then the rest of the week only literature.
  • you should give some teachers two consecutive hours to do evaluation tests.

As you can see, the problem is not NP-complete, it's NP-insane.

So what they do is that they have a large table with small plastic insets, and they move the insets around until a satisfying result is obtained. They never start from scratch: they normally start from the previous year timetable and make adjustments.

Stefano BoriniStefano Borini
77.1k73 gold badges259 silver badges379 bronze badges

The International Timetabling Competition 2007 had a lesson scheduling track and exam scheduling track. Many researchers participated in that competition. Lots of heuristics and metaheuristics were tried, but in the end the local search metaheuristics (such as Tabu Search and Simulated Annealing) clearly beat other algorithms (such as genetic algorithms).

Take a look at the 2 open source frameworks used by some of the finalists:

  • JBoss OptaPlanner (Java, open source)
  • Unitime (Java, open source) - more for universities
Geoffrey De SmetGeoffrey De Smet
16.2k5 gold badges45 silver badges93 bronze badges

One of my half-term assignments was an genetic-algorithm school table generation.

Whole table is one 'organism'. There were some changes and caveats to the generic genetic algorithms approach:

  • Rules were made for 'illegal tables': two classes in the same classroom, one teacher teaching two groups at the same time etc. These mutations were deemed lethal immediately and a new 'organism' was sprouted in place of the 'deceased' immediately. The initial one was generated by a series of random tries to get a legal (if senseless) one. Lethal mutation wasn't counted towards count of mutations in iteration.

  • 'Exchange' mutations were much more common than 'Modify' mutations. Changes were only between parts of the gene that made sense - no substituting a teacher with a classroom.

  • Small bonuses were assigned for bundling certain 2 hours together, for assigning same generic classroom in sequence for the same group, for keeping teacher's work hours and class' load continuous. Moderate bonuses were assigned for giving correct classrooms for given subject, keeping class hours within bonds (morning or afternoon), and such. Big bonuses were for assigning correct number of given subject, given workload for a teacher etc.

  • Teachers could create their workload schedules of 'want to work then', 'okay to work then', 'doesn't like to work then', 'can't work then', with proper weights assigned. Whole 24h were legal work hours except night time was very undesired.

  • The weight function.. oh yeah. The weight function was huge, monstrous product (as in multiplication) of weights assigned to selected features and properties. It was extremely steep, one property easily able to change it by an order of magnitude up or down - and there were hundreds or thousands of properties in one organism. This resulted in absolutely HUGE numbers as the weights, and as a direct result, need to use a bignum library (gmp) to perform the calculations. For a small testcase of some 10 groups, 10 teachers and 10 classrooms, the initial set started with note of 10^-200something and finished with 10^+300something. It was totally inefficient when it was more flat. Also, the values grew a lot wider distance with bigger 'schools'.

  • Computation time wise, there was little difference between a small population (100) over a long time and a big population (10k+) over less generations. The computation over the same time produced about the same quality.

  • The calculation (on some 1GHz CPU) would take some 1h to stabilize near 10^+300, generating schedules that looked quite nice, for said 10x10x10 test case.

  • The problem is easily paralellizable by providing networking facility that would exchange best specimens between computers running the computation.

The resulting program never saw daylight outside getting me a good grade for the semester. It showed some promise but I never got enough motivation to add any GUI and make it usable to general public.

SF.SF.
7,6068 gold badges58 silver badges93 bronze badges

This problem is tougher than it seems.

As others have alluded to, this is a NP-complete problem, but let's analyse what that means.

Basically, it means you have to look at all possible combinations.

But 'look at' doesn't tell you much what you need to do.

Generating all possible combinations is easy. It might produce a huge amount of data, but you shouldn't have much problems understanding the concepts of this part of the problem.

The second problem is the one of judging whether a given possible combination is good, bad, or better than the previous 'good' solution.

For this you need more than just 'is it a possible solution'.

For instance, is the same teacher working 5 days a week for X weeks straight? Even if that is a working solution, it might not be a better solution than alternating between two people so that each teacher does one week each. Oh, you didn't think about that? Remember, this is people you're dealing with, not just a resource allocation problem.

Even if one teacher could work full-time for 16 weeks straight, that might be a sub-optimal solution compared to a solution where you try to alternate between teachers, and this kind of balancing is very hard to build into software.

To summarize, producing a good solution to this problem will be worth a lot, to many many people. Hence, it's not an easy problem to break down and solve. Be prepared to stake out some goals that aren't 100% and calling them 'good enough'.

Lasse Vågsæther KarlsenLasse Vågsæther Karlsen
304k87 gold badges541 silver badges731 bronze badges

UPDATE: from comments .. should have heuristics too!

I'd go with Prolog .. then use Ruby or Perl or something to cleanup your solution into a prettier form.

I am (still) in the process of doing something similar to this problem but using the same path as I just mentioned. Prolog (as a functional language) really makes solving NP-Hard problems easier.

Reed DebaetsReed Debaets
2321 gold badge4 silver badges18 bronze badges

Genetic algorithms are often used for such scheduling.

Found this example (Making Class Schedule Using Genetic Algorithm) which matches your requirement pretty well.

Christian VChristian V

Here are a few links I found:

School timetable - Lists some problems involved

NiyazNiyaz
30.1k52 gold badges139 silver badges178 bronze badges

My timetabling algorithm, implemented in FET (Free Timetabling Software, http://lalescu.ro/liviu/fet/ , a successful application):

The algorithm is heuristic. I named it 'recursive swapping'.

Input: a set of activities A_1..A_n and the constraints.

Output: a set of times TA_1..TA_n (the time slot of each activity. Rooms are excluded here, for simplicity). The algorithm must put each activity at a time slot, respecting constraints. Each TA_i is between 0 (T_1) and max_time_slots-1 (T_m).

Constraints:

C1) Basic: a list of pairs of activities which cannot be simultaneous (for instance, A_1 and A_2, because they have the same teacher or the same students);

C2) Lots of other constraints (excluded here, for simplicity).

The timetabling algorithm (which I named 'recursive swapping'):

  1. Sort activities, most difficult first. Not critical step, but speeds up the algorithm maybe 10 times or more.
  2. Try to place each activity (A_i) in an allowed time slot, following the above order, one at a time. Search for an available slot (T_j) for A_i, in which this activity can be placed respecting the constraints. If more slots are available, choose a random one. If none is available, do recursive swapping:

    a. For each time slot T_j, consider what happens if you put A_i into T_j. There will be a list of other activities which don't agree with this move (for instance, activity A_k is on the same slot T_j and has the same teacher or same students as A_i). Keep a list of conflicting activities for each time slot T_j.

    b. Choose a slot (T_j) with lowest number of conflicting activities. Say the list of activities in this slot contains 3 activities: A_p, A_q, A_r.

    Download This page contains the list of device drivers for HP Compaq dc5100 MT(PM213AV). To download the proper driver, first choose your operating system, then find your device name and click the download button. Download the latest driver, firmware, and software for your HP Compaq dc5100 Small Form Factor PC.This is HP's official website to download drivers free of cost for your HP Computing and Printing products for Windows and Mac operating system. Aug 17, 2015  is there any drivers for hp compaq dc5100 sff for windows 7 32bit (plz help). Yesterday i installed the video driver given in the link and it. Hp compaq dc5100 sff drivers for windows 7; Hp.

    c. Place A_i at T_j and make A_p, A_q, A_r unallocated.

    d. Recursively try to place A_p, A_q, A_r (if the level of recursion is not too large, say 14, and if the total number of recursive calls counted since step 2) on A_i began is not too large, say 2*n), as in step 2).

    e. If successfully placed A_p, A_q, A_r, return with success, otherwise try other time slots (go to step 2 b) and choose the next best time slot).

    f. If all (or a reasonable number of) time slots were tried unsuccessfully, return without success.

    g. If we are at level 0, and we had no success in placing A_i, place it like in steps 2 b) and 2 c), but without recursion. We have now 3 - 1 = 2 more activities to place. Go to step 2) (some methods to avoid cycling are used here).

A5C1D2H2I1M1N2O1R2T1
159k22 gold badges312 silver badges398 bronze badges
Liviu LalescuLiviu Lalescu

I have designed commercial algorithms for both class timetabling and examination timetabling. For the first I used integer programming; for the second a heuristic based on maximizing an objective function by choosing slot swaps, very similar to the original manual process that had been evolved. They main things in getting such solutions accepted are the ability to represent all the real-world constraints; and for human timetablers to not be able to see ways to improve the solution. In the end the algorithmic part was quite straightforward and easy to implement compared with the preparation of the databases, the user interface, ability to report on statistics like room utilization, user education and so on.

PermaquidPermaquid
1,8121 gold badge14 silver badges13 bronze badges

This paper describes the school timetable problem and their approach to the algorithm pretty well: 'The Development of SYLLABUS—An Interactive, Constraint-Based Scheduler for Schools and Colleges.'[PDF]

The author informs me the SYLLABUS software is still being used/developed here: http://www.scientia.com/uk/

LeftiumLeftium
8,5336 gold badges47 silver badges73 bronze badges

I work on a widely-used scheduling engine which does exactly this. Yes, it is NP-Complete; the best approaches seek to approximate an optimal solution. And, of course there are a lot of different ways to say which one is the 'best' solution - is it more important that your teachers are happy with their schedules, or that students get into all their classes, for instance?

The absolute most important question you need to resolve early on is what makes one way of scheduling this system better than another? That is, if I have a schedule with Mrs Jones teaching Math at 8 and Mr Smith teaching Math at 9, is that better or worse than one with both of them teaching Math at 10? Is it better or worse than one with Mrs Jones teaching at 8 and Mr Jones teaching at 2? Why?

The main advice I'd give here is to divide the problem up as much as possible - maybe course by course, maybe teacher by teacher, maybe room by room - and work on solving the sub-problem first. There you should end up with multiple solutions to choose from, and need to pick one as the most likely optimal. Then, work on making the 'earlier' sub-problems take into account the needs of later sub-problems in scoring their potential solutions. Then, maybe work on how to get yourself out of painted-into-the-corner situations (assuming you can't anticipate those situations in earlier sub-problems) when you get to a 'no valid solutions' state.

A local-search optimization pass is often used to 'polish' the end answer for better results.

Timetable generator polyu

Note that typically we are dealing with highly resource-constrained systems in school scheduling. Schools don't go through the year with a lot of empty rooms or teachers sitting in the lounge 75% of the day. Approaches which work best in solution-rich environments aren't necessarily applicable in school scheduling.

Tom DibbleTom Dibble

Generally, constraint programming is a good approach to this type of scheduling problem. A search on 'constraint programming' and scheduling or 'constraint based scheduling' both within stack overflow and on Google will generate some good references. It's not impossible - it's just a little hard to think about when using traditional optimization methods like linear or integer optimization. One output would be - does a schedule exist that satisfies all the requirements? That, in itself, is obviously helpful.

Good luck !

GremboGrembo

You can takle it with genetic algorithms, yes. But you shouldn't :). It can be too slow and parameter tuning can be too timeconsuming etc.

There are successful other approaches. All implemented in open source projects:

  • Constraint based approach
    • Implemented in UniTime (not really for schools)
    • You could also go further and use Integer programming. Successfully done at Udine university and also at University Bayreuth (I was involved there) using the commercial software (ILOG CPLEX)
    • Rule based approach with heuristisc - See Drools planner
  • Different heuristics - FET and my own

See here for a timetabling software list

Community
KarussellKarussell
12.3k11 gold badges77 silver badges167 bronze badges

I think you should use genetic algorithm because:

  • It is best suited for large problem instances.
  • It yields reduced time complexity on the price of inaccurate answer(Not the ultimate best)
  • You can specify constraints & preferences easily by adjusting fitness punishments for not met ones.
  • You can specify time limit for program execution.
  • The quality of solution depends on how much time you intend to spend solving the program.

Also take a look at :a similar question and another one

Community
BetamooBetamoo
6,66120 gold badges65 silver badges105 bronze badges

I don't know any one will agree with this code but i developed this code with the help of my own algorithm and is working for me in ruby.Hope it will help them who are searching for it in the following code the periodflag ,dayflag subjectflag and the teacherflag are the hash with the corresponding id and the flag value which is Boolean.Any issue contact me....(-_-)

periodflag.each do k2,v2

user3218146

Not the answer you're looking for? Browse other questions tagged algorithmlanguage-agnosticnp or ask your own question.

QuickSlots: A web-based timetable management system

  • Light-Weight: The whole application, including all images,scripts andstylesheets, is only 1.35 MB uncompressed and just 714KB when compressed.

  • Fully automated installer: QuickSlots comes with a fully automated installer,meaning that the administrator just has to run the installer and does nothave to look into ANY PART OF THE SOURCE CODE AT ALL.

  • One-click total system backup and restore: Backup and restore settings anddatabases, even across different servers, just with a single click.

  • Generate ready-to-print timetable image snapshots.

  • Support for LDAP authentication.

User management:

Slots Configuration:

Timetable Allocation:

  • .setup.php-- Initial system setup.
  • .index.php-- Displays the timetable applying the provided filters, if any.
  • .login.php-- Provides interface and back end routines that handle user logins.
  • .logout.php-- Logs out the user when visited
  • .allocate.php-- Provides interface and back end routines for allocation of courses totime slots
  • .dean.php-- Homepage of dean level users, it provides interface and back endroutines to edit and save global settings. Access is restricted to deanlevel users.
  • .manage.php-- Provides interface and back end routines to manage departments, faculty,batches and rooms. Access is restricted to dean level users.
  • .faculty.php-- Homepage of HOD and faculty level users, provides interfaces toadd/delete courses. Access requires at least faculty level account.
  • .register.php-- Contains back end routines for user management. It is invoked bymanage.php and setup.php
  • .connect_db.php-- Initiates database connections. Required by all files that needs toperform database operations
  • .functions.php-- Contains various common helper routines used across most files
  • .courses.php-- Contains back end routines to add/delete courses. It is invoked byfaculty.php
  • .batches.php-- Contains back end routines to add/delete batches. It is invoked bymanage.php
  • .depts.php-- Contains back end routines to add/delete batches. It is invoked bymanage.php
  • .rooms.php-- Contains back end routines to add/delete batches. It is invoked bydean.php
  • .backup.php-- Contains back end routines to generate/restore backups, invoked bydean.php
  • .download.php-- Back end routines that call PhantomJS to generate printable timetablesnapshot images.
  • .jsgrid.js-- Client side script to render timetable grids
  • .jsform.js-- Handles all form submissions and validation that needs to be done viaAJAX
  • .jscapture.js-- Contains PhantomJS routines for printable table snapshot generation
  • .cssstyles.css-- Defines generic styles shared by the whole QuickSlots UI
  • .csstable.css-- Defines generic styles for QuickSlots table grids
  • .cssdashboard.css-- Defines the stylings for various elements of the dashboard
  • PhantomJS: PhantomJS web stack (for generating screenshots)(https://phantomjs.org/)

  • jQuery Core: The jQuery Core javascript library (https://jquery.com/)

  • jQuery UI: The jQuery UI library (https://jqueryui.com/)

  • jQuery UI Touch Punch: Touch Event Support for jQuery UI(http://touchpunch.furf.com/)

  • Chosen.js: Select Box Enhancer for jQuery (http://harvesthq.github.io/chosen/)

  • Apache Web Server: Version 2.4 or higher recommended

  • MYSQL Database Engine: Version 5.5 or higher recommended

  • PHP Hypertext Preprocessor: Version 5.5 or higher recommended

  • Make sure that the apache user has read/write permissions on the file'config.php', and the directory 'tmp', used respectively for configuration andbackup & screen-shot generation.

  • Visit setup.php through a web browser and provide the required database andLDAP configurations. Thereafter, set up the first dean/admin accountto complete the setup.

  • Login using the 'dean'(admin) account. You will be redirected to the'Manage Timetables' page.

  • Create a timetable by clicking on the drop-down on top, beside 'ConfigureTimetable:'

  • Add departments, faculty, courses and rooms.

  • HOD of every department can create courses and allocate timetables for allfaculty of his/her department.

  • Faculty is the account with the least set of privileges: creating courses andmanaging, the timetable for his courses. These privileges are shared by theHOD and dean as well.

The timetable can be viewed by two groups of users:

  • Public/guest users (like students):

Timetable For School

School
  • Without needing any login, guest users can either visit the applicationweb-root to view the timetable by applying filters on their own, or byvisiting the links generated by faculty.
  • When they visit the web-root, only the current active timetable is displayedby default. As before, users can further apply the various filters such tofind what they need.
  • The system also displays a link based on these filters which can besaved/bookmarked by them for direct display of the filtered timetable.
  • Authorized users (Faculty/HOD/Dean):
    • Once authenticated faculty can view, generate links and download snapshotsfor all instances of the timetable, with any set of filters applied.

School Timetable Generator Software

  • Multiple instances of timetable can be created. While creating a newtimetable, number of slots, working days and starting time can be configured.

  • In a authenticated users can easily manage timetable with the help of theintuitive GUI and instructions that accompany.

  • Timetables can be frozen by a dean at any time when a finalized timetable isneeded. It can be used if you want to avoid any accidental changes on thetimetable once finalized. A frozen timetable cannot be edited unless a deanchoses to de-freeze it.

Mcmaster Mosaic

  • The system allows the dean to download a whole backup of the database.

  • System can be restored to the previous state by uploading the backup fileback.