## 4 Racing + CBR Module
### CBR Submodule
#### 4.2.2 Reusing Phase  
In the reusing phase, the most similar case to the new case is selected, and the respective solution is suggested as a possible solution. Thus, the metaheuristic and the parameters used for the resolution of that case are copied to the resolution of the new case. In Algorithm 7, three variables are initialized: \(simVerySimilar\) to determine if two cases are very similar; \(listBestCases\) for storing the list of best retrieved cases; and \(minRatio\) to serve as a comparison determining the best cases. ```
Input:\(listCases\) Output:\(bestCase\)  Begin \(simVerySimilar\gets 0.95\)\(\triangleright\) similarity to validate if two cases are very similar \(minRatio\gets 0.75\)\(\triangleright\) minimum ratio to add a case into \(listBestCases\leftarrow\emptyset\)\(\triangleright\) list to store the best cases if\(listCases\) is emptythen bestCase\(\gets applyPreDefinedParameters()\) else for all\(case\in listCases\)do if\(compareSims(case,bestCase)\geq simVerySimilar\)then ratio\(\leftarrow\) case.OptCmax\(/case\_Cmax\) if\(ratio\geq minRatio\)then listBestCases.add\((case)\) else \(ratioBest\gets bestCase.OptCmax/bestCase.Cmax\) if\(ratio=ratioBest\)then if\(case.TimeExec<bestCase.TimeExec\)then bestCase\(\leftarrow\) case endif else if\(ratio>ratioBest\)then\(\triangleright\) case is more effective \(bestCase\leftarrow\) case \(\triangleright\) update best case endif endif endif else\(\triangleright\) cases are not very similar, so compare similarities directly if\(case.Sim>bestCase.Sim\)then\(\triangleright\) case more similar \(bestCase\leftarrow\) case \(\triangleright\) update best case endif endif if if\(listBestCases\) is not emptythen \(index\gets random(0,size(listBestCases))\)\(\triangleright\) randomly selects a case to be considered as the best bestCase\(\leftarrow\) listBestCases.get\((index)\) endif endfor endif return\(bestCase\)  End
```
**Algorithm 7** Reusing phase. First, the algorithm checks if the list of retrieved cases is not empty. If it is empty, then there are no cases with similarity higher than the minimum similarity. This means that the predefined parameters are used, working as a starting point for the resolution of future similar cases. When the list of retrieved cases has elements, the most effective cases are selected. However, if there is no effective case, the most similar case is selected. In this cycle, some checks are carried out to determine if there are cases with very high similarity. If so, the best cases or the most effective/efficient cases are selected, by comparing the conclusions and running times. The verification of very similar cases is performed using Equation (12), and then the value is compared with \(simVerySimilar\). For this variable, the value of 0.95 was considered; two cases are very similar if the ratio of their similarities is greater than 95%. When there are very similar cases, it is necessary to calculate the ratio (Equation (13)) between \(OptCmax\) and \(Cmax\) of each case to make the comparison with \(minRatio\). This variable indicates that a case is considered as one of the best if the ratio of its \(OptCmax\) by its \(Cmax\) is equal to or greater than 75%. When this happens, the case is added to \(listBestCases\). When the ratio of a case, \(ratio_{case}\), is not greater than \(minRatio\), it is necessary to calculate the ratio for the best case so far. If the ratio of a particular case is equal to \(bestCase\) ratio, the two cases are equally effective and it is necessary to compare the execution times. If the case runtime is lower than \(bestCase\), then \(bestCase\) is updated as a more efficient case has been found. The \(bestCase\) is also updated if the ratio of a particular case is higher than \(bestCase\) ratio, as a more effective case has been found. When there are not very similar cases, the best case is chosen by a direct comparison between the similarities from the list of cases.