## 3 Upper-Level Multiple Resources Coordinated Optimization Modeling and Solving
### Model Analysis and Solving
#### 3.3.2 Model Solving  
The classical PSO algorithm treats the solution of the optimization problem as a particle in space without mass and volume, and the update of the particle is determined by a combination of inertial motion, self-awareness, and social learning. The particle merit is evaluated according to the adaptation value determined by the objective function of the optimization problem. In this paper, the classical PSO algorithm is improved by using dynamically updated inertia weights. A larger inertia weight at the beginning of the algorithm iteration can improve the global search capability, and a smaller inertia weight at the end of the iteration can improve the local search capability. In the improved PSO algorithm, the inertia weights are updated in each iteration, and if the current position of the \(i\)th particle (\(\mathbf{x}_{i}=(x_{i1},x_{i2},\cdots,x_{iD})\), \(D\) is the particle space dimension) is known, then the particle velocity \(\mathbf{v}_{i}(n+1)\) (\(\mathbf{v}_{i}=(v_{i1},v_{i2},\cdots,v_{iD})\)) at the next moment is calculated based on the inertia weights (\(\omega(n)\)), and thus the new position of the particle at the next moment (\(\mathbf{x}_{i}(n+1)\)) can be calculated. The update of the particle position can be expressed as  
\[\omega(n)=\omega_{\text{max}}-n(\omega_{\text{max}}-\omega_{\text{min}})/n_{ \text{max}} \tag{15}\]  
\[\mathbf{v}_{i}(n+1)=\omega(n)\mathbf{v}_{i}(n)+\alpha_{1}\beta_{1}(\mathbf{x}_{\text{pbest },i}-\mathbf{x}_{i}(n))+\alpha_{2}\beta_{2}(\mathbf{x}_{\text{gbest}}-\mathbf{x}_{i}(n)) \tag{16}\]  
\[\mathbf{x}_{i}(n+1)=\mathbf{x}_{i}(n)+\eta_{\text{PSO}}\mathbf{v}_{i}(n+1) \tag{17}\]  
where \(\omega(n)\) is the calculation formula of dynamic inertia weight. \(n\) is the current number of iterations. \(n_{\text{max}}\) is the maximum number of iterations. \(\omega_{\text{max}}\) and \(\omega_{\text{min}}\) are the maximum and minimum values of dynamic weights, respectively. \(\mathbf{v}_{i}\) is the velocity of the \(i\)th particle in the population. \(\alpha_{1}\) and \(\alpha_{2}\) are the acceleration coefficients; \(\alpha_{1}\) corresponds to self-learning ability and \(\alpha_{2}\) corresponds to the social learning ability, that is, to learn from the optimal individual in the population. \(\eta_{\text{PSO}}\) is the weight coefficient of speed update. In the solving of PSO, the fitness value can be obtained by adding penalty factors to the constraints into the objective function. The value of the penalty factors should be much larger than the estimated optimal value of the objective function. Therefore, the calculation formula of fitness can be expressed as follows,  
\[\text{fitness}=F+h_{1}f(f_{\text{dn}})+h_{2}f(f_{\text{ss}})+h_{3}f(\Delta \delta)+h_{4}f(V^{\text{min}})+h_{5}f(S_{\text{sp}}) \tag{18}\]  
where \(h_{1}-h_{5}\) are the penalty factors of each constraint. \(f(\cdot)\) is the penalty term corresponding to the constraints. Taking the transient frequency nadir constraint \(f(f_{\text{dn}})\) as an example, it can be expressed as  
\[f(f_{\text{dn}})=\text{max}(0,f_{\text{dn,min}}-f_{\text{dn}}) \tag{19}\]  
The particle positions obtained by the particle swarm initialization and iteration are the control amounts of resources for EFC. The control amounts are input into the electromechanical transient simulation software to obtain power grid status trajectory data. Based on the status trajectories, the fitness and penalty term corresponding to each constraint can be calculated. In each iteration of PSO, it takes very little time to update the particle positions, and most of the computation time is used to obtain the simulation trajectory from electromechanical transient simulation software. The parallel simulation of the electromechanical transient can reduce the time consumption of each iteration of PSO. The electromechanical transient simulation can be parallelized by calling multiple cores on one computer/server or by using several computers/servers simultaneously for each iteration.