## 3 Solution Methodology
### Population-Based Genetic Algorithm (PGA)
Then, mutation introduces changes in the offspring by randomly generating values between the minimum and maximum power limits assigned to the time periods selected for this effect. The time periods for mutation and the number of periods dedicated to this process are defined as PGA parameters, and they generally affect the proposed encoding. * **Step 5. ** The fitness function of the offspring population is evaluated using the aforementioned hourly power flow method. * **Step 6. ** Based on the fitness values of the offspring and parents, a comparison is made, and the parents with lower fitness than the best offspring are replaced. It is possible that, in a given iteration, the entire parent population is replaced without affecting convergence since the offspring's encodings contain the information from the best parents. * **Step 7. ** The incumbent solution is updated. * **Step 8. ** If the maximum number of iterations is reached, the incumbent solution is selected as the optimal solution to the problem, and the iterative process is terminated. If the maximum number of iterations is not reached, the process returns to Step 4, and the iterations continue from there. The pseudocode presented in Algorithm 1 is associated with the above-presented process is as follows:  
```
Data: Read the parameters of the MG and the PGA for\(t=1:iter_{max}\)do if\(iter==1\)then 1. Randomly generate the initial population 2. Evaluate the fitness function for each individual in the population using the hourly power flow 3. Select the best solution as the incumbent else 4. Generate the offspring population using selection, recombination, and mutation processes 5. Evaluate the fitness function of the offspring population using the hourly power flow 6. Replace parents with offspring that improve the fitness function 7. Update the incumbent with the best solution 8.ifHas the stopping criterion been met?then 8.1 Terminate the iterative process and select the incumbent as the final solution Break; else 8.2 Return to Step 4
```  
**Algorithm 1**Iterative process of the PGA  
In this methodology, the fitness function is responsible for evaluating the impact of each individual on the operating costs, energy losses, or \(CO_{2}\) emissions of the MG, as well as on its set of constraints. This function processes the data provided by the PGA and ensures that each solution complies with the technical and operational constraints of the MG. The evaluation allows the PGA to operate efficiently, ultimately guiding the search toward the optimal solution for the MG. The process implemented for evaluating each of the individuals generated by the PGA for each hour of the day is as follows:  
* **Step 1. ** The power demand of the users connected to the MG during hour \(h\) is entered. * **Step 2. ** The active and reactive power supplied by the WTs in the system is entered for hour \(h\). * **Step 3. ** The system's load flow for hour \(h\) is executed using the SA method. This method calculates the magnitude of the nodal voltages in the network, which are necessary for calculating the objective function and system constraints [42]. \[V_{d,h}^{t+1}=-Y_{dd}^{-1}[diag^{-1}(V_{d,h}^{t})S_{d,h}+Y_{dg}V_{g,h}]\] (16) Equation (16) is used to calculate the nodal voltages, where \(V_{d,h}^{t+1}\) represents the voltages at all demand nodes during the \(h\)-th period of iteration \(t+1\). In addition, \(Y_{d,d}^{-1}\) is the admittance matrix relating the demand nodes, and \(S_{d,h}\) corresponds to the power demand and the WTs' generation. \(Y_{d,g}\) and \(V_{g,h}\) represent the connection to the reference node and its voltage, respectively. The recursive process converges when the stopping criterion reaches a convergence tolerance of \(\varepsilon=1\times 10^{-10}\). * **Step 4. ** Using the previously obtained information, the objective function is calculated. Depending on the case, this may refer to operating costs, energy losses, or \(CO_{2}\) emissions. Subsequently, the violations of the previously established constraints are calculated.