5.4. Cost Function
In the process of unmanned aerial vehicle (UAV) path planning, the cost function serves as the criterion for evaluating the relative merits of different paths. A well-designed cost function guides the algorithm to generate safe and efficient paths within complex environments, avoiding terrain obstacles and hazardous zones. This paper constructs the following UAV path cost function by comprehensively considering multiple factors, including maximum flight range, minimum flight altitude, turn angle, and avoidance of hazardous zones:
The coefficients ω1, ω2, ω3, and ω4 represent the weights assigned to distance, altitude, turning angle, and threat costs, respectively. Following the principles of safety and operational efficiency, these weight coefficients are set as follows:
Threat weight ω4 = 5: The threat cost is the most critical safety constraint in path planning. Entering a threat zone may result in mission failure; therefore, the threat cost is assigned the highest weight to ensure that the algorithm always prioritizes path safety.
Distance weight ω1 = 1: Path length directly affects UAV energy consumption and mission duration. As a key factor secondary only to safety, it is assigned a moderately high weight to encourage the algorithm to search for shorter paths.
Altitude weight ω3 = 0.5: The turning angle cost mainly influences path smoothness and flight maneuverability. Its importance is lower than that of threat avoidance and path length, so it is assigned a moderate weight to prevent unnecessary sharp turns while avoiding excessive penalization of path curvature.
Angle weight ω2 = 0.05: The magnitude of the altitude cost is typically much higher than other cost terms. Without proper normalization, it could dominate the optimization process. Therefore, a relatively small weight is assigned to ensure safe altitude while minimizing its interference with distance and threat optimization.
5.4.1. Distance Cost
The path distance directly affects the UAV’s energy consumption and flight time; therefore, it is essential to consider the distance between each consecutive path node during path planning. The distance cost term,
, can be obtained by summing the Euclidean distances of all consecutive segments along the path, which is calculated as follows:
Here, represents the spatial distance between two consecutive nodes and , while denotes the spatial distance between the consecutive nodes and .
5.4.2. Angular Cost
In UAV path planning, the smoothness of path turning plays a critical role in ensuring flight stability and reducing maneuvering load. Excessively large turning angles can not only increase lateral overload but also lead to abrupt maneuvers, higher energy consumption, and in some cases, infeasible flight actions. Therefore, in this study, an angular cost term,
, is introduced into the objective function to penalize large turning angles along the path, thereby improving the overall path smoothness. The angular cost term is calculated as follows:
5.4.3. Altitude Cost
During the UAV’s flight from the start point to the endpoint, both terrain clearance and altitude constraints must be satisfied. To ensure flight safety, the UAV should neither fly too low, which would increase the risk of collision, nor fly excessively high, which would result in unnecessary energy consumption. To address this, an altitude cost term is incorporated into the objective function to penalize unsafe altitude behaviors. If the flight path maintains a safe altitude and changes smoothly, the corresponding cost remains low. Conversely, if the flight altitude falls below the minimum allowable height
or approaches the terrain height
, the cost increases significantly to avoid potential collision risks. Terrain elevation data are obtained from a pre-established three-dimensional digital elevation model (DEM). For any given path point
, the corresponding terrain height
is determined through terrain interpolation and contributes to the computation of the altitude cost
, as expressed in Equation (28).
Here, denotes the flight altitude at the -th path point, represents the minimum allowable flight altitude, and indicates the terrain elevation at the -th point. The parameter defines the minimum safety distance to avoid collision with the terrain. is the penalty coefficient applied when the flight altitude falls below the minimum allowable altitude , while is the penalty coefficient applied when the flight altitude is lower than the sum of the terrain height and the safety distance. These penalties are used to strictly prevent the UAV from flying through the terrain.
5.4.4. Threat Costs
In practical flight environments, UAVs must strictly avoid obstacles, terrain, and no-fly zones. Therefore, this study incorporates a threat evaluation function
into the cost function to determine whether any point
along the path approaches or enters the
-th threat region.
Each threat source is modeled as a spherical region, where
represents the center of the threat and
denotes its radius. An additional safety buffer of
is applied around each sphere to mitigate the risk of boundary crossing due to positioning errors or airflow disturbances. When
, it indicates that the path intersects with an obstacle or a no-fly zone, and the path is immediately deemed infeasible. In this study, all threat sources are treated as forbidden regions; if any of these regions are violated, a penalty is imposed on the total cost function, as defined in Equation (30):
Here, denotes the total number of threat sources. If , it indicates that the path has entered an obstacle or a no-fly zone at least once, and consequently, is forcibly increased by approximately tenfold. Conversely, if , all path nodes are within safe regions, and a smaller penalty is applied to encourage maintaining a safe distance.
5.5. UAV 3D Path Planning Simulation and Analysis
In this work, three-dimensional UAV path planning experiments were performed using MATLAB R2022a. To enable the UAV to effectively circumvent terrain obstacles and reach the destination safely, the planning framework was developed on a 3D terrain model incorporating predefined threat regions. Two mountainous environments were constructed, containing three and six threat zones, respectively, to emulate flight scenarios of differing complexity and evaluate the CTWRBMO algorithm’s performance under various environmental conditions. The UAV’s operational domain was specified as a
spatial grid. The initial position was set to (15.15, 30.3, 295.9), while the destination point was defined as (449.5, 459.6, 422). A summary of the environmental configurations is presented in
Table 7, and detailed parameters of the threat models are listed in
Table 8. The corresponding 3D terrain model generated from these parameters is depicted in
Figure 8.
In this study, three-dimensional UAV path planning in Environments 1 and 2 was investigated using five optimization algorithms—ABC, AVOA, HHO, RBMO, and the proposed CTWRBMO. The selection of these algorithms is based mainly on two considerations. First, ABC is a classical benchmark algorithm that provides a reliable baseline for comparison; HHO and AVOA are recently proposed algorithms that have demonstrated competitive performance in recent years; and RBMO is adopted as the baseline algorithm for improvement to verify the effectiveness of the proposed strategies. In addition, during preliminary exploratory experiments, we observed that in strongly constrained three-dimensional environments involving complex terrain, obstacles, and multiple kinematic constraints, general-purpose swarm intelligence algorithms such as PSO, GTO, and WOA have difficulty in stably generating feasible and safe paths when no additional constraint-handling or path-repair mechanisms are incorporated. To avoid compromising the fairness and consistency of the comparative study due to the use of different constraint-handling strategies across algorithms, these algorithms were not included in the three-dimensional path planning comparisons.
Furthermore, in order to enhance the ability of the algorithm to generate feasible solutions in a strongly constrained three-dimensional environment and to further improve the comparability among different algorithms, this study introduced the same initial path generation strategy for all the compared algorithms to construct feasible initial solutions. This initial path serves only as a starting reference for the search process and does not participate in the fitness evaluation during the subsequent path optimization process, thereby avoiding any bias impact on the final optimization result.
To further guarantee the comparability of the experimental results, the population size of all algorithms was set to 50, and the maximum number of iterations was fixed at 100. Each algorithm was independently executed 30 times in both Environment 1 and Environment 2. The optimal, mean, and variance of the path lengths obtained from these 30 independent runs are reported. A smaller mean indicates a lower average path planning cost, while the variance reflects the stability and robustness of the algorithms in three-dimensional environments.
In addition, multiple performance metrics were evaluated, including average computational time, path feasibility rate, path smoothness, and energy consumption, to comprehensively assess the performance and applicability of each algorithm. The energy consumption of each UAV path was calculated using a simplified model that considers the Euclidean distance between consecutive waypoints, the path curvature (which indirectly reflects the UAV’s maximum turning angle constraint), and vertical energy expenditure (which indirectly reflects climb and descent rates). Although simplified, this model provides a consistent and fair basis for comparing different algorithms. The parameter settings for all algorithms are summarized in
Table 9.
This study presents representative three-dimensional side views and top views of typical experimental results to facilitate an intuitive comparison of the performance of different algorithms in three-dimensional UAV path planning. The results for Environment 1 are illustrated in
Figure 9a,b. In this scenario, the number of threat regions is relatively small. The path planned by the CTWRBMO algorithm exhibits overall altitude stability, with a smooth flight trajectory throughout the mission and no abrupt turning angles, demonstrating strong obstacle avoidance capability. In contrast, the UAV paths generated by the other algorithms show larger altitude fluctuations and tend to fly closer to mountainous terrain, indicating weaker obstacle avoidance and threat avoidance capabilities, which makes flight safety difficult to guarantee.
The results for Environment 2 are shown in
Figure 9c, where a larger number of threat regions are present. Except for the CTWRBMO algorithm, the paths generated by the other algorithms exhibit significant altitude fluctuations and poor trajectory smoothness. Nevertheless, even in this more complex environment, the path produced by CTWRBMO maintains minimal altitude variation and superior smoothness, as further illustrated by the top view in
Figure 9d. The paths generated by RBMO and ABC contain large turning angles, which increase the overall path length and result in sharper maneuvers. By comparison, the CTWRBMO algorithm produces a smoother and shorter path.
Table 10 summarizes the path planning performance of the different algorithms. In Environment 1, the average path cost of CTWRBMO is lower than that of RBMO, HHO, ABC, and AVOA by 6.04%, 36.23%, 4.29%, and 31.43%, respectively. In Environment 2, the reductions are 6.29%, 30.22%, 6.18%, and 31.38%, respectively, indicating that CTWRBMO is highly effective in minimizing path length.
Path success rate was used to evaluate the reliability of an algorithm in generating feasible paths. The results show that both CTWRBMO and ABC achieve a 100% success rate in both environments, meaning that all paths generated during 30 independent runs were feasible and did not pass through threat zones or produce abnormal trajectories. RBMO maintains a 100% success rate in Environment 1 but drops to 93% in Environment 2, suggesting reduced robustness under higher threat density. HHO and AVOA exhibit lower success rates, often generating paths that violate no-fly zones or contain excessive sharp turns.
Regarding path smoothness, CTWRBMO produces the smallest average turning angles, indicating that its trajectories are smoother compared to those generated by the other algorithms.
Energy consumption and average computational time were also evaluated. CTWRBMO consistently achieves the lowest energy consumption due to its shorter and smoother paths, which minimize frequent sharp-turn operations. In contrast, the other algorithms consume more energy because their paths are longer and less smooth, requiring more maneuvers. The average computational time of CTWRBMO is comparable to RBMO and slightly higher than ABC or AVOA, demonstrating that the improved solution quality does not incur a prohibitive computational cost.
It is noteworthy that CTWRBMO exhibits the smallest variation in path cost across independent runs, indicating minimal performance fluctuation and high stability. Overall, these results demonstrate that CTWRBMO can reliably generate high-quality, feasible, smooth, and energy-efficient paths while maintaining acceptable computational times, making it particularly suitable for complex 3D UAV path planning scenarios.
From the convergence curves of the different algorithms in Environment 1 (
Figure 10a), it can be observed that during the first 25 iterations, CTWRBMO ranks third in convergence speed, slightly behind AVOA and ABC. However, as the iterations progress, by the 60th iteration, the convergence accuracy of CTWRBMO surpasses that of both AVOA and ABC, achieving the best overall performance among all algorithms. This indicates that, although CTWRBMO explores the solution space slightly more slowly in the early stage, its optimization strategies enable efficient solution refinement in subsequent iterations, ultimately achieving higher convergence accuracy.
Similarly, in Environment 2 (
Figure 10b), CTWRBMO exhibits relatively slower convergence in the early iterations. Nevertheless, around the 45th iteration, its convergence accuracy exceeds that of ABC, rising to the top rank. These results demonstrate that CTWRBMO can effectively generate high-quality solutions in the later stages of iteration, highlighting its robustness and excellent global search capability across different 3D UAV path planning scenarios.