Project · Personal project

Automated School Timetable Generator

A solver that turns a school's teachers, classes, subjects and periods into a conflict-free weekly timetable, in seconds rather than days.

OptimisationConstraint programmingSoftware
Type
Personal project
Core engine
OR-Tools CP-SAT
Also built
Browser JS version
Language
Python, JavaScript

Overview

Making a school timetable by hand is a classic headache. Every teacher, every class and every period interacts with every other, and moving one lesson can break the week somewhere else.

I treated it as what it really is, a constraint-satisfaction problem, and let a solver do the juggling. The result is a generator that produces a timetable where nobody is in two places at once, while still respecting the softer preferences that make a timetable pleasant to live with.

See it in action

How it works

Stage 1School dataTeachers, classes, subjects and periods
Stage 2Decision variablesWho teaches which class, and when
Stage 3Hard constraintsRules that must never break, such as no double-booking
Stage 4Soft preferencesNice-to-haves the solver tries to honour
Stage 5CP-SAT solverSearches for a schedule that satisfies everything
Stage 6TimetableA complete, conflict-free week

How the problem is modelled and solved.

How I did it

1

Modelling the data

Described the school as data: the teachers, the classes, the subjects each class needs, and the periods in a week.

2

Defining the variables

Set up decision variables for each possible assignment of a teacher and subject to a class in a period.

3

Encoding the hard rules

Wrote the constraints that must always hold, such as a teacher or class never being booked twice in the same period.

4

Adding preferences

Added softer goals so that, among all valid timetables, the solver prefers the better ones.

5

Solving and checking

Ran Google OR-Tools' CP-SAT solver and checked the output for any conflicts.

6

Taking it to the browser

Built a standalone HTML and JavaScript constraint-satisfaction version that runs entirely in the browser, with nothing to install.

What mattered most

Is there a solution at all?

Too many rules can make a timetable impossible. A good model makes it clear when the inputs themselves are the problem.

Speed

Schools want an answer quickly. Constraint programming lets the solver prune huge numbers of bad options early.

Hard versus soft

Separating must-have rules from preferences is what lets the solver produce a timetable that is both valid and sensible.

Easy to run

The browser version means someone at a school can use it without setting up Python.

Tools and technologies

PythonGoogle OR-ToolsCP-SATConstraint satisfactionJavaScriptHTML