## 4 Application of PSO to Solve the Proposed Optimization Problem  
Meta-heuristic optimization algorithms are highly popular for solving complex, non-linear, and non-convex optimization problems. Particle swarm optimization (PSO) is one such popular meta-heuristic optimization algorithm and is based on swarm-intelligence, which is popularly used to obtain a global solution for several problems [46]. PSO uses the position and velocity of swarms to find a global solution. Thus, it was chosen to solve the proposed optimization problem formulated in the previous section of this paper. The proposed method is used for minimizing four objective functions (VUF, VD, CC, BC). A high penetration with different phase connections can cause voltage unbalance and voltage deviations. The proposed method is separated into two stages, where the first stage aims to minimize voltage unbalance, charging costs, and battery degradation costs by using active power as a decision variable. The second stage aims only to minimize voltage deviation by obtaining the optimal active power to calculate the proportional reactive power, which is the decision variable of the second stage. The advantage of dealing with voltage deviation in the second stage is to avoid overvoltage occurring in some time intervals if it is located in first stage, and it is able to improve positive sequence voltage, which reduces voltage deviation, as well as VUF, according to Equation (6). Another advantage is that decreasing the objectives in the first stage decreases complicated searching of global optimal solution. The major steps of the proposed method are shown in Figure 3 and are as follows:Step 1: Specification of the total number of iterations, population size, and hours (h). Step 2: Random initialization of the particle position according to the population size in each bus that connects to EVs. \[P_{EV}=[P_{EV,1}^{j},P_{EV,2}^{j},P_{EV,3}^{j},\ldots P_{EV,j}^{j}] \tag{19}\]  
Step 3: Find the position of \(P_{EV,i}\) at \(j+1\) iteration \(P_{EV,i}^{j+1}\) and velocity of the \(P_{EV,i}^{j+1}\) at \(j+1\) iteration \(v_{i}^{j+1}\)as:  
\[P_{EV,i}^{j+1}=P_{EV,i}^{j}+v_{i}^{j+1} \tag{20}\]  
\[v_{i}^{j+1}=\omega v_{i}^{j}+c_{1}\bullet rand_{1}^{j}(pbesl_{i}^{j}-P_{EV,i}^{ j})+c_{2}\bullet rand_{2}^{j}(gbest_{k}^{j}-P_{EV,i}^{j}) \tag{21}\]  
Step 4: Calculate the fitness values for the Stage I objective functions given by Equations (1), (3), and (4). The weight sum method is used to combine the multiple objectives into a single one. \[Min_{x}F_{ws}=\theta_{1}(F_{1}(x)/F_{1,nor})+\theta_{2}(F_{2}(x)/F_{2,nor})+ \ldots\theta_{n}(F_{n}(x)/F_{n,nor}) \tag{22}\]  
This process utilizes DlgSILENT software to run the unbalance load flow and obtain the value of the fitness function. Step 5: PSO will then compare the obtained fitness with the global best solution. The global best solution is changed if the local best solution is better. Figure 3: Application of PSO to solve the proposed method. Step 6: Continue until a maximum number of iterations is reached. Step 7: Proceed to the second stage and initialize the constraints according to the population size for each bus, which has EVs, using Equation (23) when EVs are charging and discharging. \[Q_{EV}=[Q_{EV,1}^{j},Q_{EV,2}^{j},Q_{EV,3}^{j},\ldots Q_{EV,i}^{j}] \tag{23}\]  
Step 8: Find the position of the particle at \(j+1\) iteration \(Q_{EV,i}^{j+1}\) and velocity of the particle at \(j+1\) iteration \(v_{i}^{j+1}\) as Step 3. \[Q_{EV,i}^{j+1}=Q_{EV,i}^{j}+v_{i}^{j+1} \tag{24}\]  
\[v_{i}^{j+1}=\omega v_{i,k}^{j}+c_{1}\times rand_{1}^{j}(pbest_{i,k}^{j}-Q_{EV, i}^{j})+c_{2}\times rand_{2}^{j}(gbest_{k}^{j}-Q_{EV,i}^{j}) \tag{25}\]  
Step 9: Compute the fitness function by solving Equation (6). This step utilizes DIgSILENT software. Step 10: Find the best current and global solution. Step 11: Continue until a maximum number of iterations is reached. Step 12: Store the optimal \(P_{Chg}\), \(P_{Dchg}\), \(Q_{Dchg,GZV}\), \(Q_{Dchg,V2G}\). Step 13: Increase the hours and stop when the maximum hour is reached.