You are on page 1of 12

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/220887693

Solving a School Timetabling Problem Using a Bee Algorithm

Conference Paper · October 2008


DOI: 10.1007/978-3-540-88636-5_63 · Source: DBLP

CITATIONS READS

19 1,516

3 authors:

Carlos Lara-Alvarez Juan Flores


Centro de Investigación en Matemáticas (CIMAT) Universidad Michoacana de San Nicolás de Hidalgo
50 PUBLICATIONS   108 CITATIONS    122 PUBLICATIONS   742 CITATIONS   

SEE PROFILE SEE PROFILE

Felix Calderon
Universidad Michoacana de San Nicolás de Hidalgo
51 PUBLICATIONS   453 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Affective Computing View project

Power Forecasting for Photovoltaic, Eolic and Hydroelectric Power Plants Using Novel Techniques View project

All content following this page was uploaded by Juan Flores on 18 September 2014.

The user has requested enhancement of the downloaded file.


Solving a School Timetabling Problem Using a
Bee Algorithm

Carlos Lara, Juan J. Flores and Félix Calderón

Universidad Michoacana de San Nicolás de Hidalgo


División de Estudios de Posgrado. Facultad de Ingenierı́a Eléctrica
Santiago Tapia 403 Centro. Morelia, Michoacán, México. CP 58000

Abstract. The timetabling problem consists in fixing a sequence of


meetings between teachers and students in a given period of time, satisfy-
ing a set of different constraints. This paper shows the implementation of
a Bee Algorithm (BA) to solve the Scholar Timetabling Problem. In the
implemented BA, scout–bees find feasible solutions while collector–bees
search in their neighborhood to find better solutions. While other algo-
rithms evaluate every plausible assignment, the implemented algorithm
only evaluates feasible solutions. This approach seems to be helpful to
manage constrained problems. We propose a new measurement for re-
placing population that considers the evolutionary history of the bees
as well as their fitness. Experimental results are presented for two real
schools, where the algorithm shows promising results.

Keywords: Scholar Scheduling, Bee Algorithm, Decision Support System,


Education.

1 Introduction
The Academic Timetabling Problem consists of scheduling a sequence of activi-
ties between teachers and students, satisfying a set of constraints. A large number
of variants of the Academic timetabling problem have been studied in the lit-
erature, which differ from each other based on the type of institution involved.
Schaerf et. al. [8] classifies them as: School Timetabling, Course Timetabling,
and Examination Timetabling.
This paper focuses on the School Timetabling Problem (ST) also known as
Class–Teacher Timetabling Problem. This problem consists of scheduling all the
lectures of a week for a school, satisfying a set of constraints. Finding a good
solution is sometimes difficult because this problem is computationally N P–
hard. The complexities and challenges of timetabling problems arise from the
fact that there exists a large variety of constraints. In the timetabling literature,
constraints are usually categorized into two types: hard constraints and soft
constraints.

– Hard Constraints. These constraints cannot be violated under any cir-


cumstance. For instance, teachers cannot meet two classes at the same time.
F2
F3 F
F1 Feasible-Solution
Space

X11
X5 X
X3 Solution Space
X6 X9
X4
X1 X2 X7 X8

Fig. 1. Feasible–Solution Space

Analogously, a class cannot meet two lectures at the same time. A timetable
assignment which satisfies all of the hard constraints is called a feasible so-
lution.
– Soft Constraints. These constraints are desirable to solve but are not ab-
solutely critical. In practice it is usually impossible to find feasible solutions
that satisfy all of the soft constraints. The most common soft constraint in
the school timetabling is to avoid empty time slots between class’ activities.
Figure 1 illustrates that the search space X can be explored by using atomic
moves. For example: X2 is found by applying a single atomic move to X1 , X3
is found from X2 , etc. Some instances (e.g. X3 , X6 , . . .) do not violate hard
constraints, and they are in the feasible–solution space F. In ST as in many other
combinatorial problems, we are looking for instances in the feasible–solution
space. This paper proposes to use a Bee Algorithm (BA) to solve the ST problem,
on which scout–bees find feasible solutions while collector–bees search in the
neighborhood of these feasible solutions to find better solutions, keeping them
feasible. The implemented algorithm iterates two basic stages:
1. Exploration. This stage performs a random search to find feasible solutions.
2. Recollection. This stage performs a local search in the neighborhood of
a feasible solution to find another feasible solution. An example is shown
in Figure 1: given F1 , the recollection stage tries to find another feasible
solution– F2 . This stage finds another solution, which may or may not be
better than the original one.
The rest of the paper is organized as follows: Section 2 describes the re-
lated work in this area. Problem statement is presented in Section 3. Then the
representation used is introduced in Section 4. The implemented algorithm is
presented in Section 5. Section 6 shows the results of computational tests that
were conducted using real data. Finally, Section 7 presents our conclusions and
proposes extensions to the work presented in this article.
2 Related Work

The timetabling problem is one of the scheduling problems that have been exten-
sively studied. The solution approaches range from graph coloring to heuristic
algorithms, including mathematical programming models and metaheuristics as
well.
There are two different strategies used to explore the search space:

– those that search in the search space; in this strategy the unfeasible timeta-
bles are also included in the search space [9]. Unfeasibilities are usually highly
penalized and the problem is seen as an optimization one, and
– those that search in the space of feasible solutions [2]; in this strategy
unfeasible–solutions are not considered in the problem.

The implemented algorithm is one that searches in the space of feasible so-
lutions. An example of this strategy is used in [2] to solve a slightly different
problem –the University Course Timetabling Problem. Their approach consists
of finding an initial population of feasible solutions, and then performing a lo-
cal search by using a combination of neighborhood structures [1]. The reason for
considering a combination of diverse neighborhood criteria is related to the diver-
sification of search needed to escape from local optima [4]. We use a Neighborhood
Composition, on which the neighborhood is composed by chains of atomic moves
of variable length; although the chain length is limited to a maximum.
Our work is also related with memethic algorithms (MA); Memethic algo-
rithms have provided very good results for a variety of scheduling problems [7].
MA are combinations of evolutionary based approaches with local search [7].

3 Problem Statement

The Scholar Timetabling problem is defined as follows. Given the following pre-
liminary definitions:

– a set of teachers T = {ti } i = 1 . . . nT ,


– a set of classes C = {cj } j = 1 . . . nC (every class is a set of students having
a common curriculum and studying together).
– a set of timeslots in a day S = {sk } k = 1 . . . nS
– a matrix R = [ri,j ]nT ×nC called the requirements matrix, on which ri,j ≥ 0
is the quantity of lectures that teacher ti must teach to class cj in a week,
and
– two matrices V t = [vti,k ]nT ×nS and V c = [vcj,k ]nC ×nS that represent the
availability of teachers and the availability of classes, respectively. Where
vti,k , vcj,k ∈ {0, 1}. For instance vti,k = 0 means that teacher ti is unavailable
at period sk .

The problem is to assign meetings between teachers and classes in such a way
that no teacher has two meetings at the same time and no class has two meetings
at the same time. More precisely, let us define xi,j,k to be 1 if teacher i meets
class j at period k and 0 otherwise. Also, let us define the following functions,
representing Soft Constraints:

– Teacher Holes Ht(·). Number of idle periods between lectures in the teach-
ers assignment of a day.
– Class Holes Hc(·). Number of idle periods between lectures in the class
assignment of a day.
– Splits S(·). Number of periods that divide two or more lectures of the same
class.

A mathematical formulation of the problem is the following [3]:

Determine X = [xi,j,k ]nT ×nC ×nS such that it minimizes

f (X) = α1 Ht(X) + α2 Hc(X) + α3 S(X) (1)

Subject to
nS
X
∀i ∈ {1 . . . nT } , ∀j ∈ {1 . . . nC } xi,j,k = ri,j (2)
k=1
nC
X
∀i ∈ {1 . . . nT } , ∀k ∈ {1 . . . nS } xi,j,k ≤ 1 (3)
j=1
nT
X
∀j ∈ {1 . . . nC } , ∀k ∈ {1 . . . nS } xi,j,k ≤ 1 (4)
i=1
xijk ∈ {0, 1} (5)

Where α1 . . . α3 are weight constants. Equation 2 constrains that for every


teacher ti and every class cj , the sum of assigned timeslots must equal the
requirement rij . Equation 3 constrains that teachers only have 0 or 1 activity
associated to period k. Analogously, Equation 4 constrains that classes only have
0 or 1 activity associated to period k.

4 Representation of constraints and assignments


The previous section introduces matrices V t an V c, describing teacher’s and
classes’ availability. In order to simplify the problem representation, this section
introduces an equivalent representation for V t an V c using bit strings. This
section also introduces how to represent a candidate solution X.
n
Let Ω be the set of bit strings b = {0, 1} S on which the ith bit rep-
resents whether timeslot i is assigned (1) or not (0). We can represent the
teacher’s availability matrix by Vt = {vti |i = 1, . . . , nT }, class’ availability
matrix by Vc = {vcj |j = 1, . . . , nC }, and a candidate solution by the matrix
X = [xi,j ]nT ×nC ; where vt, vc, xi,j ∈ Ω. Given that each element vti ∈ Vt is a
bit string, what was defined in the previous section as vti,k is now the kth bit of
vti .
For instance, a binary string vt2 = 010000 denotes that teacher 2 is only
available at timeslot 2, vc3 = 111000 denotes that class 3 is available at timeslots
1, 2 and 3. Finally x2,3 = 0001100 means that teacher 2 meets class 3 at slots 4
and 5.
Every assignment xi,j must be compatible with availabilities of the ith teacher
and the jth class. That is, xi,j ∨ vti = vti , ∀j ∈ {1 . . . nC } and xi,j ∨ vcj = vcj ,
∀i ∈ {1 . . . nT }.
Given a candidate solution X, it is possible to retrieve the following infor-
mation by using bitwise operations:

– Used slots. Used slots are slots on which teacher (or class) has one or more
activities assigned. Teacher ti ’s used slots are determined by
nC
_
uti = (xi,1 ∨ . . . ∨ xi,nC ) = xi,j (6)
j=1

and to find class j’s used slots


nT
_
ucj = (x1,j ∨ . . . ∨ xnT ,j ) = xi,j (7)
i=1

– Free timeslots. Free timeslots of teacher i (or a class j), are slots on which
teacher i (or class j) is available according to vi (or vcj ) but has no activ-
ity assigned yet. Free slots are found by applying the XOR operation. For
example, to find teacher i’s free timeslots

dti = vti ⊕ uti (8)


and, to find class cj ’s free slots

dcj = vcj ⊕ ucj (9)


equations 8 and 9 hold because we enforce uti ∨vti = vti , ∀i and ucj ∨vcj =
vcj , ∀j. That is, we restrict every assignment in the used slots to available
slots.
– Unfeasibilities. There are two kinds of unfeasibilites:
1. Teacher–unfeasibility occurs when a teacher has two assignments in the
same period of time, and
2. Class–unfeasibility occurs when a class has two or more assignments at
the same time.
To find unfeasibilities we simply count the number of bits for every slot in the
current assignment of the teacher (or class). If the count for a determined slot
is more than one then the slot has an unfeasibility. To reduce the complexity,
the count is only performed on slots used by the teacher (or class).
– Holes and Splits. In order to calculate holes and splits we need to introduce
some concepts.
1. The number of zeroes between ones. The number of zeros between
ones in a bit string b ∈ Ω is given by:

Z(b) = send (b) − sstart (b) − sused (b) + 1 (10)


where sused (b) is the number of slots used in the bit string b, sstart (b)
is position of the first 1 in b, and send (b) is the position of the last 1
in b. For instance, given b = 0101001000, send (b) = 7, sstart (b) = 2,
and sused (b) = 3; then the number of zeros between ones is Z(b) =
7 − 2 − 3 + 1 = 3. This formula counts the number of unused slots,
whether they are contiguous or not.
2. Clusters. A cluster is a bit string b′ ∈ Ω which contains© a single ª
sequence of consecutive ones in b. Let us define Γ (b) = b′1 . . . b′γ
as the set of all clusters of b. For instance if b = 001110101 then
Γ (b) = {00111000000, 000000100, 000000001}.
3. Number of windows. The number of windows of an assignment y ∈ Ω
depends on the related availability v. To evaluate the number of windows
we use:
X
W(b, v) = Z(b ∧ vl′ ) (11)
∀vl′ ∈Γ (v)

These definitions allow us to calculate:


the number of holes of the ith–teacher

Hti = W(uti , vti ) (12)

the number of holes of the class cj

Hcj = W(ucj , vcj ) (13)

and the number of splits of an assignment

Si,j = Z(xi,j ). (14)

Finally, for a given assignment X the total numberP of teacher holes is Ht(X) =
P nt nc
i=1 Ht i , the number of class holes is Hc(X) = j=1 Hcj and the number
Pnt Pnc
of splits is S(X) = i=i j=1 Si,j .

5 Bee Algorithm

The necessary and sufficient conditions for the existence of feasible solutions are
discused in [5]. Next description considers that feasible solutions exist.
The goal of the algorithm is to find a feasible and optimal solution. In other
words, it must solve hard constraints (feasible solution) and satisfy as many
soft constraints as possible (optimal solution). We propose the use of the Bee
Algorithm (BA) [6].
Algorithm 1 Bee Algorithm to solve STP
1: Initialize a population of m scout bees (algorithm 2).
2: repeat
3: Evaluate the fitness of the population by using Eq. 1.
4: Determine the size of the neighborhood (patch size).
5: Recruit bees for selected sites and collect.
6: In each site replace the scout–bee for the local fittest bee
7: Create n new scout bees from random sites
8: Select the best m scouts according to Eq. 15
9: until converge

The BA mimics the food foraging behavior of swarms of honey bees. The BA
performs a kind of neighborhood search combined with a random search. BA
can be used for both combinatorial optimization and functional optimization. Its
first step, initialization, consists on creating a population of n scout–bees. Every
scout–bee finds a random feasible solution. In each iteration the BA evaluates
the n sites using a fitness function, selects the best m sites, searches in the
neighborhood of the m sites, and add a determined number of new random
sites.
The algorithm we implemented is shown in Algorithm 1. To select the num-
ber of collector bees to each patch, we implemented a simple roulette wheel
algorithm. The algorithm has a slightly but important difference with the basic
algorithm, while the basic version uses only the fitness of the bees to keep m
scouts, we suggest the use of a new measurement that considers the evolutionary
history of the bees as well as their fitness:

g(X) = f (X) + β1 ea /ζ1 (15)
where: the relative–age a′ is the number of iterations since the fitness of the
bee was improved. The new measurement lets the older bees grow, while allows
newer bees to be competitive. If only a fitness–based evaluation is used, then
newer scouts usually are not competitive against well explored neighborhoods.
It implies that new scout–bees are rarely selected for recollection. Parameters
β1 , and ζ1 must be sintonized. If β1 = 0 then g(X) = f (X) and the algorithm
acts as the basic bee algorithm.

5.1 Searching random feasible solutions: scout bees


Algorithm 2 shows how a random feasible solution is found by a scout bee.
Firstly, it initializes a random solution X based on requirements R and subject
to availabilities of teachers and classes, Vt and Vc. After that, the infeasible
solution X is repaired.
To get a feasible solution from the infeasible solution X, Algorithm 3 it-
eratively performs two steps: (a) finds an infeasibility (teacher or class), and
(b) replace it by a free slot. Every replacement is done randomly, therefore the
solution found is also random.
Algorithm 2 Scout–bees: searching a feasible solution from zero
1: Create a Random Matrix X based on R:
2: for all ri,j ∈ R do
3: yi,j ← Vti ∧ Vcj
4: xi,j ← new random string with ri,j ones, such that xi,j ⊕ yi,j = 0
5: end for
6: Find a feasible solution by repairing X (algorithm 3)

Algorithm 3 Repairing an unfeasible solution


1: while X has unfeasibilities do
2: Randomly select γ ∈ {0, 1}
3: if γ == 0 then
4: if there are teacher–unfeasibilities then
5: Select a random teacher ti that has unfeasibilities
6: Select a random unfeasible slot of ti and replace it for a free slot of ti
(calculated with Eq. 8)
7: end if
8: else
9: if there are class–unfeasibilities then
10: Select a random class cj that has unfeasibilities
11: Select a random unfeasible slot of cj and replace it for a free slot of cj
(calculated with Eq. 9)
12: end if
13: end if
14: end while

5.2 Local Search: collector bees


While scout–bees find feasible solutions from zero, collector–bees do it by per-
forming slight modifications to an initial feasible solution. Therefore collector–
bees perform a kind of Neighborhood Search. We implement three types of
atomic moves for local search:
– Moving a single lecture. Move a single lecture to a different suitable slot,
a suitable slot is a slot on which both the teacher and the class are available.
– Moving a cluster of lectures. The same case than the previous one, but
move two or more consecutive lectures of a class-teacher pair to a different
suitable slot.
– Teacher swapping. Given a class, select two teachers that teach to the
class and swap their slots; both teacher slots must be available.
– Class swapping. Given a teacher, select two classes associated with the
teacher and swap the two assigned slots; both class slots must be available.
Initially a collector–bee follows the scout, that is create a copy X′ of the
scout assignment X. After that, X′ is modified by a single atomic move or a
chain of atomic moves, these atomic moves can introduce unfeasibilities and the
collector bee needs to be fixed by using Algorithm 3. This reparation is much
easier than the one performed originally by scout bees.
BA (β1 = 0) BA (β1 = 1) Manual
elapsed time 15 Min 24 Seg 15 Min 49 Seg several days
best fitness 90 78 Unknown
total class holes 0 0 26
total teacher holes 30 26 64
total splits 0 0 13
Table 1. Experimental results for school A

6 Experimental Results
This section presents the experimental results. All code has been implemented
in Java and runs on an Acer Aspire 3680–2125 with a 1.86 GHz processor. Two
different schools A and B were used for the test, in those schools the timetabling
problem takes several days of manual work. School–A managers are interested on
keeping the same timetabling all days, while school–B managers are interested
on an optimal timetable, and they allow different timetable for each day during
the week. Both schools have enough room spaces because every class has an
assigned room in their corresponding periods.
We have carried out experiments using the presented algorithm, the values
for the parameters were: α1 = 7, α2 = 3, α3 = 5, β1 = 1, and ζ1 = 10. The
values of α1 , α2 and α3 reflect the scholar administrator preferences. The initial
number of scout-bees where m = 20, the maximum number of collector bees
associated to each patch was 50.

6.1 School A
The first timetabling data was provided by ITSUR1 and consists of 42 teachers,
23 classes, and 160 events per day. A typical evolutionary history for the best
bee is shown in Figure 2. The number of iterations where 1000. We perform the
experiment 100 times, the average results are shown in Table 1. Total class holes,
total teacher holes and total splits are calculated for a day.

6.2 School B
The second data was provided by the Michoacana University. The school data
consists of 86 teachers and 25 classes. School–B managers are interested on an
optimal timetable, and they allow different timetable for each day during the
week. To evaluate holes and splits we feed the algorithm with a list of day
patterns. To evaluate Ht(·), Hc(·) and S(·) we simply apply the bitwise–and
operation over each assignment and day pattern. This makes sure that we do
not consider the bit string representing a week as a long day. That kind of
misinterpretation would change the semantics of the representation, thus yielding
different measures for holes and splits.
1
South Guanajuato Institute of Technology
450

400

350

300

f (X) 250

200

150

100

50
0 100 200 300 400 500 600 700 800 900 1000
ITERATION
(a) School A, 1000 generations
6000

5000

4000

f (X) 3000

2000

1000

0
0 500 1000 1500 2000 2500
ITERATION
(b) School B, 10000 generations

Fig. 2. Fitness of best bee for School A and B

A typical evolutionary history for the best bee is shown in Figure 2. The
number of iterations where 10000. We perform the experiment 100 times, the
average results are shown in Table 2.

7 Conclusions and Future Work


The Bee algorithm implemented to solve the scholar timetabling problem yields
good results. The algorithm searches in the space of feasible solutions. In the
implemented BA, scout–bees find feasible solutions while collector–bees search
in their neighborhood to find better solutions.
The main contribution of this paper is to apply BA to STP by using a new
measurement for replacing population that considers the evolutionary history of
the bees as well as their fitness. This approach gives better results than using
the plain fitness function.
BA (β1 = 0) BA (β1 = 1) Manual
elapsed time ≃ 6 hrs ≃ 6 hrs several days
best fitness 15 6 Unknown
total class holes at week 0 0 114
total teacher holes at week 5 2 43
total splits at week 0 0 0
Table 2. Experimental results for school B

Local search techniques give the possibility to start the search from any
timetable, easily allowing for interactive construction and maintenance of timeta-
bles. In fact, once a timetable has been generated, it can be used as the starting
point for a new search, after some constraints or the timetable have been man-
ually modified. In the near future we want to test the technique presented for
interactive construction of the timetable and to apply the bee algorithm in other
contexts.

References
1. S. Abdullah, E. Burke, and B. McCollum, editors. Computer Science Interfaces
Book series, chapter Using a Randomised Iterative Improvement Algorithm with
Composite Neighbourhood Structures for the University Course Timetabling Prob-
lem. Springer Operations Research, 2006.
2. S. Abdullah, E. K. Burke, and B. McCollum. A hybrid evolutionary approach to
the university course timetabling problem. In CEC, 2007.
3. D. de Werra. An introduction to timetabling. European Journal of Operational
Research, 19(2):151–162, February 1985.
4. L. Di Gaspero and A. Schaerf. Multi-neighbourhood local search with application
to course timetabling. In E. Burke and P. D. Causmaecker, editors, Practice and
Theory of Automated Timetabling IV, number 2740 in Lecture Notes in Computer
Science, pages 263–278. Springer-Verlag, Berlin-Heidlberg, Germany, 2003.
5. G. A. Neufeld and J. Tartar. Graph coloring conditions for the existence of solutions
to the timetable problem. Commun. ACM, 17(8):450–453, 1974.
6. D. Pham, A. Ghanbarzadeh, E. Koç, S. Otri, S. Rahim, and M. Zaidi. The bees
algorithm a novel tool for complex optimisation problems. In IPROMS 2006.
7. O. Rossi-Doria and B. Paechter. A memetic algorithm for university course
timetabling. In Combinatorial Optimisation 2004 Book of Abstracts, Lancaster,
UK, Lancaster University, 2004.
8. A. Schaerf. A survey of automated timetabling. In 115, page 33. Centrum voor
Wiskunde en Informatica (CWI), ISSN 0169-118X, 30 1995.
9. A. Schaerf. Tabu search techniques for large high-school timetabling problems. In
88, page 17. Centrum voor Wiskunde en Informatica (CWI), ISSN 0169-118X, 1996.

View publication stats

You might also like