## 4 A Two-Stage Optimal Scheduling Model for Wind-PV-Thermal-Storage System
### Solutions
#### 4.3.2 Algorithm Steps  
Bat algorithm [29] based on the genetic algorithm is applied to solve the two-stage optimal scheduling model in the wind-PV-thermal-storage system. The algorithm steps are as follows:  
Step 1: initialize the algorithm parameters, and generate the gene sequence of the individual bat, in which wind power, photovoltaic power, load, and other parameters are set according to the generation-load uncertainty model. In addition, determine the number of iterations is 1000 and objective function \(f(X)\). Set the total number of bats \(N_{\rm pop}\), position \(X_{0}\), flight speed \(v_{0}\), loudness \(A_{0}\), and frequency \(f_{0}\).  
Step 2: randomly generate \(N_{\rm pop}\) bats within the feasible range of control variables as the current optimal solution set, calculate the objective function value of the current bat gene sequence and sequence them from small to large, and retain the first half of the individual bats for update and proliferation.  
Step 3: start iterative calculations. Change frequency and update individual speed, and take the new bat population as the parent generation to carry on selection, velocity push average crossover and mutation, and then constitute the first half of the offspring bat population;  
Step 4: update the individual location of the parent bat population, and then determine whether the local search condition rand1\(>r_{I}\) is satisfied. If so, the optimal solution is selected for local search to get a new position to replace the original position;  
Step 5: determine whether the new fitness value satisfies \(f(X_{I})<f_{best}\) and the random number rand2\(<A_{I}\). If so, the new solution is accepted to form the second half of the offspring bat population, and the function value of the individual bat is updated;  
Step 6: rank and evaluate the objective function value of the entire offspring population, and then update the current optimal position (solution) \(X_{s}\);  
Step 7: determine whether the maximum number of iterations is exceeded. If so, return step 2. Otherwise, end the algorithm and the optimal value is output.  
Figure 3 shows the two-stage optimal scheduling solution flow chart proposed in this paper, including day-ahead scheduling and intraday scheduling. In the day-ahead stage, according to the wind energy, photovoltaic energy, total load of the system and price-type demand response model mentioned above, Monte-Carlo method is used to conduct random sampling, and then the improved bat algorithm is used to solve day-ahead scheduling plan, so as to determine thermal power unit start-stop combination, electricity price in each period and price demand response quantity. In the intraday stage, according to the parameter distribution functions of wind, photovoltaic, and load, a two-point estimation stochastic optimization model is built to calculate the minimum average adjustment cost and determine the output of thermal power units, and the process is shown in Figure 4,  
Figure 3: Two-stage optimal scheduling solution flow chart.  
and details are analyzed in the Appendix C. Based on this, the improved bat algorithm is used to obtain the IDR quantity and the output of other units.