# 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
Population crossover: Since the chromosomes contain two types of encodings, crossover operations must be performed accordingly for each type. First, the maternal population is sorted by fitness and then evenly divided into two sublists. Next, individuals at corresponding positions from the two sublists are selected for crossover pairing to effectively recombine genetic information. (1) Sequencing coding: For sorted encoding, partial-matched crossing is used. The crossing regions are identified, and the positions of the two sets of genes are swapped, as shown in Figure 7.  
After the initial crossover operation, systematic conflict detection is performed to identify potential conflicts in the coding bits. By analyzing the exchanged genomes, the mapping relationship is constructed; then, the chromosome is repaired, as shown in Figure 8.  
Finally, the results of the sort encoding are shown in Figure 9.  
(2) Directional coding: Two points are randomly selected in two coding strings, and the gene fragments between these two points are exchanged, as shown in Figure 10. The method is direct and effective, aiming to explore the solution space and enhance genetic diversity through the recombination of gene fragments. Figure 8: Gene conflict detection. Figure 6.0 Swap gene positions. Figure 6.1 Sorting encoding crossover. Finally, the results of the sort encoding are shown in Figure 6.2  
6. Population variation: In the variation process of ordering encoding, the inversion mutation operator is applied. Two encoding positions are randomly selected based on a preset probability, and their positions are swapped, as shown in Figure 6.3 For directional encoding, each encoding position undergoes possible mutations independently and with the same probability, as shown in Figure 6.4  
7. Generate progeny: The parent population is combined with the population obtained in Step 6 to form a merged population that is twice the size of the initial population. Subsequently, the merged population is sorted based on the fitness of individuals, and the top \(m\) individuals with the highest fitness are selected to form the next generation population. Step 4: UAV landing hive optimization based on the enhanced elite retention genetic algorithm: To ensure that only one UAV resides in each hive at the beginning and end of the mission, this study introduces Constraint (13) and employs genetic algorithms with enhanced elitist retention to optimize UAV landing in the hive. Transfer between cells is achieved by adding UAVs to the mission list while reducing air loss under endurance constraints. In addition, the mission sequence is reviewed; eligible air flights are merged, and the objective function values are updated to optimize landing assignments and avoid UAV collisions. After completing the above four steps, the pre-processing optimization phase is over. This phase aims to optimize the order and direction of each UAV's mission to minimize the distance flown. Finally, the total flight distance and the individual flight distance of each UAV are obtained. These optimization results are presented in the form of populations and serve as input to the ENS_SS function for non-dominated sorting, which is used to classify population individuals hierarchically based on non-dominated relationships and provide a basis for subsequent genetic algorithm operations.