## 3 Two-Stage Stochastic Optimization Problem  
In actual flight scenarios, wind speed and wind direction are characterized by randomness, volatility, and intermittency. Deterministic models for optimizing the system's total cost fail to account for these uncertainties, leading to a significant deviation between the optimization results and the actual situation. Therefore, a two-stage stochastic programming model is developed to optimize the capacity configuration of hydrogen hybrid UAVs considering uncertainty. This study proposes a two-stage stochastic programming model that uses the particle swarm optimization (PSO) algorithm to optimize the first-stage device capacity. The second stage uses random wind speed and wind direction scenarios generated by the Monte Carlo method, combining the optimal device capacity from the first stage to obtain the expected optimal cost of the system under different scenarios. This expected cost serves as the fitness function for the PSO algorithm, continuously evolving the first-stage optimization process. It can be understood as taking the UAV's flight power demand as input, and after considering the uncertainty of the wind field, along with balance constraints, capacity constraints, and energy storage constraints, deriving the expected optimal cost of the system under different scenarios. Then, the particle swarm optimization algorithm is used to optimize the system, ultimately determining the optimal equipment capacity to meet various flight scenarios. CPLEX typically uses branch-and-bound and cutting-plane methods to solve MILP models, incorporating preprocessing and heuristic methods. Therefore, the CPLEX solver can be used to solve the second-stage MILP problem. The specific process is shown in Figure 2.  
The process is based on solving the MILP problem and the PSO algorithm, using Monte Carlo simulation to generate random scenarios for the system, and accounting for uncertainty in the system. The main steps include particle swarm generation, fitness calculation, particle position update, particle velocity update, boundary check, and termination condition check. The specific computational steps are as follows:  
Step 1: Initial Particle Swarm Generation:  
Define the space range within which the particles can move. Within this range, randomly generate the position vector and velocity vector for each particle. Step 2: Fitness Calculation:  
For each individual in the particle swarm, substitute it into each scenario generated by Monte Carlo simulation to obtain the expected value for each scenario, i.e., the fitness of the individual. In cases of no solution or failed solution, a large value can be added to the fitness function to lower the fitness of that individual, further screening the particles. Step 3: Update Global Best Particle and Individual Best Particle:  
Based on the fitness function values, select the particle with the best fitness among the current individuals, as well as the global best particle. Step 4: Boundary Check:  
Verify the updated particle positions and velocities, and if any particle exceeds the boundary, regenerate its position and velocity randomly. Step 5: Repeat Steps 2-4 until the iteration conditions are met, exit the loop, and obtain the optimal solution. In addition, PSO includes the number of particles, \(N\), maximum number of iterations, _Max_iteration_, dimensionality, dim, lower boundary of the search space, \(I_{b}\), and upper boundary of the search space, \(u_{b}\). The core of the PSO algorithm is to simulate the movement of multiple particles within the search space, where each particle represents a potential solution. The selection of the number of particles needs to balance performance and computation time. The maximum number of iterations refers to the maximum number of updates for the particles' velocity and position. The lower and upper boundaries of the search space define the lower and upper limits of the decision variables.