## 3 The Machine Learning Swarm Intelligence Algorithm
### Repair Operator and Local Search Operator  
This section aims to explain the repair algorithm, which is also used to identify a new optimum as part of the local search process. Algorithm 3 presents the pseudocode for the repair and local search operator. The operator starts by taking the solution (\(Sol\)) obtained from the binarized metaheuristic as input and initializes two variables--_candidates_ and \(isImproved\). The algorithm continues while \(isImproved\) remains as 0. A movement--either add, drop, swap, or randomly one of the three--is selected to perform the repair and local search for improvement. The impact of each operator is analyzed to compare their effects. If the add operation is selected, elements not currently in the solution are sequentially added and evaluated using the penalty function defined in Equations (4) and (5), as proposed by [12]. \[P(Sol)=\sum_{i=1}^{m}\max\left(0,\sum_{j=1}^{n}a_{ij}x_{j}-c_{i}\right)+\sum_{ i=q+1}^{q+m}\max\left(0,c_{i}-\sum_{j=1}^{n}a_{ij}x_{j}\right) \tag{4}\]  
\[F(Sol)=\sum_{j=1}^{n}p_{j}x_{j}-\lambda\times P(Sol) \tag{5}\]  
Solutions that do not meet the constraints can still be incorporated if they improve the penalized objective function \(F\), defined in (5). This process is repeated for each element not currently in the solution. If the addition of an element improves the penalized objective function over the previous one, the element is added to the solution. In Equation (4), the penalty applied depends on whether \(\sum_{j=1}^{n}\) exceeds or falls short of \(c_{i}\), with the penalty decreasing as \(\sum_{j=1}^{n}\) approaches \(c_{i}\). The same procedure is applied for dropping an item or swapping elements between the solution and those not in it. Finally, the candidates are checked to determine if any of them satisfy the constraints, and if so, the best candidate is selected and \(isImproved\) is updated to 1. In the case of the local search operator, the same movements are used, but the algorithm runs for a fixed number of iterations (2000). \(Sol\) is a valid solution and, at the end of the iterations, it is verified whether a better valid solution was found than the original one. ```
1:Function enhancedRepairAndLocalSearch(\(Sol\), operationType, iterationLimit)
2:InputSol, operationType, iterationLimit
3:OutputSol
4:candidates \(\leftarrow\) []
5:\(isImproved\)\(\leftarrow\) FALSE
6:\(iteration\)\(\leftarrow\) 0
7:whileiteration \(<iterationLimit\)do
8:ifoperationType == \"add\"then
9:\(newSol\)\(\leftarrow\) addItem(\(Sol\))
10:elseifoperationType == \"drop\"then
11:\(newSol\)\(\leftarrow\) dropItem(\(Sol\))
12:elseifoperationType == \"swap\"then
13:\(newSol\)\(\leftarrow\) swapItem(\(Sol\))
14:elseifoperationType == \"mix\"then
15:\(randomOperation\)\(\leftarrow\) randomly choose between \"add\", \"drop\", or \"swap\"
16:if\(randomOperation==\) \"add\"then
17:\(newSol\)\(\leftarrow\) addItem(\(Sol\))
18:elseif\(randomOperation==\) \"drop\"then
19:\(newSol\)\(\leftarrow\) dropItem(\(Sol\))
20:elseif\(randomOperation==\) \"swap\"then
21:\(newSol\)\(\leftarrow\) swapItem(\(Sol\))
22:endif
23:endif
24:ifnewSol improves based on Equation (5) then
25:\(candidates.append(newSol)\)
26:\(isImproved\)\(\leftarrow\) TRUE
27:\(Sol\)\(\leftarrow\) newSol
28:endif
29:\(iteration\)\(\leftarrow\)\(iteration+1\)
30:endwhile
31:if\(isImproved\)then
32:\(Sol\)\(\leftarrow\) selectBestCandidate(candidates)
33:endif
34:returnSol
```  
**Algorithm 3** Enhanced Repair and Local Search Operator  
Algorithm 3 provides a flexible framework to study the impact of different repair strategies in optimization problems. The following four configurations are explored: Addition only, Drop only, Swap only, and a mixed strategy incorporating all three. Each configuration helps analyze the effects of the corresponding operation on solution improvement, as follows:  
* Addition Only: This strategy focuses solely on adding new elements to \(Sol\), testing whether incremental additions can improve the penalized objective function while maintaining constraints.