# Advancing Multi-UAV Inspection Dispatch Based on Bilevel Optimization and GA-NSGA-II
## 3 Solution Algorithm
### Nested Bilevel Optimization Algorithm
#### 3.2.2 Path Optimization Based on the Enhanced Elite Retention Genetic Algorithm  
Aiming at the dependence of UAVs on specific hives, this section focuses on the optimization strategies of takeoff and landing hives. In addition, in view of the limitations that power consumption may pose to mission execution during takeoff and landing, this section will also discuss the scheme of task re-segmentation by taking into account the takeoff and landing energy consumption to ensure the completion of UAV mission execution. The detailed steps are as follows:  
Step 1: Takeoff hive optimization: To ensure that each hive is served by at least one UAV, we take the following steps to determine the starting hive for the UAVs: First, calculate the distances from the starting and ending transmission towers of the UAV's task to each candidate hive. Next, sum up the total distances from the starting and ending towers to the assigned hives for each UAV. Finally, select the solution with the minimum total distance as the final result. Step 2: Hive insertion within unit tasks: During task execution, UAVs may experience reduced endurance due to the need to transfer between towers and hives. To avoid this risk, the algorithm evaluates the total energy consumption of unit tasks before optimizing UAV routes. If the total energy consumption is less than the UAV's safe flight range, the task segment is considered continuously executable. Conversely, if the total energy consumption exceeds the UAV's safe flight range, additional hives are introduced as waypoints, and the unit tasks are further divided to ensure feasibility. The specific process of task segmentation is shown in Figure 5.  
Step 3: Sorting and fusion of unit tasks: After the endurance is verified, each UAV is given a final unit task to perform. This section uses the genetic algorithm to enhance the elite retention policy to improve inspection efficiency and path optimization. The steps of the algorithm are as follows:  
1. Population coding: The chromosome uses a two-part integer encoding strategy, and its length is set to twice the number of tasks assigned by the UAV. The first half of the code consists of a sequential sequence of natural numbers that define the execution order of the task unit in the flight table. The second half of the code adopts an independent 0, 1 binary format, which is used to specify the execution direction of the unit task, and the chromosome structure is shown in Figure 6.  
2. Population initialization: In the initialization phase, the task units assigned to each UAV are first renumbered. The sequence number of the task unit is generated by a random algorithm to ensure that the probability of each unit task being assigned the execution direction is equal. The above arrangement is fused with the code of the patrol direction to form a chromosome. This process is repeated until an initial population that meets the preset size is built. 3. Decoding and fitness calculation: Individual encodings are parsed, and the unit task list according to sort encoding is rearranged. The execution direction of the tasks according to the direction code is determined: If the direction code is 0, the tasks are arranged in ascending order of the tower number. If the direction code is 1, it is sorted in descending order. The value of the objective function is calculated according to the optimized flight list to evaluate the individual fitness of the task, thereby ensuring the minimization of the flight distance of each UAV. The fitness function is as follows:  
\[\mathrm{fitness_{p}}=\mathrm{min}(\sum_{q=1}^{|M|}\mathrm{L_{pq}}\mathrm{y_{ pq}}),p=1,2\ldots|\mathrm{U}| \tag{17}\]  
4. Selection operator: The binary tournament method is used to randomly select two individuals and compare their fitness, and the individuals with better fitness are put  
Figure 5: Transit live insertion. Figure 6: Inner chromosome encoding. into the next generation population. This process is repeated until a sufficient number of individuals are selected. 5.