## 3 Master-Slave Optimization Framework
### Slave Stage: Load Flow Problem via Successive Approximations
If any violation of operational, voltage, current, or diesel generator power constraints is detected, penalty terms are incorporated into the objective function to discourage the selection of such solutions during the optimization process. 4. **Incorporation of penalty terms**: If any constraint violations are detected, corresponding penalty terms are added to the objective function to penalize infeasible solutions. This evaluation is performed using the fitness functions described in (1) and (2). The penalization used is explained below: To manage constraint violations within the optimization process, the proposed strategy incorporates penalty terms directly into the objective function. This mechanism modifies the evaluation of candidate solutions by penalizing infeasibilities, thereby guiding the search toward viable regions of the solution space. 5. Penalty-adjusted evaluation: Each solution is assessed using a penalized objective, denoted as the adjusted fitness (\(f_{\text{Eval}}\)), which merges the original cost metric (\(f_{\text{Obj}}\)) with an aggregated penalty component (\(\Phi\)): \[f_{\text{Eval}}=f_{\text{Obj}}+\Phi\] (31) This formulation ensures that solutions violating constraints receive degraded evaluations, making them less likely to persist in the optimization process. 6. Penalties in grid-connected operation: When operating in grid-connected mode, constraint breaches primarily relate to load balancing and voltage regulation: \[\Phi=\alpha_{1}\cdot\delta_{\text{Current}}+\alpha_{2}\cdot\delta_{\text{ Voltage}}\] (32)
7. \(\delta_{\text{Current}}\): Quantifies the deviation from permissible branch current limits;
8. \(\delta_{\text{Voltage}}\): Measures voltage violations across the system;
9. \(\alpha_{1},\alpha_{2}\): Tunable penalty weights, chosen to ensure constraint violations significantly degrade solution quality. - \(\delta_{\text{Pslack}}\): Quantifies the energy injected from the microgrid into the slack node during islanded operation, where the slack corresponds to the diesel generator;
- \(\delta_{\text{Diesel}}\): Captures instances where the diesel generator operates outside its nominal range;
- \(\alpha_{3},\alpha_{4}\): Penalty coefficients calibrated to prioritize feasibility in isolated mode. Penalty coefficients are deliberately set to high values to ensure that any constraint violation results in a significant degradation in the fitness function, effectively discarding infeasible solutions early in the optimization process and preserving the robustness of the search. In this particular case, the penalty weights were tuned heuristically, with all coefficients set to 1000 in grid-dependent mode and increased to 1500 in self-powered mode to enforce stricter feasibility requirements. Furthermore, the power balance is satisfied through the application of the power flow algorithm, which evaluates the nodal injections based on the operational states of distributed generators, storage units, and loads. The power output limits of the photovoltaic generators are inherently respected by their operation under MPPT control. Additionally, the proposed encoding structure ensures compliance with both the maximum charge/discharge power and the state-of-charge bounds of the batteries, thus guaranteeing the physical feasibility of each candidate solution generated by the optimization methodologies. * **Fitness function evaluation**: After completing the simulations for all 24 h, the total energy losses and CO2 emissions of the MG are quantified. Additionally, any penalties resulting from constraint violations are incorporated into the overall fitness value. As the magnitude of detected violations increases, indicating technical feasibility, the objective function value also increases. Consequently, such solutions are discarded both as viable candidates and as potential stepping points in the convergence path, prompting the initiation of a new optimization cycle focused on feasible regions of the search space.