## 4 The TLBO Optimization Method
### Discrete TLBO
#### 4.2.2 DTLBO Teacher Stage  
At this stage, a Partial Teacher is selected for each subpopulation. As with the original TLBO, this teacher is used to improve the students in each subpopulation taking into account the mean value of the subpopulation. In addition, to avoid losing the global vision of the route, a global Teacher is also selected as the best individual of the whole population. It must be taken into account that the calculation of the mean individual could violate the path conditions of the TSP, so a viability condition must be added to its calculation. This condition is performed in the following four steps  
* The number of times a place appears is counted. To store the places that appear more than once, the _TempA_ vector is used. Each place is stored in the last position (higher index) that it occupies in the original unfeasible vector; in case a place does not appear or just appears once, the corresponding item remains empty (symbol -). In Figure 2, it can be observed that locations 3 and 5 appear in the last positions they occupied in the original unfeasible vector, that is, positions 5 and 6, respectively.
* Search for the missing locations. Again, in Figure 2 it can be seen that places 1, 6, and 7 do not appear. The _TempA_ vector is used to store these places. In this vector, the index of the place that does not appear is written in the associated item, leaving the remainder of the items empty.
* A vector _TempC_ is created to indicate the places that appear just once. In Figure 2, it can be observed that places 0, 2, and 4 appear in their corresponding positions within _TempC_.
* Using the above mentioned vectors, a viable individual is constructed by adding to the empty items of _TempA_ and _TempC_ the places that do not appear in them and that are found in _TempB_.  
Figure 1: Representation of an individual solution.  
The crossover operation is used in the DTLBO to generate new individuals from existing ones. This operation is indicated by the symbol \(\otimes\). In this version of the algorithm, four different ways of creating new individuals from crossovers were introduced and are shown in Equation (5). In contrast to the work presented in [35], in which a fixed cross is assigned between individuals, this approach makes a random selection for each cross operation. This randomness avoids falling into local minima and increases the variability of populations.  
\[\begin{array}{l}X\textit{new}(i)=X(i)\otimes\textit{Teacher}\\ X\textit{new}(i)=X(i)\otimes\textit{PartialTeacher}(i)\\ X\textit{new}(i)=X(i)\otimes\textit{Mean}(i)\\ X\textit{new}(i)=\textit{PartialTeacher}(i)\otimes\textit{Mean}(i)\\ \end{array} \tag{5}\]  
The operation of the crossover can be shown in Figure 3. Suppose that two individuals \(A\) and \(B\) must generate a new one called \(A_{c}\). The initial and final positions of the new individual are selected randomly and thus the new individual \(A_{c}\) replaces the selected items by those of individual \(B\). Logically, after this crossover is performed, the viability operation must be applied.  
To increase the variability of the populations, a mutation operator is included, which is denoted by the symbol \(\Theta\) (shown in the Equation (6)). Figure 4 shows the functionality of this operator. Given an \(A_{c}\) individual, initial and final positions are randomly selected; in the current example, these are positions 3 and 6. Once these positions are determined, the elements included in this sequence (items of positions 3, 4, 5, and 6) are inverted to create the mutated element \(A_{cm}\).  
\[A_{cm}(i)=\Theta A_{c}(i) \tag{6}\]  
Figure 4: An example of the mutation operation.  
Figure 3: An example of the crossover operation.  
Figure 2: An example of the viability operation.