# Spinning Reserve Capacity Optimization of a Power System When Considering Wind Speed Correlation
## 4 Solution Algorithm
### Quantum-Behaved Particle Swarm Optimization  
The QPSO is a probability search algorithm that introduces quantum mechanics into particle swarm optimization (PSO). The average best position \(C(k)\) is introduced into QPSO to calculate variables in the following iteration:  
\[C(k)=\frac{1}{M}\sum_{i=1}^{M}\mathbf{p}_{i}(k)=(\frac{1}{M}\sum_{i=1}^{M}p_{i,1}( k),\frac{1}{M}\sum_{i=1}^{M}p_{i,2}(k),\ldots,\frac{1}{M}\sum_{i=1}^{M}p_{i,N}(k)), \tag{31}\]  
where \(M\) is the number of the swarm, \(k\) is the current number of iterations, and \(\mathbf{p}_{i}\) is the local best position of the swarm \(i\).  
The particle position of decision variables \(\mathbf{x}_{i}\) is updated through the Monte Carlo stochastic simulation, as follows:  
\[\mathbf{x}_{i}(k+1)=\mathbf{p}_{i}\pm\lambda\cdot|C(k)-\mathbf{x}_{i}(k)|\cdot\ln[1/u], \tag{32}\]  
where \(u\) is uniform random numbers in the interval [0,1], and \(\lambda\) is the contraction-expansion coefficient, which can be applied to control the convergence speed of PSO algorithm. The contraction-expansion coefficient is defined as  
\[\lambda=(1-0.5)\times(M_{\rm axiter}-k)/M_{\rm axiter}+0.5, \tag{33}\]  
where \(M_{\rm axiter}\) is the maximum number of the inner iterations.  
The flow chart of the proposed QPSO based on Equations (31)-(33) is shown as Figure 1.  
The detailed procedure is as follows:  
1. Obtain the correlated wind speed data of wind farms, according to Section 2.3;
2. Read the system data, such as the prediction values of the loads and wind power output and the probability distribution of the prediction deviation. In addition, set the input the parameters of the quantum-behaved particle swarm optimization algorithm, such as maximum iteration number and particle swarm size;
3. Initialize the population. The active power and reserve capacity of each thermal power unit are randomly generated to form the population, which is tested according to Formulas (15)-(24); if the population is not feasible, it will be regenerated until Formulas (15)-(24) are satisfied;
4. Calculate the average best position of the particle swarm, according to Formula (31), and then calculate the fitness function value of particles at the current location according to Formula (10);
5. Update the position of the particles. The position of each particle is updated according to Formula (32), and the limit is verified. If the decision variables are beyond their limits, the particles are renewed. Besides, a random simulation is also employed to verify whether the particles are satisfied with the predetermined confidence level, and if they do not satisfy the confidence level, the particles will be renewed. Then the fitness function values of each particle are calculated. If they are superior to the extreme value of the current particles, the individual extremum is updated. If the individual extreme value of the population is better than the current global extreme value, then update the global optimum;  
Figure 1: Flow chart of the quantum-behaved particle swarm optimization (QPSO) algorithm.  
Determine whether the convergence condition \(|F(k+1)-F(k)|\leq\varepsilon\) is satisfied, or if the number of iterations is reached. If it is not satisfied, then go back to Step 4--otherwise, output the best particle as the optimal solution.