# An Evolutionary-Based MPPT Algorithm for Photovoltaic Systems under Dynamic Partial Shading
## 2 Evolutionary-Based MPPT Algorithm for PV System Power Extraction
### PSO-Based Algorithm Implementation
The initial positions of the particles, namely a first solution vector of duty cycles with \(N_{p}\) elements, are calculated: they are linearly spaced between the minimum and maximum duty cycle to cover the whole search space. All of the variables that contain information related to a previous GMPP search are reset. Then, the algorithm transmits the first duty cycle to the power converter. The change of duty cycle causes a transient of the electrical system; the new steady state condition will be evaluated at the next time interval. 3. _Fitness Evaluation and Update Individual Best Data_. The fitness value \(P_{PV}(n)\) (actual PV output power) of the \(i\)-th particle, is calculated. Both the best individual position, \(d_{best,i}\), and the best fitness, \(P_{PVbest,i}\), are updated in case the fitness value is greater than the best fitness. If the particle that hasjust been evaluated is not the last one, the algorithm transmits the next duty cycle to the power converter, whose fitness function will be evaluated at the next time interval. Otherwise, global best data will be updated and operations after each \(k\)-th iteration will be performed. 4. _Update Global Best Data and End-of-Iteration checks_. This step is the end of each \(k\)-th iteration. Both the global best position, \(D_{best}\), and the global best fitness, \(P_{PV,Gbest}\), are updated in case the maximum of the best fitness values of particles is greater than the global best fitness. A counter, \(CounterG_{best}\), is set to 1 at every global best position update, otherwise it is incremented. 5. _Convergence Determination and Reset Criterion_. The convergence determination proposed in this work is based on the number of iterations without the update of \(D_{best}\): the convergence is reached in case a new \(D_{best}\) is not found in the last \(N_{Gbest}\) iterations. Moreover, a maximum number of iterations, \(N_{Iter}\), is allowed to reach convergence. In case the convergence is not met within the number of allowed iterations, the algorithm has to update the velocity and position of each particle and has to perform another search iteration (move to Step 6). In case the convergence is met within the number of allowed iterations, the algorithm transmits \(D_{best}\) to the power converter to check the solution (move to Step 7). If the maximum number of allowed iterations is reached without convergence, the search for the GMPP has to be repeated (move to Step 2). 6. _Update Velocity and Position of Each Particle_. After all the particles are evaluated and convergence is not achieved, the velocity and the position of each particle have to be updated by using Equations (3) and (4). Then, the algorithm transmits the first duty cycles to the power converter. At the next time interval, the algorithm will move to Step 3. 7. _Check the GMPP_. The duty cycle of the power converter is \(D_{best}\); the actual PV output power, \(P_{PV}(n)\), is compared with the global best fitness, \(P_{PV,Gbest}\). The GMPP is reached if the absolute value of the difference between these powers is below a threshold. This check is necessary in case of dynamic partial shading, when the P-V curve changes significantly during the GMPP search process. Under these conditions, several fitness functions are sampled during the GMPP search process, making the information of \(d_{best,i}\) and \(D_{best}\) totally useless for tracking the actual GMPP. In case the result of the GMPP check is not successful, a new full scan is necessary and the algorithm immediately moves to Step 2. Otherwise, it is assumed that the GMPP has been reached and the power converter will be operated with the duty cycle \(D_{best}\) until a change in the environmental conditions, namely a change in the PV output power, triggers a new scan. Figure 3 shows the timing of the proposed PSO-based MPPT algorithm.