## 3 Solution Methodology
### Population-Based Genetic Algorithm (PGA)
All of this is done for the hour \(h\) under analysis. * **Step 5. ** Using the outcomes of the preceding evaluations, the fitness function integrates the original objective function with penalty terms that are activated when key constraints are violated. In this case, this has to do with the nodal voltage limits, line current capacities, and diesel generator output bounds. As the problem is formulated as a minimization task, constraint violations increase the objective function value, discouraging the selection of infeasible solutions. This penalization strategy not only enforces constraint compliance but also enhances the optimizer's ability to explore near-infeasible regions. This improves population diversity, accelerates convergence, and often yields higher-quality solutions with reduced computational effort [31]. The corresponding formulation of the fitness function is presented below: \[FF=FO+Pen\] (17) Equation (17) represents the fitness function (\(FF\)), which is composed of the objective function (\(FO\)) to be minimized and a penalty (\(Pen\)) that is applied if the established loading and voltage constraints are violated. In this particular case, the best solution of the \(FF\) corresponds to the smallest value found. As penalty in the grid-connected case, the following is considered: \[Pen=fp_{1}\cdot Vl_{load}+fp_{2}\cdot Vl_{voltage}\] (18) In Equation (18), \(V_{load}\) and \(V_{voltage}\) correspond to loading and voltage violations, respectively, and \(fp_{1}\) and \(fp_{2}\) are penalty factors implemented when the aforementioned violations occur. These penalty factors were heuristically set as 1000, thereby increasing the value of the associated objective function. This implies that the solution quality will be reduced as a consequence of the penalties incurred due to violations. On the other hand, for the islanded operation, two additional constraints must be added, as shown in the following equation: \[Pen=fp_{1}\cdot Vl_{load}+fp_{2}\cdot Vl_{voltage}+fp_{3}\cdot Vl_{black}+fp_{4 }\cdot Vl_{disel}\] (19)Here, \(VI_{load}\) and \(VI_{voltage}\) are the same as those mentioned in Equation (18), while \(VI_{Pslack}\) and \(VI_{diesel}\) correspond to the violations associated with energy sales at the slack node and with generation outside the established limits of diesel generators. It is worth emphasizing that, in this study, certain constraints are not included in the fitness function since they are inherently satisfied through structural aspects of the model that guarantee feasibility by design. Specifically, the active and reactive power limits of the WTs are inherently satisfied through the adopted encoding strategy (see Figures 3-5). Each candidate solution is constructed within admissible power ranges determined by wind resource availability and by the rated capacity of power converters. This approach ensures that the generation limits of the WTs are respected at all times without the need for penalization in the adaptation function, which reduces the computational burden while improving search efficiency. Moreover, the active and reactive power balance within the MG is addressed through a power flow analysis executed on an hourly basis. This analysis, based on the SA method (Equation (16)), solves the Nonlinear Balance Equations (4) and (5), ensuring that each candidate solution satisfies the physical laws governing power injection, demand, and network behavior. As such, the power balance constraint is not handled through penalty terms but rather through explicit calculation, which makes it an intrinsic part of the model evaluation. By managing these constraints in a structural fashion via encoding and power flow analysis, the model avoids unnecessary penalization and enhances computational efficiency, allowing the fitness function to focus solely on dynamic and system-dependent constraints. * **Step 6. ** The fitness functions for each hour \(h\) are then summed to obtain a single value. * **Step 7. ** Finally, the fitness function is sent to the PGA.