### 4.1 Traditional PSO

The first step of the traditional PSO algorithm is to initialize the particle swarm. Then, the fitness of the particles is calculated. The global optimal solution and local optimal solution are updated according to the fitness. Finally, the velocity and position of the next generation of particles are calculated by updating the velocity and position formula until the maximum number of iterations is reached. The updating formula of the velocity and position of particle *i* is

$$\begin{aligned} v_i^k= & \, \omega v_i^{k-1}+a_1 r_1(Pbest_i-y_i^{k-1})+a_2 r_2(Gbest_i-y_i^{k-1}) \end{aligned}$$

(9)

$$\begin{aligned} y_{i}^k= & \, y_{i}^{k-1}+v_{i}^k \end{aligned}$$

(10)

where \(v_i^k\) is the component of the velocity vector of particle i in iteration k. \(y_i^k\) is component of the position vector of particle i in iteration k. \(a_1\) and \(a_1\) are acceleration constants, which are responsible for adjusting the maximum speed of particle learning. \(r_1\) and \(r_2\) are random functions with values ranging from 0 to 1. *w* is the inertia weight (nonnegative), reflecting the influence of the individual particle history at present.

In Formula (10), the first part represents the previous velocity of the particle. The second part is the “cognition” part, which represents the distance between the current position of particle i and its historical optimal position, which is equivalent to the local optimal solution. The third part is the “society” part, which represents the distance between the current position of particle i and the optimal position of the population, which is equivalent to the global optimal solution. The final motion direction of particles is affected by the above three parts, as shown in Fig. 2.

Compared with the traditional algorithm, PSO has a memory function. The update process is affected by the local optimal solution and the global optimal solution instead of blind random selection, which greatly improves the search efficiency. Furthermore, fewer parameters need to be adjusted, and the structure is simple and easy to implement. However, because of these advantages, the PSO algorithm loses diversity of the search space. Furthermore, it easily produces premature convergence, has poor local searchability, and easily falls into the local optimal solution.

### 4.2 Improved PSO algorithm

In view of the above shortcomings, many domestic and foreign researchers have proposed some improvement methods. These improved methods can be divided into two categories. One category improves the inertia weight, contraction factor, velocity, and position update process of particles on their own. The other category combines the PSO algorithm with another algorithm that can compensate for its shortcomings so as to improve the performance of the algorithm. In this paper, an improved particle swarm optimization combined with a genetic algorithm (GA-PSO) is proposed. By introducing crossover and variation, the velocity and position updating formula of PSO are improved to increase the diversity of the search space and avoid falling into the local optimal solution.

#### 4.2.1 Local optimal solution

Partially matched crossover (PMX) refers to two invalid chromosomes or duplicate individual genes after randomly selecting two crossover points in individual chromosomes for partial gene exchange. In order to repair the chromosomes, the matching relationship of each chromosome is established in the cross-region, and the matching relationship is applied to the duplicate genes outside the cross-region to eliminate the conflict. Because PMX can ensure that the genes in each chromosome only appear once, we choose this crossover strategy to solve the traveling salesman problem (TSP) and VRP.

As shown in Fig. 3, PMX crossover mainly consists of the following steps:

(1) Two intersections are randomly selected, and the sequences between the two intersections are the exchanged segments.

(2) The new parent sequence is obtained by exchanging the positions of the exchanged segments.

(3) Conflict detection is performed on sequences. According to the exchange segment of the two-parent sequences, the two-child sequences with mapping relationships can be obtained. The traversal repeat points in the offspring sequence outside the exchange segment are exchanged one by one according to the mapping relationship of the exchanged segments until there is no conflict.

(4) The final offspring sequence is obtained.

In this paper, each particle represents a task planning path, so the parent sequence is the particles before the crossover operation, and the points that compose the sequence are the task points. Finally, the target function values of the new particle sequence and the parent sequence are compared. If the target function after crossover is small, the cross-particle sequence is stored in the local optimal solution, and the corresponding target function value is updated.

#### 4.2.2 Global optimal solution

The crossover process of the global optimal solution is the same as that of the local optimal solution. The final new particle sequence is compared with the target function value of the parent sequence. If the target function value after crossover is smaller, the crossed particle sequence is stored in the global optimal solution, and the corresponding target function value is updated. The global optimal solution is updated according to the minimum value of the local optimal solution.

#### 4.2.3 The particle itself

According to Formula (9), each particle will generate a pair of random numbers in the process of an iteration. Transposition mutation is equivalent to exchanging the order of task points in a path corresponding to two random numbers. This occurs as shown in Fig. 4.

Finally, the target function values of the new particle sequence and the parent sequence are compared. If the mutated target function value is smaller, the mutated particle sequence is stored in the local optimal solution, and the corresponding target function value is updated.

### 4.3 Algorithm implementation for the task allocation problem

UAVs need to meet some constraints in task allocation. In the intelligent marine system studied in this paper, the constraints can be divided into the task point constraints, the task order constraints, and the constraints of the UAV itself. The details are as follows:

$$\begin{aligned}&\sum _{i=1}^n\sum _{k=1}^m x_{ki,j}=1 \end{aligned}$$

(11)

$$\begin{aligned}&\sum _{j=1}^n\sum _{k=1}^m x_{ki,j}=1 \end{aligned}$$

(12)

Formulas (11) and (12) indicate that each task point can only be accessed by one UAV once. \(x_{ki,j}\) is the decision variable. When UAV \(u_k\) arrives at task point \(c_i\) from task point \(c_i\), the value is 1. Otherwise, the value is 0.

$$\begin{aligned}&\sum _{j=0}^n x_{k0,j}=\sum _{i=0}^n x_{ki,0} \end{aligned}$$

(13)

$$\begin{aligned}&\sum _{j=1}^n x_{kl,j}-\sum _{i=1}^n x_{ki,l}=0 \end{aligned}$$

(14)

Formula (13) indicates that the UAV starts from the warehouse and finally needs to return to the warehouse. Formula (14) represents the node balance constraint, and the total number of UAVs starting from the task point must be consistent with the total number of UAVs arriving at the task point.

$$\begin{aligned}&\sum _{i=0}^n\sum _{j=1}^n x_{ki,j}q_i\le q_k \end{aligned}$$

(15)

$$\begin{aligned}&\sum _{i=0}^n\sum _{j=1}^n x_{ki,j}d_{i,j}\le _{kmax} \end{aligned}$$

(16)

Formulas (15) and (16) represent the material loading constraint and travel constraint of each UAV, respectively. The material requirement \(q_i\) of task point \(_i\) must be less than the maximum material loading \(q-i\) of UAV \(u_k\). The flight distance from task point \(c_i\) to task point \(c_j\) must be less than the maximum travel \(l_k\) of UAV \(u_k\).

$$\begin{aligned} t_k+x_{i-1,i}t_{u(i-1),i}\le t_{\omega (i-1),i} \end{aligned}$$

(17)

Formula (17) indicates that the time for the UAV to go to the task point must be within the task time window. The time window \(t_{\omega i,j}\) is an interval, and only when the task is completed in this interval can it be regarded as an effective task.

$$\begin{aligned} q_k,l_{kmax},t_{\omega i,j}>0 \end{aligned}$$

(18)

Formula (18) indicates that the material loading capacity \(q_k\) , maximum range \(l_k\) and time window \(t_{\omega i,j}\) from task point \(c_i\) to task point \(c_j\) of UAV \(u_k\) are all positive numbers.

Algorithm 1 describes the constraint process in the UAV task allocation problem. The input part sets the maximum material loading capacity, flight speed, and maximum range of UAVs. The number, location, material demand, and time window of task points are set randomly. Then, initialization and memory preallocation are conducted. Then, when proceeding to the next task point from the current position, it is necessary to judge whether the constraint conditions are satisfied in turn according to the above formulas (11–18). If all of the constraint conditions are met, the implementation will continue. If the constraints are not met, the UAV returns to the warehouse and a new UAV is arranged to perform the task. After all task points are completed, all UAVs return to the warehouse.

Algorithm 2 describes the UAV task allocation problem based on improved GA-PSO. First, the UAV, task point, warehouse, and particle are input and set initially, and the memory is preallocated. Then, the optimal solution of the target function of each generation of particles is compared. The PMX operation is performed on the local optimal solution and the global optimal solution, and the secondary transposition mutation is performed on the particle itself, which is compared and updated with the current position. This continues until the maximum number of iterations is reached.

### 4.4 Algorithm implementation for the route planning problem

There are many self-constraints in the actual route planning of UAVs, such as the maximum travel distance, the minimum inertial distance, and the maximum horizontal deflection angle.

#### 4.4.1 Maximum travel distance

Suppose the maximum travel distance of UAV \(u_k\) is \(l_{kmax}\). If the entire travel route is composed of n flight points, the entire travel route can be divided into \(n-1\) segments, the flight of segment i can be expressed as \(l_{ki}\), and the total travel route \(L_k\) can meet the following requirements:

$$\begin{aligned} L_k\le l_{kmax}, L_k=\sum _{i=1}^{n-1}l_{ki} \end{aligned}$$

(19)

#### 4.4.2 Minimum inertial distance

The minimum inertial distance refers to the shortest flight distance that a UAV needs to maintain the original direction due to the inertial effect when it suddenly changes direction. If the minimum inertial distance of UAV \(u_k\) is \(l_{kmin}\), the minimum inertial distance constraint is:

$$\begin{aligned} L_k\ge l_{kmin} \end{aligned}$$

(20)

#### 4.4.3 Maximum horizontal deflection angle

The maximum horizontal deflection constraint means that the UAV cannot complete large-angle turning in the horizontal direction, and can only turn in a certain angle range. If the horizontal projection of segment i of UAV \(u_k\) is \(e_{ki}=(x_i-x_{i-1}, y_i-y_{i-1})\), and the maximum horizontal deflection angle is \(\theta _{kmax}\), then the maximum horizontal deflection angle constraint is:

$$\begin{aligned} \frac{e_{ki}^T e_{k(i+1)}}{\parallel e_{ki}\parallel \cdot \parallel e_{ki+1}\parallel }\ge cos \theta _{kmax} \end{aligned}$$

(21)

Algorithm 3 describes the constraint process in a UAV two-dimensional route planning problem. First, the maximum range, minimum inertial distance, and maximum horizontal deflection angle of the UAV are input and set. The positions of the threat area, starting point, and target point are set randomly. The memory is preallocated, a route is randomly generated, and the number of flights of the route is counted. Then, it is necessary to judge whether each flight meets Formulas (20–21). If this occurs, it is necessary to calculate the total travel distance and judge whether Formula (19) is satisfied. If this is not satisfied for any UAV, it will jump out. If both conditions are met, the travel is recorded, and the constraint parameters and threat factors are returned.

Algorithm 4 describes the process of two-dimensional route planning of UAVs based on improved GA-PSO. First, the initial settings of the UAV, threat area, target point, starting point, link, communication environment, and particle are input and initially set. Memory is preallocated. It is necessary to calculate the speed and direction of UAVs and calculate the signal-to-noise ratio of UAVs in the marine communication environment. Then, we need to compare the optimal solution of the fitness function for each generation of particles. The PMX operation is performed on the local optimal solution and the global optimal solution. The second transposition mutation of the particle itself is conducted and compared with the current position to determine updates. This process repeats until the maximum number of iterations is reached.