## 1. Introduction

Creating a school timetable is a complex task that involves assigning classes, subjects, teachers, and classrooms to specific time slots.

It’s a classic constraint-satisfaction problem (CSP), where we search for a feasible solution that satisfies all the specified constraints.

In this tutorial, we’ll show how to use a general-purpose CSP solver to create a school timetable.

## 2. Importance of Creating a School Timetable

Creating a school timetable is essential for efficient and organized school operations:

• It helps us optimize the utilization of available resources, such as classrooms.
• A well-structured timetable provides consistency in the daily schedule of school activities.
• Well-designed timetables can accommodate extracurricular activities, such as sports, allowing students to engage in other educational experiences.

## 3. Creating a School Timetable

Before diving into the algorithm, let’s specify all the requirements and constraints for creating a timetable.

We need to determine the number of periods per day, the list of all subjects offered, teachers’ availability, and other factors to specify a timetable:

### 3.1. Variables

Let’s use the following notation:

• is the set of available lecturers
• denotes the subjects
• is the set of working days in a week  ()
• denotes time slots
• is the set of classes
• is the set of classrooms

For the decision variable, we let be a binary variable that equals if a class has subject with teacher in classroom on day during the time slot . Otherwise, is zero.

### 3.2. Constraints

Let’s describe the constraints.

Each class has a single lecturer for a particular subject:

(1)

It is specified how many times a class is taught in each subject:

(2)

Further, for each lecturer , subject , working day , and time slot , there should be at most one class in which the lecturer teaches that subject during that specific time and day:

(3)

To guarantee that for each classroom , there’s exactly one combination of lecturer, subject, working day, and time slot assigned, we require that each classroom be occupied by at most one class at any given time:

(4)

Similar to Equation (3), each lecturer can teach at most one class at any given time slot and working day:

(5)

We allow all classes to follow their lectures simultaneously:

(6)

Finally, the decision variable (representing the assignment of a lecturer, subject, working day, time slot, classroom, and subject) must be non-negative:

(7)

We designed constraints (36) with inequalities rather than strict equalities to introduce flexibility within the scheduling framework. For example, that means allowing a classroom to be empty during a period.

For simplicity, we assumed that each lecturer could teach all the subjects. However, each lecturer can teach a specific set of subjects in a real-world scenario. This doesn’t affect our approach since we can use instead of to denote the subjects that can teach.

### 3.3. Algorithm

We can use a general-purpose CSP solver:

We only have to feed it the variables and constraints specific to this problem.

In , we use a value-ordering heuristic. For instance, when assigning a class or classroom to a particular time slot or teacher, we prioritize those imposing the fewest constraints on the available options for other time slots and related variables.

does forward checking. For example, when a subject is assigned to a time slot in a day and a class, we remove it from the remaining set of subjects that must be scheduled for that class. If it detects a variable has no options, we know we have to backtrack on the current assignment.

Finally, in , we prioritize variables with the fewest available values.

## 4. Example

Let’s use the following example:

stands for senior high school.

We start with Monday, assigning to the two classrooms two teachers and subjects to two classes of students in the first time slot. Continuing like this, we get our solution. Here’s the timetable for class :

Here’s the schedule for ::

In these timetables, we ensure that the two classrooms are occupied in every time slot, with no overlapping lectures. All the other constraints are also satisfied.

## 5. Optimization

Any feasible timetable will do if we’re only concerned with satisfying constraints. However, there are reasons we may prefer one timetable over another. For example, teachers can ask not to have free gaps. So, a schedule where each lecturer holds classes consecutively will be preferred to the one in which there are many periods that teachers sit out between classes. Alternatively, we may want students not to take similar subjects one after another.

We don’t include such requests as constraints because the algorithm can treat many acceptable timetables as infeasible. Instead, we formulate an objective function that evaluates each schedule and indicates which is better. Optimizing it via our algorithm will give us a feasible solution that considers our preferences.

Let’s check out some examples.

### 5.1. Maximizing Classroom Utilization

To calculate classroom utilization, we can count the number of time slots the -th classroom is assigned and compute the utilization rate:

(8)

Then, the average classroom utilization rate () will be :

(9)

In our example, the utilization rate is 1.0.

Balancing teacher workloads ensures that no teacher is overburdened with too many classes while others have too few. To calculate teacher workload balance, we can compute the standard deviation of the number of classes taught by each teacher:

(10)

where is the number of classes taught by the -th teacher, and is the number of teachers.

If all the teachers have approximately the same workload, the deviation will be close to zero, indicating a balanced schedule.

### 5.3. Balancing Teachers’ Workload by Day

We could try to distribute their teaching assignments evenly throughout the week. Balancing teachers’ workload by day aims to achieve a schedule where each lecturer teaches approximately the same number of classes daily. An uneven distribution of classes can lead to stressful peaks in a teacher’s schedule.

## 6. Conclusion

Creating a school timetable is a complex problem that can be effectively solved as a constraint-satisfaction problem. There are many tools for constraint-satisfaction solving, so all we have to do is formulate the constraints according to our needs.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.