# Optimization of PV and Battery Energy Storage Size in Grid-Connected Microgrid
## 4 Results and Discussion
Figure 6: Particle best cost per iteration and best costs through all iterations of the proposed energy management method with PSO: (**a**) case 1; (**b**) case 2. As can be seen, this process is not simple, such as defining the number of PV and battery modules regarding the known changing load demand. PV generation changes according to irradiation and weather conditions. There is an allowed grid supply limit that is defined at the system design stage. Therefore, the energy management algorithm should decide when to charge and discharge the batteries, and when to obtain energy from the grid by considering cost. Eventually, the results show that the proposed optimization algorithm correctly determines the optimum PV and BESS size within the defined constraints. The proposed energy management system with the PSO algorithm has some advantages and superiorities. It also needs only a few initial parameters. In addition, it can be used with different algorithms. Furthermore, the constraints and parameters used in the energy management strategy are also configurable such that they can be easily adapted for different systems. The flexible nature of the proposed approach is its most important strength. Figure 7: System total cost for various PV and BESS module combinations: (**a**) case \(1\); (**b**) case 2. In order to test the performance of the PSO-based method with the energy management algorithm, its performance is compared with GA, which is the one of the well-known optimization algorithms. The obtained results with the GA are shown in Figure 8a,b for case 1 and case 2, respectively. The parameters used in the GA algorithm are as follows: the population size is set to 50, the maximum number of iterations is set to 200, crossover rate = 1, mutation rate = 0.04, and the number of battery and PV module is limited from 1 to 50. As can be seen in Figure 8a,b, the novel energy management method with the PSO algorithm gives better performance than the novel energy management method with the GA algorithm. In addition, the energy management method with GA found that the optimum PV and BESS modules count as 47 and 28, respectively, and the total cost is USD 40.972 at the 192 nd iteration for case 1 and the PV and BESS modules count as 24 and 28, respectively, and the total cost is USD 24.186 at the 187 th iteration for case 2. It takes more time to find the global point than the proposed algorithm. Furthermore, this comparison is proven that the proposed novel energy management system can also work with other algorithms. Comparisons between existing studies and the proposed study are given in Table 3. A close examination of Table 3 provides an idea of the difference between the proposed system and the other algorithms. In past studies, various algorithms have been used for different systems for optimization. This study differs from other studies in the following aspects. As can be seen from the table, some of the studies in the literature do not use the PSO algorithm for both PV and BESS sizing. In most of the studies, one of the PV and BESS parameters was kept constant, and the other parameter was optimized. Although the PSO optimization algorithm has been proposed for both PV and BESS in a limited number of studies, they have only been used for island mode systems. Most of the remaining studies did not use cost minimization as an objective function or energy management system. A limited number of studies have used cost minimization as an objective function or energy management system, but with different optimization algorithms. Figure 8: Obtained best cost results obtained from the proposed energy management method with GA: (a) case1; (b) case2.