# Optimizing the Scheduling of Teaching Activities in a Faculty
## 3 Model of the Automatic Timetable Generation System
### Problem Formulation  
In the context of generating a university timetable using the Timefold Solver, the objective function is designed to satisfy multiple constraints and to find an optimal or near-optimal assignment of lessons to rooms and timeslots. This involves assigning each lesson to a specific room and timeslot while minimizing violations of the constraints.  
Given that the timetable generation problem is a Constraint Satisfaction Problem (CSP) [48], the objective function can be structured as a multi-objective optimization function, where each constraint is weighted according to its importance.  
Let,  
* \(L=\{l_{1},\,l_{2}\ldots,\,l_{n}\}\) represent the set of lessons that need to be scheduled.
* \(R=\{r_{1},\,r_{2}\ldots,\,r_{m}\}\) represent the set of rooms in which lessons can take place.
* \(T=\{t_{1},\,t_{2}\ldots,\,t_{p}\}\) represent the set of discrete time intervals during which lessons can be scheduled.
* \(S=\{s_{1},s_{2},\ldots,s_{q}\}\) be the set of student groups.
* \(D=\{d_{1},\,d_{2}\ldots,\,d_{5}\}\) represent the set of days in the week.
* _cap_ (\(r\)) be the capacity of room \(r\).
* _students_ (\(l\)) be the number of students enrolled in lesson \(l\).
* _teacher_ (\(l\)) be the teacher assigned to lesson \(l\).
* _duration_ (\(l\)) be the duration of lesson \(l\).
* _duration_ (\(t\)) be the duration of timeslot \(t\).
* _group_ (\(l\)) be the student group attending lesson \(l\).
* _room_ (\(l\)) denote the room assigned to lesson \(l\).
* _building_ (\(r\)) represent the building associated with room \(r\).
* \(C_{hard}\), \(C_{medium}\), \(C_{soft}\) represent the hard, medium, and soft constraints, respectively.  
The objective function can be written as follows:  
\[Z=\sum_{h\in\overline{C_{band}}}w_{h}\cdot V_{h}+\sum_{m\in\overline{C_{medium}}}w_{ m}\cdot V_{m}-\sum_{s\in\overline{C_{soft}}}w_{s}\cdot V_{s} \tag{1}\]  
where  
* \(Z\) is the overall cost (objective value) to be minimized.
* \(w_{h}\), \(w_{m}\), \(w_{s}\) are weights associated with the hard, medium, and soft constraints, respectively (with \(w_{h}\ \gg\ w_{m}\ \gg\ w_{s}\), since hard constraints are the most critical).
* \(V_{h}\), \(V_{m}\), \(V_{s}\) represent the number of violations for the respective constraint types (hard, medium, and soft, respectively).
* The objective is to minimize \(Z\), ideally achieving \(V_{h}=0\) to ensure a feasible timetable, while minimizing \(V_{m}\) and maximizing \(V_{s}\). In practice, this function is represented as a 3-level score in the system in the following way: (\(V_{h}\) hard/\(V_{m}\) medium/\(V_{s}\) soft). Let \(x_{l,r,t}\) be a binary decision variable, where \[x_{l,r,t}=\left\{\begin{array}{ll}1,&\quad if\ lesson\ l\ is\ assigned\ to\ room\ r\ at\ timeslot\ t,\\ 0,&\quad otherwise\end{array}\right.\] (2)  
Thus, the decision space for the problem can be represented as a 3D matrix \(X\ \in\ \{0,1\}^{n\times m\times p}\), where each element \(x_{l,r,t}\) indicates whether a lesson \(l\) is assigned to a room \(r\) and a timeslot \(t\), and the search space size, where the possible number of solutions for the timetable problem can be determined, is \(S=(p\ \times\ m)^{n}\).