3.3.4. The Proposed Optimization Algorithm

In this study, a hybrid HHO–GWO algorithm is proposed by combining the HHO algorithm with its random search capability and high convergence speed and the GWO algorithm, which has a high performance in avoiding local optima, so that the quadcopter can both avoid obstacles and track the planned path with minimum error. This algorithm ensures the robustness of the controller, even with sudden mass changes in the quadcopter during payload hold and release. The pseudo-code of the proposed algorithm for this study is presented in Algorithm 4.

```
Algorithm 4: Pseudo-code of hybrid HHO–GWO algorithm
  Input: The population size N and maximum number of iterations T
  Output: The location of rabbit and its fitness value
  Initialize the random population Xi(i = 1, 2, ..., N)
  while (stopping condition is not met) do
      Calculate the fitness values of hawks. Set Xrabbit as the location of rabbit (best
       position).
      for (each hawk (Xi)) do
         Update the initial energy E0 and jump strength J
          E0 = 2rand() − 1, J = 2(1 − rand())
         Update the E using Equation (41)
         if |E | ≥ 1 then
             Update the location vector using Equation (39)—(Exploration phase)
         end
         if | E| < 1 then
             if r > 0.5 and |E| > 0.5 then
                Update the position vector using Equation (42)—Soft besiege
             end
             if r ≥ 0.5 and |E| < 0.5 then
                Update the position vector using Equation (44)—Hard besiege
             end
             if r < 0.5 and |E| ≥ 0.5 then
                Update the position vector using Equation (45)—Soft besiege with
                 progressive rapid dives
             end
             if r < 0.5 and |E| < 0.5 then
                Update the position vector using Equation (50)—Hard besiege with
                 progressive rapid dives
             end
         end
      end
  end
  return Xrabbit
  Initialize the starting position of search agents as final position vector of Harris
   Hawk Optimization
  Initialize a, A and C
  Calculate the fitness of each search agent
   Xα = the best search agent
   Xβ = the second best search agent
   Xδ = the third best search agent
  while (t<Max number of iterations) do
      for each search agent do
         Update the position of the current search agent by Equation (37)
         Update a, A and C
         Calculate the fitness of all search agents
         Update Xα, Xβ and Xδ
      end
      t = t + 1
  end
  return Xα
```