# Optimizing the Scheduling of Teaching Activities in a Faculty
## 5 The Development of Theoretical/Practical Contributions
### Implementation Details
#### 5.4.3 Timefold for Timetable Generation
For each lesson \(l_{i}\) (in descending order of difficulty), find the most suitable pair of room \(r_{k}\) and timeslot \(t_{j}\) that  
Figure 7: Timefold domain model. The * means “multi” relationship. \begin{table}
\begin{tabular}{c c} \hline \hline \multicolumn{2}{c}{**Timefold Configuration**} \\ \hline \multicolumn{2}{c}{**InitializingScoreTrend**} & **MoveThreadCount:** \\ \hline \multirow{8}{*}{Description} & This parameter is set to AUTO, which \\  & This parameter defines the trend of \\  & the score during the initialization \\  & phase, while the previously initialized \\  & variables remain unchanged. Some \\  & optimization algorithms, including \\  & Construction Heuristics, can achieve \\  & better execution times when provided \\  & with such information. \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Timefold configuration. minimizes constraint violations. This can be formulated as minimizing the cost function \(f\) (\(l_{i}\), \(r_{k}\), \(t_{j}\)), which represents the penalty for assigning a lesson \(l_{i}\) to room \(r_{k}\) in timeslot \(t_{j}\):  
\[\min_{l_{i}\in L,r_{k}\in R,t_{j}\in T}f\big{(}l_{i},\ r_{k},\ t_{j}\big{)} \tag{19}\]  
By assigning the most difficult lessons first to the best available room-timeslot pairs, the algorithm tackles the hardest parts of the problem early, reducing the complexity of the remaining assignments. The Late Acceptance Algorithm is a local search algorithm that accepts solutions based on their quality relative to past solutions rather than the immediate current solution. This approach helps avoid being trapped in local optima. This algorithm can be described as follows: Let \(LA\_size\) be the number of previous solutions to be considered and _accepted-CountLimit_ be the number of consecutive non-improving moves allowed before stopping. Let the initial solution be \(S_{0}\) with an objective value \(Z\) (\(S_{0}\)). Maintain a memory buffer \(M=[Z\) (\(S_{1}\)), \(Z\) (\(S_{2}\)),..., \(Z\) (\(S_{LA\_size}\))] of the objective values of the last \(LA\_size\) solutions. For each iteration \(k\), generate a new candidate solution \(S_{k}\) and calculate its objective value \(Z\) (\(S_{k}\)). The new solution \(S_{k}\) is accepted if:  
\[Z(S_{k})<Z(S_{k-LA\_size}) \tag{20}\]  
That is, the new solution is accepted if it is better than the solution from \(LA\_size\) iterations ago, even if it is worse than the current solution. If no better solution is found after _acceptedCountLimit_ consecutive iterations, the search is terminated. Tabu Search is a local search algorithm that uses memory structures to avoid revisiting recently explored solutions, encouraging the search to explore new regions of the solution space. Mathematically, it can be described as follows: Let \(Tabu\_size\), the size of the tabu list (how many recent solutions are considered \"tabu\") and _acceptedCountLimit_, the number of consecutive iterations allowed before termination. Start with the initial solution be \(S_{0}\) with an objective value \(Z\) (\(S_{0}\)). In each iteration, explore the neighborhood \(N\) (\(S_{k}\)). of the current solution \(S_{k}\). The neighborhood \(N\) (\(S_{k}\)) consists of solutions that can be reached by making small changes to \(S_{k}\) (e.g., swapping rooms or timeslots for two lessons). Maintain a tabu list \(T\) of size \(Tabu\_size\). A move that leads to a solution that is in the tabu list is forbidden (tabu) unless it satisfies an aspiration criterion (i.e., if it significantly improves the solution). If the move leads to a solution \(S_{k+1}\) such that \(Z\) (\(S_{k+1}\)) \(<Z\) (\(S_{\text{best}}\)), it is accepted regardless of whether it is tabu. Among the non-tabu moves in the neighborhood \(N\) (\(S_{k}\)), select the move that leads to the solution with the best objective value \(Z\) (\(S_{k+1}\)). The new solution \(S_{k+1}\) is added to the tabu list, and the oldest entry in the tabu list is removed, keeping the tabu list size constant at \(Tabu\_size\).