Solving Real School Timetabling Problems
Solving Real School Timetabling Problems
Abstract: - School timetabling is a classical combinatorial optimization problem, which consists in assigning
lessons to time slots, satisfying a set of constraints of various kinds. Due mostly to the constraints this problem
falls in the category of NP-Complete problems. In this paper we try to show an implementation of a decision
support system that solves real timetabling problems from various schools in Portugal. This implementation is
based on the Simulated Annealing meta-heuristic. The constraints we use were obtained after inquiries made
to several schools in Portugal. We show the results on three schools from different levels of teaching.
In general, a compound lesson means that we C10,11 Number of idle time slots (10-classes; 11-teachers)
have several classes joined together to attend a C12 Number of time slots of lessons without a room assigned.
certain subject or it means that a class can be
subdivided into subgroups to attend special subjects, C13,14,15 Number of time slots that are forbidden and are filled
with lessons (13-classes; 14-teachers; 15-subjects)
like laboratories, etc.
C16 Total number of teaching days for teachers
It is associated with each subject the kind of
Number of repetitions of lessons of the same subject in
room it must have, i.e., the resources that there must C17 the same class per day
exist in the room for a lesson of that subject should Number of time slots that doesn’t satisfy the predefined
happen. C18 space between lessons.
Table 1 Constraint set.
2.1 Constraints We also have introduced the concept of flexible
As it was stated in the beginning of this section, a constraint. Which means that a user may choose to
set of constraints must be satisfied in order to have a which category each constraint belongs.
valid timetable. The number and the kind of
constraints vary from school to school, even within Therefore the main objective of any Decision
the same school system. Nevertheless there are only Support System for this kind of problem should be
two categories of constraints: solving the hard constraints and minimizing the soft
• Hard constraints are constraints that physically constraints. Even if it is impossible to find any
cannot be violated. There are also other feasible solution, it is better to give an approximate
constraints in spite of not being any physical solution than none at all.
constraint they fall into this category because of
several reasons, for instance, because they are
governmental ruled. 3 Combinatorial Optimization
• Soft constraints are in general preferences and Problem (COP)
they do not represent a physical conflict. Any timetabling problem belongs to the class of
By hard constraints, we mean the following: combinatorial optimization problem. In general a
• A teacher cannot teach different lessons at the combinatorial optimization problem has a discrete
same time. finite search space S, and a function f, that measures
• A class cannot have different lessons at the the quality of each solution in S.
same time.
• Different classes cannot be held in the same
f :S → (1)
room at the same time. The problem is to find
• Class unavailabilities.
• Teacher unavailabilities. s ∗ = arg min f ( s ) (2)
s∈S
• Etc.
As soft constraints are mainly preferences they vary Where s is a vector of decision variables and f is
a lot among schools some examples are: the cost function. The vector s * is a global
• Teachers may prefer specific time slots. optimum. The neighbourhood N ( s ) of a solution s
• Teachers may prefer specific rooms. in S is defined as the set of solutions which can be
obtained from s by a move. Each solution
Feasible solutions
s ' ∈ N ( s) is called a neighbour of s .
For each s the set N ( s ) doesn’t need to be
listed explicitly, in general it is implicitly defined by
referring to a set of possible moves. Moves are
usually defined as local modifications of some part
of s . The “locality” of moves (under a
correspondingly appropriate definition of distance
between solutions) is one of the key ingredients of
local search. Nevertheless, from the definition above
Search space for all solutions
there is no implication that there exist “closeness” in
some sense among neighbours, and actually Figure 1 Search space of all solutions for
complex neighbourhood definitions can be used as the timetabling problem.
well. This operator can be quite complicated it might
even be a meta-heuristic. In our problem we did more or less the same
thing with the main difference that we didn’t relax
the hard constraints (user defined). Instead, we will
allow partial solutions to belong to the search space.
3.1 Search Space
We have a partial solution when there is at least one
When working with discrete domains it is possible
lesson that is not scheduled. Mathematically this can
to define the search space in terms of the possible
values that each variable can have [13]. For this be represented by augmenting each set H i with one
{
problem we have the set H = h1 ,… , hp } as the set more time slot, h0 . From a technical point of view,
of possible values that each lesson can have. we will assume that the search space (with partial
solutions) satisfies the following properties:
Definition Search space: The complete set of 1. The empty solution is in the search space
solutions that belongs to the search space is defined
∅∈S
by S = H1 × … × H l . If all H i are equal then
2. There is a path from any partial solution
S = H l and S = H = p l .
l
leading to other partial solution along which
the lessons are scheduled one after the other.
This value is an extreme case. For instance, there
are 1010 possible solutions if there are 10 lessons 3. All complete solutions in the search space
satisfy the hard constraints.
and 10 time slots. Even if we restrict each lesson to
a different time slot there will be 10! = 3, 628,800 In an attempt to limit the search space it is possible
to define at the beginning regions of the search
possible assignments. As it can easily be verified the
space that are forbidden, black holes. This can be
search space for this kind of problem is very large.
accomplished by defining a bipartite graph
However not all solutions are feasible, i.e., a feasible
solution has to have its lessons all scheduled and G = (V1 ,V2 , E ) , where every lesson belongs to V1
satisfying a certain number of constraints (hard and every time slot belongs to the other vertex set
constraints). A possible search space for this kind of V2 of this bipartite graph. The edge (i, j ) ∈ E
problem could be similar to the one shown in Figure means that lesson i can be given in time slot j .
1.
For certain problems it is very difficult to know This graph only takes into account the static
if there exists at least one feasible solution before constraints, i.e., class unavailabilities, teacher
starting any search algorithm. Thus any search unavailabilities, subject unavailabilities, etc. It is
algorithm should be able to walk across the search then possible to define the set H i for each lesson.
space even inside infeasible regions. One of the The search space thus formed could be like the one
most common ways to do that is to penalize shown in Figure 2.
constraints that are not satisfied and mixing them
together in a cost function.
Feasible solutions
1. Select randomly two lessons i≠ j