0% found this document useful (0 votes)
2 views

Cairo Sat Course Timetabling

This paper presents a solution to the course timetabling problem at Cairo University by encoding it into a Max-SAT framework. It discusses the challenges of scheduling courses for a growing number of students and limited teaching staff, and details the encoding of various constraints into hard and soft clauses. The approach aims to generate a conflict-free timetable while maximizing the satisfaction of soft constraints related to student registrations and room capacities.

Uploaded by

plant6693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Cairo Sat Course Timetabling

This paper presents a solution to the course timetabling problem at Cairo University by encoding it into a Max-SAT framework. It discusses the challenges of scheduling courses for a growing number of students and limited teaching staff, and details the encoding of various constraints into hard and soft clauses. The approach aims to generate a conflict-free timetable while maximizing the satisfaction of soft constraints related to student registrations and room capacities.

Uploaded by

plant6693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Solving the Course-timetabling Problem of Cairo

University Using Max-SAT


arXiv:1803.05027v1 [cs.AI] 11 Feb 2018

Mohamed El Halaby
August 30, 2018

Abstract
Due to the good performance of current SAT (satisfiability) and Max-
SAT (maximum satisfiability) solvers, many real-life optimization prob-
lems such as scheduling can be solved by encoding them into Max-SAT. In
this paper we tackle the course timetabling problem of the department of
mathematics, Cairo University by encoding it into Max-SAT. Generating
timetables for the department by hand has proven to be cumbersome and
the generated timetable almost always contains conflicts. We show how
the constraints can be modelled as a Max-SAT instance.

1 Introduction
The satisfiability problem (SAT), which is the problem of deciding if there exists
a truth assignment that satisfies a Boolean formula in conjunctive normal form
(CNF), is a core problem in theoretical computer science because of its central
position in complexity theory. Given a Boolean formula, SAT asks if there is an
assignment to the variables of the formula such that it is satisfied (evaluates to
true). SAT was the first problem proven to be N P-complete by Cook [4]. Each
instance of an N P-complete problem can be translated into an instance of SAT
in polynomial time. This makes it very important to develop fast and efficient
SAT solvers.
An important optimization of SAT is Max-SAT which asks for a truth as-
signment that satisfies the maximum number of clauses of a given CNF formula.
Many theoretical and practical problems can be encoded into SAT and Max-
SAT such as debugging [13], circuits design and scheduling of how an observation
satellite captures photos of Earth [15], course timetabling [2, 10, 9, 7], software
package upgrades [6], routing [16, 11], reasoning [14] and protein structure align-
ment in bioinformatics [12].
This paper addresses the course timetabling problem of the department of
mathematics, faculty of science, Cairo university. Generating a timetable is done
every semester and with the growing number of students and the limited number
of teaching staff, this is becoming a difficult task. An important aspect of this
problem is that students of the department take different courses belonging to

1
different curricula at the same time. This fact complicates the problem because
the number of students taking an arbitrary set of courses is small and generating
a conflict-free schedule becomes harder.
This paper is structured as follows. Section 2 gives basic definitions and back-
ground about SAT and Max-SAT. Section 3 describes our timetabling problem,
problem encoding into partial Max-SAT and weighted Max-SAT and finally an
example that illustrates the workings of the encoding. Section 4 summarizes
our results and discusses future work.

2 Preliminaries
A Boolean variable x can take one of two possible values 0 (false) or 1 (true). A
Wnl is a variable x or its negation ¬x. A clause is a disjunction of literals,
literal
i.e., i=1 li . A CNF formula is a conjunction of clauses [5]. Formally, a CNF
formula F composed of k clauses, where each clause Ci is composed of mi is
defined as
^k
F = Ci
i=1
where
_
mi
Ci = li,j
j=1

In this paper, a set of clauses {C1 , C2 , . . . , Ck } is referred to as a Boolean for-


mula. A truth assignment satisfies a Boolean formula if it satisfies every clause.
Max-SAT is a generalization of SAT. Given a CNF formula F , the problem
asks for a truth assignment that maximizes the number of satisfied clauses in
F . For example, if F = {(x ∨ ¬y), (¬x ∨ z), (y ∨ z), (¬z)} then I = {x =
0, y = 0, z = 0} satisfies three clauses. In fact, F is unsatisfiable and thus the
maximum number of clauses that can be satisfied in F is three.
There are important variations of Max-SAT such as partial Max-SAT, weighted
Max-SAT and weighted partial Max-SAT. In partial Max-SAT we have two sets
of clauses, one is called hard and another called soft and we seek an assignment
that satisfies all the hard clauses and maximize the number of the satisfied soft
clauses.
For example, for F = Hard ∪ Sof t, where Hard = {(x ∨ ¬y), (¬x ∨ z)} and
Sof t = {(y ∨ z), (¬z)}, the assignment A = {x = 0, y = 0, z = 1} satisfies all
Hard and leaves one clause in Sof t unsatisfied, namely (¬z).
A weighted CNF formula is a set of clauses where each clause has an asso-
ciated number. In weighted Max-SAT, we are concerned with finding a truth
assignment that maximizes the sum of weights of satisfied clauses. The weighted
partial Max-SAT problem is the combination between partial and weighted Max-
SAT. Hard clauses have weight ∞.
As an example, the partial Max-SAT instance F = {((x, ¬y), ∞), ((¬x, z), ∞),
((y, z), 3), ((¬z), 4)} has a solution {x = 0, y = 0, z = 0} that satisfies every hard
clause and maximizes the sum of weights of satisfied soft clauses.

2
3 Problem description and encoding
The course timetabling problem deals with the following objects:
• Courses: Each course is associated with one teacher and a number of
students. In our case, each course is scheduled twice a week, once for a
lecture and another for either a section or laboratory work, but we will
consider the lecture and laboratory work of the same course as different
courses for technical purposes as the lecture is given by teachers and the
laboratory work is supervised by teaching assistants.
• Curricula: A curriculum is a set of courses constituting an area of special-
ization.
• Rooms: Courses take place in rooms (lecture rooms or labs), where each
room has an associated capacity. There are two kinds of rooms: lecture
rooms and laboratories.
• Timeslots: A timeslot is a specific day and hour during which a course is
taught.
The course timetabling problem asks for an assignment of courses to rooms and
timeslots in such a way that all the hard constraints are met and satisfy as much
soft constraints as possible.
Because of the large number of students taking courses belonging to differ-
ent curricula, a generated timetable is prone to have conflicts (with two or more
courses taken by a student scheduled at the same time), which is a very impor-
tant problem in the timetabling problem we are tackling. Other formulations
do not take this conflict into account.
Our timetabling approach assumes that the timetable is a per-week schedule
of courses. A week consists of several work days, and each work day is divided
into equal-length timeslots and courses are scheduled into these timeslots.
Many of our timetabling requirements are common for many teaching insti-
tutions, however, some may vary. This allows us to use existing encodings and
timetabling tools.

3.1 Partial Max-SAT encoding


Here, the problem is modelled as a PMax-SAT instance. We first define the
following variables upon which the encoding is based, then we mention the
constraints and requirements of the timetable. The notation used is the same
one used in [2].
1. ctc,t : course c takes place in timeslot t.
2. cdc,d : course c takes place in day d.

3. crc,r : course c takes place in room r.

3
4. ktk,t : curriculum k takes place in timeslot t, which implies that one of the
courses belonging to k takes place in t.
The truth values of these basic variables will determine the whole timetable.
First, we show how to encode correctness requirements, which must all be satis-
fied (i.e., they are hard constraints) for the generated timetable to be accepted.
So, in order for the encoding to be correct, the relation between the variables
must be expressed correctly.
Relationship between ct and cd:
1. If some course c takes place in timeslot t, it also takes place in the day
corresponding to t. So, for each course c and timeslot h, the following
hard clause is needed:
ctc,t ⇒ cdc,day(t)
which is equivalent to1
¬ctc,t ∨ cdc,day(t)

2. If some course c takes place in a day d, it must also occur in some of


the timeslots of d. So, for each course c and day d consisting of timeslots
t1 , t2 , . . . , tn , the following hard clause is needed:

¬cdc,d ∨ ctc,t1 ∨ . . . ∨ ctc,tn

Relationship between ct and kt:


• If a course c takes place in timeslot t, then all the curricula k1 , k2 , . . . , kn ,
to which c belongs occur in t. So, for each course c, timeslot t and curricula
k1 , k2 , . . . , kn that include c, the following hard clauses are needed:

¬ctc,t ∨ ktk1 ,t
..
.
¬ctc,t ∨ ktkn ,t

• If a curriculum k takes place in timeslot t, then at least one of the courses


belonging to k takes place in t. So, for each timeslot t and curriculum k
consisting of courses c1 , c2 , . . . , cn we need the following hard clause

¬ktk,t ∨ (ctc1 ,t ∨ . . . ∨ ctcn ,t )

Now after the relationships between the variables have been encoded, we
encode the constraints of the timetabling problem. Here we omit the details of
the cardinality constraints by denoting them by exactly, at most and at least.
Several attempts have been made to encode the cardinality constraints into CNF
such as [1], [8] and [3].
1 p ⇒ q is equivalent to ¬p ∨ q. From this point forward we will directly write the encoding

clauses using only ORs ∨ and ANDs ∧.

4
• Curriculum clashes: Courses belonging to the same curriculum must be
scheduled at different timeslots. Thus, for every two distinct courses c1
and c2 belonging to the same curriculum, and for every timeslot t, the
following hard clause is needed
¬ctc1 ,t ∨ ¬ctc2 ,t

• Student registration clashes: Students are allowed to enrol themselves


in any of the available courses except if the student had not passed its
prerequisite. Hence, there are many cases where students register two
or more courses from different curricula, e.g., a course from first year
curriculum and another from the second year curriculum. The main reason
for this is that a student did not pass a first year course and he or she
is taking it again. So, for every timeslot t and two courses c1 and c2
registered by a student, the following soft clause is needed
¬ctc1 ,t ∨ ¬ctc2 ,t
The reason for making the clause soft is that insisting on satisfying all
these clauses is not realistic because of the limited number of teaching
staff and the large number of students.
Before the beginning of each semester, the timetable coordinators receive
from students the courses they hope to register from different curricula.
Not all such courses can be scheduled with no conflicts with other courses.
• Teacher clashes: Courses taught by the same teacher must not be sched-
uled at the same time. So, for every timeslot t and two distinct courses c1
and c2 taught by the same teacher, the following hard clause is needed
¬ctc1 ,t ∨ ¬ctc2 ,t

• Room clashes: Every room can have at most one course scheduled to it at
any timeslot. So, for each room r, timeslot t, and pair of distinct courses
c1 and c2 , we have
¬ctc1 ,t ∨ ¬ctc2 ,t ∨ ¬crc1 ,r ∨ ¬crc2 ,r

• Timeslot unavailability: Each course can have a set of forbidden timeslots


to be scheduled in. For each course c with forbidden timeslots t1 , t2 , . . . , tn ,
the following soft clauses are needed
¬ctc,t1
..
.
¬ctc,tn
In our case, timeslot unavailability are times during which teachers are
not available to teach their courses. It is practically difficult to satisfy
every such constraint and that is why they are declared soft.

5
• Room capacity: Every course is preferred to be scheduled into a room
that fits. So, for every course c having nc students and for every room
with capacity cr such that ns > cr , we need the following soft clause

¬crc,r

• Every course must be scheduled to exactly one room. Courses with weekly
laboratory work must be scheduled to a room that is a laboratory. We will
denote regular lecture rooms r1 , . . . , rm and laboratory rooms lab1 , . . . , labn .
1. For each course c with weekly lecture and laboratory work, we need
the following hard clause for the lecture:

exactly(1, {crc,r1 , . . . , crc,rm , crc,lab1 , . . . , crc,labn })

and the following hard clause for the laboratory work:

exactly(1, {crc,lab1 , . . . , crc,labn })

2. For each course c with a weekly lecture and a section and no labora-
tory work, we need the following hard clause:

exactly(2, {crc,r1 , . . . , crc,rm , crc,lab1 , . . . , crc,labn })

The clauses in the previous two cases are SAT encodings of the cardinality
constraint exactly, which requires that exactly k out of l literals be true.
• Number of lectures: Each course c must be scheduled twice a week; once
for a lecture and another for either a section (e.g., for solving exercises)
or laboratory work (e.g., for programming exercises). So, for every course
c we need the following hard clause

exactly(2, {ctc,t1 , . . . , ctc,tn })

3.2 Weighted partial Max-SAT encoding


Not all the soft constraints are of the same importance and a practical solution
must take this fact into account. The previous PMax-SAT encoding can be
extended to associate the encoding clauses of an important constraint with a
big weight and the less important constraints with smaller weights. For every
soft constraint a positive weight is going to be assigned:
1. Student registration clashes: Courses that belong to different curricula
and desired by more students will receive larger weight. So, for every two
courses c1 and c2 needed by a number of students n belonging to two
different curricula, and for every timeslot t, the following soft clause is
needed with weight n
(¬ctc1 ,t ∨ ctc2 ,t )

6
2. Timeslot unavailability: Each clause representing a timeslot unavailability
will receive a weight of 10. This constraint is considered less important
than student registration clashes.
3. Room capacity. Each violation of this constraint has a cost of 1 per each
student that does not fit. For example if the capacity of a room r is 50
and the number of students in a course c is 60, then the weight assigned
to (¬crc,r ) is 10.

3.3 Example
The following is a simple example to demonstrate the partial Max-SAT encod-
ing.
• Days: {d1 , d2 , d3 }.
• Timeslots: {t1 , t2 , t3 , t4 , t5 }, where day(t1 ) = d1 , day(t2 ) = d1 , day(t3 ) =
d2 , day(t4 ) = d2 and day(t5 ) = d3 .
• Courses: {CS101, CS202, M 271, CS304, CS305, CS402,
CS408}.

Course ID Name Curriculum Teacher Forbidden timeslots


CS101 Introduction to Computers k1 I1 {t1 , t2 }
CS202 Data Structures and Algorithms k2 Rasha {t5 }
M271 Newtonian Mechanics k2 Enaam ∅
CS305 Algorithms k3 Hassan {t1 }
CS304 Computer Graphics k3 Hassan {t1 }
CS402 Cryptography k4 Rasha {t4 , t5 }
CS408 Artificial Intelligence k4 Alaa ∅

• Curricula: {k1 = {CS101}, k2 = {CS202, M 271}, k3 = {CS304, CS305}, k4 =


{CS402, CS408}}.
• Student registration information:

Courses desired Number of students


{CS101} 55
{CS101, M 271} 20
{M 271, CS202} 50
{CS304, CS305} 64
{CS305, M 271} 15
{CS402, CS408} 50
{CS304, CS402} 10
{CS408, M 271} 5
Course Number of students
CS101 20
CS202 50
M271 90
CS304 74
CS305 79
CS402 60
CS402 55

7
• Rooms: {r1 , r2 , lab1, lab2}.

Rooms Capacity
r1 50
r2 100
lab1 50
lab2 100

3.3.1 Clauses
1. Relationship between ct and cd. The clauses are grouped by course.
CS101:
(¬ctCS101,t1 ∨ cdCS101,d1 ), (¬ctCS101,t2 ∨ cdCS101,d1 )
(¬ctCS101,t3 ∨ cdCS101,d2 ), (¬ctCS101,t4 ∨ cdCS101,d2 )
(¬ctCS101,t5 ∨ cdCS101,d3 ), (¬cdCS101,d1 ∨ ctCS101,t1 ∨ ctCS101,t2 )
(¬cdCS101,d2 ∨ ctCS101,t3 ∨ ctCS101,t4 ), (¬cdCS101,d3 ∨ ctCS101,t5 )
CS202:
(¬ctCS202,t1 ∨ cdCS202,d1 ), (¬ctCS202,t2 ∨ cdCS202,d1 )
(¬ctCS202,t3 ∨ cdCS202,d2 ), (¬ctCS202,t4 ∨ cdCS202,d2 )
(¬ctCS202,t5 ∨ cdCS202,d3 ), (¬cdCS202,d1 ∨ ctCS202,t1 ∨ ctCS202,t2 )
(¬cdCS202,d2 ∨ ctCS202,t3 ∨ ctCS202,t4 ), (¬cdCS202,d3 ∨ ctCS202,t5 )
M271:
(¬ctM 271,t1 ∨ cdM 271,d1 ), (¬ctM 271,t2 ∨ cdM 271,d1 )
(¬ctM 271,t3 ∨ cdM 271,d2 ), (¬ctM 271,t4 ∨ cdM 271,d2 )
(¬ctM 271,t5 ∨ cdM 271,d3 ), (¬cdM 271,d1 ∨ ctM 271,t1 ∨ ctM 271,t2 )
(¬cdM 271,d2 ∨ ctM 271,t3 ∨ ctM 271,t4 ), (¬cdM 271,d3 ∨ ctM 271,t5 )
CS304:
(¬ctCS304,t1 ∨ cdCS304,d1 ), (¬ctCS304,t2 ∨ cdCS304,d1 )
(¬ctCS304,t3 ∨ cdCS304,d2 ), (¬ctCS304,t4 ∨ cdCS304,d2 )
(¬ctCS304,t5 ∨ cdCS304,d3 ), (¬cdCS304,d1 ∨ ctCS304,t1 ∨ ctCS304,t2 )
(¬cdCS304,d2 ∨ ctCS304,t3 ∨ ctCS304,t4 ), (¬cdCS304,d3 ∨ ctCS304,t5 )
CS305:
(¬ctCS305,t1 ∨ cdCS305,d1 ), (¬ctCS305,t2 ∨ cdCS305,d1 )
(¬ctCS305,t3 ∨ cdCS305,d2 ), (¬ctCS305,t4 ∨ cdCS305,d2 )
(¬ctCS305,t5 ∨ cdCS305,d3 ), (¬cdCS305,d1 ∨ ctCS305,t1 ∨ ctCS305,t2 )
(¬cdCS305,d2 ∨ ctCS305,t3 ∨ ctCS305,t4 ), (¬cdCS305,d3 ∨ ctCS305,t5 )
CS402:
(¬ctCS402,t1 ∨ cdCS402,d1 ), (¬ctCS402,t2 ∨ cdCS402,d1 )
(¬ctCS402,t3 ∨ cdCS402,d2 ), (¬ctCS402,t4 ∨ cdCS402,d2 )
(¬ctCS402,t5 ∨ cdCS402,d3 ), (¬cdCS402,d1 ∨ ctCS402,t1 ∨ ctCS402,t2 )
(¬cdCS402,d2 ∨ ctCS402,t3 ∨ ctCS402,t4 ), (¬cdCS402,d3 ∨ ctCS402,t5 )

8
CS408:
(¬ctCS408,t1 ∨ cdCS408,d1 ), (¬ctCS408,t2 ∨ cdCS408,d1 )
(¬ctCS408,t3 ∨ cdCS408,d2 ), (¬ctCS408,t4 ∨ cdCS408,d2 )
(¬ctCS408,t5 ∨ cdCS408,d3 ), (¬cdCS408,d1 ∨ ctCS408,t1 ∨ ctCS408,t2 )
(¬cdCS408,d2 ∨ ctCS408,t3 ∨ ctCS408,t4 ), (¬cdCS408,d3 ∨ ctCS408,t5 )

2. Relationship between ct and kt. The clauses are grouped by course:


CS101:
(¬ctCS101,t1 ∨ktk1 ,t1 ), (¬ctCS101,t2 ∨ktk1 ,t2 ), (¬ctCS101,t3 ∨ktk1 ,t3 ), (¬ctCS101,t4 ∨
ktk1 ,t4 ), (¬ctCS101,t5 ∨ ktk1 ,t5 )

CS202:
(¬ctCS202,t1 ∨ktk2 ,t1 ), (¬ctCS202,t2 ∨ktk2 ,t2 ), (¬ctCS202,t3 ∨ktk2 ,t3 ), (¬ctCS202,t4 ∨
ktk2 ,t4 ), (¬ctCS202,t5 ∨ ktk2 ,t5 )

M271:
(¬ctM 271,t1 ∨ ktk2 ,t1 ), (¬ctM 271,t2 ∨ ktk2 ,t2 ), (¬ctM 271,t3 ∨ ktk2 ,t3 ), (¬ctM 271,t4 ∨
ktk2 ,t4 ), (¬ctM 271,t5 ∨ ktk2 ,t5 )

CS304:
(¬ctCS304,t1 ∨ktk3 ,t1 ), (¬ctCS304,t2 ∨ktk3 ,t2 ), (¬ctCS304,t3 ∨ktk3 ,t3 ), (¬ctCS304,t4 ∨
ktk3 ,t4 ), (¬ctCS304,t5 ∨ ktk3 ,t5 )

CS305:
(¬ctCS305,t1 ∨ktk3 ,t1 ), (¬ctCS305,t2 ∨ktk3 ,t2 ), (¬ctCS305,t3 ∨ktk3 ,t3 ), (¬ctCS305,t4 ∨
ktk3 ,t4 ), (¬ctCS305,t5 ∨ ktk3 ,t5 )

CS402:
(¬ctCS402,t1 ∨ktk4 ,t1 ), (¬ctCS402,t2 ∨ktk4 ,t2 ), (¬ctCS402,t3 ∨ktk4 ,t3 ), (¬ctCS402,t4 ∨
ktk4 ,t4 ), (¬ctCS402,t5 ∨ ktk4 ,t5 )

CS408:
(¬ctCS408,t1 ∨ktk4 ,t1 ), (¬ctCS408,t2 ∨ktk4 ,t2 ), (¬ctCS408,t3 ∨ktk4 ,t3 ), (¬ctCS408,t4 ∨
ktk4 ,t4 ), (¬ctCS408,t5 ∨ ktk4 ,t5 )

3. Curriculum clashes. The clauses are grouped courses of the same curriculum:
CS202 and M271:
(¬ctCS202,t1 ∨¬ctM 271,t1 ), (¬ctCS202,t2 ∨¬ctM 271,t2 ), (¬ctCS202,t3 ∨¬ctM 271,t3 ), (¬ctCS202,t4 ∨
¬ctM 271,t4 ), (¬ctCS202,t5 ∨ ¬ctM 271,t5 )

CS304 and CS305:


(¬ctCS304,t1 ∨¬ctCS305,t1 ), (¬ctCS304,t2 ∨¬ctCS305,t2 ), (¬ctCS304,t3 ∨¬ctCS305,t3 ), (¬ctCS304,t4 ∨
¬ctCS305,t4 ), (¬ctCS304,t5 ∨ ¬ctCS305,t5 )

CS402 and CS408:


(¬ctCS402,t1 ∨¬ctCS408,t1 ), (¬ctCS402,t2 ∨¬ctCS408,t2 ), (¬ctCS402,t3 ∨¬ctCS408,t3 ), (¬ctCS402,t4 ∨

9
¬ctCS408,t4 ), (¬ctCS402,t5 ∨ ¬ctCS408,t5 )

4. Student registration clashes. The clauses are grouped by each two courses that
can not be scheduled at the same time:
CS101 and M271: (¬ctCS101,t1 ∨¬ctM 271,t1 ), (¬ctCS101,t2 ∨¬ctM 271,t2 ), (¬ctCS101,t3 ∨
¬ctM 271,t3 ), (¬ctCS101,t4 ∨ ¬ctM 271,t4 ), (¬ctCS101,t5 ∨ ¬ctM 271,t5 )

M271 and CS305:


(¬ctCS305,t1 ∨¬ctM 271,t1 ), (¬ctCS305,t2 ∨¬ctM 271,t2 ), (¬ctCS305,t3 ∨¬ctM 271,t3 ), (¬ctCS305,t4 ∨
¬ctM 271,t4 ), (¬ctCS305,t5 ∨ ¬ctM 271,t5 )

M271 and CS408:


(¬ctCS408,t1 ∨¬ctM 271,t1 ), (¬ctCS408,t2 ∨¬ctM 271,t2 ), (¬ctCS408,t3 ∨¬ctM 271,t3 ), (¬ctCS408,t4 ∨
¬ctM 271,t4 ), (¬ctCS408,t5 ∨ ¬ctM 271,t5 )

CS402 and CS304:


(¬ctCS304,t1 ∨¬ctCS402,t1 ), (¬ctCS304,t2 ∨¬ctCS402,t2 ), (¬ctCS304,t3 ∨¬ctCS402,t3 ), (¬ctCS304,t4 ∨
¬ctCS402,t4 ), (¬ctCS304,t5 ∨ ¬ctCS402,t5 )

5. Teacher clashes. The clauses are grouped by each pair of courses taught by the
same teacher:
CS202 and CS402:
(¬ctCS202,t1 ∨¬ctCS402,t1 ), (¬ctCS202,t2 ∨¬ctCS402,t2 ), (¬ctCS202,t3 ∨¬ctCS402,t3 ), (¬ctCS202,t4 ∨
¬ctCS402,t4 ), (¬ctCS202,t5 ∨ ¬ctCS402,t5 )

6. Room clashes. We will not write all the clauses since they are too many. Clauses
for one room, six pairs of courses and one timeslot:
r 1 , t1 :
(¬ctCS101,t1 ∨ ¬ctCS202,t1 ∨ ¬crCS101,r1 ∨ ¬crCS202,r1 ),
(¬ctCS101,t1 ∨ ¬ctM 271,t1 ∨ ¬crCS101,r1 ∨ ¬crM 271,r1 ),
(¬ctCS101,t1 ∨ ¬ctCS304,t1 ∨ ¬crCS101,r1 ∨ ¬crCS304,r1 ),
(¬ctCS101,t1 ∨ ¬ctCS305,t1 ∨ ¬crCS101,r1 ∨ ¬crCS305,r1 ),
(¬ctCS101,t1 ∨ ¬ctCS402,t1 ∨ ¬crCS101,r1 ∨ ¬crCS402,r1 ),
(¬ctCS101,t1 ∨ ¬ctCS408,t1 ∨ ¬crCS101,r1 ∨ ¬crCS408,r1 )

7. Timeslot unavailability. The clauses are grouped by each teacher:


I1 :

(¬ctCS101,t1 ), (¬ctCS101,t2 )
I2 :

(¬ctCS202,t4 ), (¬ctCS402,t4 ), (¬ctCS402,t5 )


Hassan:

(¬ctCS304,t1 ), (¬ctCS305,t1 )

10
8. Room capacity. The clauses are grouped by courses:
CS101: ns = 75
(¬crCS101,r1 ), (¬crCS101,lab1 )
M271: ns = 90
(¬crM 271,r1 ), (¬crM 271,lab1 )
CS304: ns = 74
(¬crCS304,r1 ), (¬crCS304,lab1 )
CS305: ns = 79
(¬crCS305,r1 ), (¬crCS305,lab1 )
CS402: ns = 60
(¬crCS402,r1 ), (¬crCS402,lab1 )
CS408: ns = 55
(¬crCS408,r1 ), (¬crCS408,lab1 )

9. Every course must be scheduled to exactly one room. The clauses are grouped
by courses:
CS101:

exactly(1, {crCS101,r1 , crCS101,r2 , crCS101,lab1 , crCS101,lab2 })

exactly(1, {crCS101,lab1 , crCS101,lab2 })


CS202:

exactly(1, {crCS202,r1 , crCS202,r2 , crCS202,lab1 , crCS202,lab2 })

exactly(1, {crCS202,lab1 , crCS202,lab2 })


M271:
exactly(2, {crM 271,r1 , crM 271,r2 , crM 271,lab1 , crM 271,lab2 })
CS304:

exactly(1, {crCS304,r1 , crCS304,r2 , crCS304,lab1 , crCS304,lab2 })

exactly(1, {crCS304,lab1 , crCS304,lab2 })


CS305:

exactly(1, {crCS305,r1 , crCS305,r2 , crCS305,lab1 , crCS305,lab2 })

exactly(1, {crCS305,lab1 , crCS305,lab2 })


CS402:

exactly(1, {crCS402,r1 , crCS402,r2 , crCS402,lab1 , crCS402,lab2 })

exactly(1, {crCS402,lab1 , crCS402,lab2 })


CS408:

exactly(1, {crCS408,r1 , crCS408,r2 , crCS408,lab1 , crCS408,lab2 })

exactly(1, {crCS408,lab1 , crCS408,lab2 })

11
10. Number of lectures. The clauses are grouped by courses:
CS101:
exactly(2, {ctCS101,t1 , ctCS101,t2 , ctCS101,t3 , ctCS101,t4 ,
ctCS101,t5 })

CS202:
exactly(2, {ctCS202,t1 , ctCS202,t2 , ctCS202,t3 , ctCS202,t4 ,
ctCS202,t5 })

M271:
exactly(2, {ctM 271,t1 , ctM 271,t2 , ctM 271,t3 , ctM 271,t4 ,
ctM 271,t5 })

CS304:
exactly(2, {ctCS304,t1 , ctCS304,t2 , ctCS304,t3 , ctCS304,t4 ,
ctCS304,t5 })

CS305:
exactly(2, {ctCS305,t1 , ctCS305,t2 , ctCS305,t3 , ctCS305,t4 ,
ctCS305,t5 })

CS402:
exactly(2, {ctCS402,t1 , ctCS402,t2 , ctCS402,t3 , ctCS402,t4 ,
ctCS402,t5 })

CS408:
exactly(2, {ctCS408,t1 , ctCS408,t2 , ctCS408,t3 , ctCS408,t4 ,
ctCS408,t5 })

3.3.2 Solution
The following table can be created by feeding the encoding clauses to a Max-
SAT solver and looking at the truth assignments of the ct and the cr variables
in the output model.
Rooms/Timeslots t1 t2 t3 t4 t5
r1 CS305 lect. CS202 lect.
r2 M271 lect. M271 sec. CS101 lect. CS304 lect. CS408 lect.
lab1 CS101 lect. CS202 lab CS305 lab
lab2 CS402 lect. CS304 lab CS402 lab CS408 lab CS101 lect.

4 Conclusion and future work


This paper showed how to encode the timetabling problem of the department
of mathematics, Cairo university using Max-SAT technology. The constraints
specific to the problem have been encoded in CNF and all the clauses encoding

12
each constraint can be grouped together to form one CNF formula to be fed to
a Max-SAT solver and generate a solution. The timetable can be created by
checking the output model for the truth assignments of the basic variables of
the encoding. A detailed example has been given to illustrate the workings of
our method.
The encoding of some constraints can be further enhanced such as room
capacity. It is sometimes possible to split the students of a section or a lab-
oratory into two groups if the number of students exceeds the room capacity.
Each group can have its own group of teaching assistants. This idea is not very
applicable for lectures as the number of teachers is small compared to that of
teaching assistants.
We are also interested in the problem of determining the minimum amount
of a certain resource (e.g., rooms, timeslots) necessary to have a conflict-free
timetable.

References
[1] Ignasi Abıo, Robert Nieuwenhuis, Albert Oliveras, and Enric Rodrıguez-
Carbonell. A parametric approach for smaller and better encodings of
cardinality constraints. 2013.
[2] Roberto Ası́n Achá and Robert Nieuwenhuis. Curriculum-based course
timetabling with sat and maxsat. Annals of Operations Research, pages
1–21, 2012.
[3] Olivier Bailleux and Yacine Boufkhad. Efficient cnf encoding of
boolean cardinality constraints. In Principles and Practice of Constraint
Programming–CP 2003, pages 108–122. Springer, 2003.
[4] Stephen A Cook. The complexity of theorem-proving procedures. In Pro-
ceedings of the third annual ACM symposium on Theory of computing,
pages 151–158. ACM, 1971.
[5] Pedro Filipe Medeiros da Silva. Max-sat algorithms for real world instances.
2010.
[6] Mikoláš Janota, Inês Lynce, Vasco Manquinho, and Joao Marques-Silva.
Packup: Tools for package upgradability solving system description. Jour-
nal on Satisfiability, Boolean Modeling and Computation, 8:89–94, 2012.
[7] Filip Maric. Timetabling based on sat encoding: a case study, 2008.
[8] Joao Marques-Silva and Inês Lynce. Towards robust cnf encodings of cardi-
nality constraints. Principles and Practice of Constraint Programming–CP
2007, pages 483–497, 2007.
[9] Elizabeth Montero, Marıa-Cristina Riff, and Leopoldo Altamirano. A pso
algorithm to solve a real course+ exam timetabling problem. In Interna-
tional Conference on Swarm Intelligence, pages 24–1, 2001.

13
[10] Fahima NADER, Mouloud KOUDIL, Karima BENATCHBA, Lotfi AD-
MANE, Said GHAROUT, and Nacer HAMANI. Application of satisfiabil-
ity algorithms to time-table problems. Rapport Interne LMCS, INI, 2004.
[11] G-J Nam, Fadi Aloul, Karem A. Sakallah, and Rob A. Rutenbar. A compar-
ative study of two boolean formulations of fpga detailed routing constraints.
Computers, IEEE Transactions on, 53(6):688–696, 2004.
[12] Wayne Pullan. Protein structure alignment using maximum cliques and
local search. In AI 2007: Advances in Artificial Intelligence, pages 776–
780. Springer, 2007.
[13] Sean Safarpour, Hratch Mangassarian, Andreas Veneris, Mark H Liffiton,
and Karem A Sakallah. Improved design debugging using maximum satis-
fiability. In Formal Methods in Computer Aided Design, 2007. FMCAD’07,
pages 13–19. IEEE, 2007.
[14] Tian Sang, Paul Beame, and Henry Kautz. A dynamic approach to mpe and
weighted max-sat. In Proceedings of the 20th international joint conference
on Artifical intelligence, pages 173–179. Morgan Kaufmann Publishers Inc.,
2007.
[15] Michel Vasquez and Jin-Kao Hao. A logic-constrained knapsack formu-
lation and a tabu algorithm for the daily photograph scheduling of an
earth observation satellite. Computational Optimization and Applications,
20(2):137–157, 2001.
[16] Hui Xu, Rob A Rutenbar, and Karem Sakallah. sub-sat: a formulation
for relaxed boolean satisfiability with applications in routing. Computer-
Aided Design of Integrated Circuits and Systems, IEEE Transactions on,
22(6):814–820, 2003.

14

You might also like