## 4 Optimal Algorithm for Maximum Consumption of DG  
In this paper, according to the objective function and constraint conditions described in the previous section, a particle swarm optimization (PSO) algorithm is used to obtain the maximum output scheme of DG under load variations. Due to the large number of control variables, it is easier for the traditional PSO algorithm to get into the local optimal solution. In order to improve the global search ability of PSO in the initial stage and to ensure better search performance in local optimization in the later stages, this study modified the inertia weight of PSO and introduced the second-order nonlinear decreasing inertia weight \(w\)[23], so as to better balance the global search ability and local search ability of the algorithm. Compared with the linear decreasing inertia weight, this method has a better ability to get out of the sub-optimal solution. The improved particle swarm updating equation is shown in (22). \[\left\{ \begin{array}{c}v_{id}^{k+1}=w_{id}^{k}+c_{1}r_{1}(P_{Bid}^{k}-x_{id }^{k})+c_{2}r_{2}(G_{bd}^{k}-x_{id}^{k})\\ x_{id}^{k+1}=x_{id}^{k}+v_{id}^{k+1}\\ w^{k+1}=w_{\rm start}-(w_{\rm start}-w_{\rm end})\Big{(}\frac{k}{r}\Big{)}^{ 2}\end{array} \right. \tag{22}\]  
where: \(V_{id}\) is the velocity of the particle; \(K\) is the number of current iterations; \(w\) is the inertia weight coefficient, which represents the coefficient that the particle maintains its original velocity; \(c_{1}\) and \(c_{2}\) are the learning factors of particles, respectively self-cognition and social cognition. \(P_{id}\) is the historical optimal value searched by the \(i\) th particle itself. \(X_{id}\) is the current position of the particle; \(r_{1}\) and \(r_{2}\) are random numbers in the interval [0,1]. \(P_{gd}\) is the optimal solution currently searched by all particles. Further, \(w_{start}\) is the initial inertia weight; \(w_{end}\) is the inertia weight when iteration reaches the maximum number; \(T_{max}\) is the maximum number of iterations. The inertia weight of the improved PSO algorithm decreases with the increase of the iteration number, and the change of the initial inertia weight \(w_{start}\) to the end of the iteration weight \(w_{end}\) changeswith the change of an iteration number as a quadratic function. At the beginning of iteration, the inertia weight is larger, the step size of searching for the optimal particle iteration is larger, and the ability of searching in a wide range is stronger. As the number of iterations increases, the inertia weight decreases, and the step size of the particle iteration to find the optimal one decreases. Therefore, the particles conduct deep excavation near the current optimal solution. The flow chart of the improved PSO algorithm is shown in Figure 4.  
The weight coefficient is determined by combining the analytic hierarchy process and entropy weight method mentioned in Section 2. The specific steps are as follows:  
1. Using the weight coefficient \(\omega_{j}\) obtained by the analytic hierarchy process to construct a single objective function, the fitness function of PSO is used to conduct an iterative solution of PSO;
2. The optimal position reached by each particle (including the local optimal solution and the global optimal solution) is recorded, as are the four single objective function values which correspond to the optimal position of each particle as the basic data;  
Figure 4: Flow chart of improved particle swarm optimization. The use of basic data on the entropy weight of each objective function value calculation, and according to (13), the comprehensive consideration of the analytic hierarchy process and entropy weight method of each objective function weight coefficient \(\lambda_{1}\), \(\lambda_{2}\) through the integration of the two methods obtains the objective function index weight coefficient as \(\lambda_{1}=0.734\), \(\lambda_{2}=0.266\).