## 4 Racing + CBR Module
### CBR Submodule
#### 4.2.1 Retrieving Phase  
The retrieving phase aims to search the casebase for the most similar  
After initializing the variables, the algorithm begins by making a pre-selection of cases, to select only cases that might be considered sufficiently similar, i.e., with similarity greater than the minimum similarity of 0.70. For each pre-selected case, the similarity to the new case is calculated, and if it is better than or equal to the previously specified minimum similarity, the case is added to the list to be returned, together with the respective similarity value. At the end of the algorithm, this list of cases is returned. One of the most important aspects of a CBR system is the similarity measure between cases. The attributes to consider for the similarity measure are: the number of tasks (\(Njobs\)), the number of machines (\(Nmachines\)), the type of problem (\(ProbType\)), the multi-level (if instances have operations with more than one precedence) feature (\(MultiLevel\)) and the known optimal conclusion time (\(OptC_{max}\)). These attributes are weighted differently in the similarity measure, as defined in Equation (5). The similarity measure is a value between zero (0) and one (1), corresponding to no similar cases and equal cases respectively. It is the result of a weighted sum of the similarities between the different attributes. In Equation (6), the weights for each attribute are presented. More importance is given to \(Njobs\) and \(Nmachines\), as these are the ones that best define the problem dimension, a fundamental characteristic for metheuristic tuning. \(Njobs\) is the most important attribute of the problem dimension, since it defines how many jobs are processed. \(Nmachines\) defines how these tasks are divided for processing. Thus, we considered a weight of 50% for \(Njobs\) and 25% for \(Nmachines\). These two attributes together represent 75% of the similarity measure. \(ProbType\), with 15%, represents some importance for the parameter tuning, since, e.g., a job-shop problem introduces additional complexity as compared to a single machine problem. With only 5% each, it was considered that \(MultiLevel\) and \(OptC_{max}\) are not as important as other attributes; however, they are important for the verification of very similar cases. The \(OptC_{max}\) attribute was taken into account in order to make it possible to know whether the new case has been previously processed or not because, when known, this is a unique characteristic of a problem. \[\text{similarity}=\sum_{\text{i=0}}^{\text{n}}\text{w}_{\text{i}}\times \text{sim}_{\text{i}} \tag{5}\]  
where \(\text{w}_{\text{i}}\) is the weight of characteristic i and \(\text{sim}_{\text{i}}\) is the similarity of characteristic i.  
\[\text{w}_{\text{Njobs}}=0.50;\text{w}_{\text{Nmachines}}=0.25;\text{w}_{\text{ ProbType}}=0.15;\text{w}_{\text{MultiLevel}}=\text{w}_{\text{OptC}_{\text{max}}}=0.05; \tag{6}\]  
\[\text{sim}_{\text{Njobs}}=\frac{\text{min}(\text{Njobs}_{1},\text{Njobs}_{2})} {\text{max}(\text{Njobs}_{1},\text{Njobs}_{2})} \tag{7}\]  
\[\text{sim}_{\text{Nmachines}}=\frac{\text{min}(\text{Nmachines}_{1},\text{ Nmachines}_{2})}{\text{max}(\text{Nmachines}_{1},\text{Nmachines}_{2})} \tag{8}\]  
\[\text{sim}_{\text{ProbType}}= \begin{cases}0&\text{if ProbType}_{1}\
eq\text{ ProbType}_{2}\\ 1&\text{if ProbType}_{1}=\text{ProbType}_{2}\end{cases}  \tag{9}\]  
\[\text{sim}_{\text{MultiLevel}}= \begin{cases}0&\text{if MultiLevel}_{1}\
eq\text{ MultiLevel}_{2}\\ 1&\text{if MultiLevel}_{1}=\text{MultiLevel}_{2}\end{cases}  \tag{10}\]  
\[\text{sim}_{\text{OptC}_{\text{max}}}= \begin{cases}\frac{\text{min}(\text{OptC max}_{1},\text{OptCmax}_{2})}{\text{max}(\text{OptCmax}_{1},\text{OptCmax}_{2})}&\text{if OptCmax}_{1}\geq 0\text{ and OptCmax}_{2}\geq 0\\ 0&\text{if OptCmax}_{1}<0\text{ or OptCmax}_{2}<0\end{cases}  \tag{11}\]  
The Njobs and Nmachines similarities (Equations (7) and (8)) are calculated in the same way, yielding a value in a \([0;1]\) range.