# A Hybrid Method for Mobile Agent Moving Trajectory Scheduling using ACO and PSO in WSNs
## 5 Our Presented HM-ACOPSO Algorithm
### Anchor Nodes Selection Based on PSO  
As mentioned above, the mobile agent needs to move to the location of the CHs for data collecting. However, each sensor owns its fixed wireless communication coverage, and any two sensors which are in each other's communication range can communicate with each other freely. Therefore, the mobile agent has no occasion to reach CHs for data collecting, and the shortest path selected by ACO can be further optimized. We allocate a virtual anchor node for each cluster head and we utilize the PSO algorithm for anchor nodes selection. We still use the order that the preceding ACO achieves to traverse the anchor nodes of the CHs. Each particle represents a path across all the anchors, and we assume that the current order for traversing is \(A=\{a_{1},a_{2},a_{3}\cdot\cdots\cdot a_{n}\}\). The dimension of each particle is \(2n\) and the particle swarm can be denoted as:  
\[P=\left[\begin{array}{c}p^{1}\\ p^{2}\\ p^{3}\\ \vdots\\ p^{n}\end{array}\right]=\left[\begin{array}{c}x_{a_{1}}^{1},y_{a_{1}}^{1},x_{ a_{2}}^{1},y_{a_{2}}^{1}\cdot\cdots\cdot x_{a_{n}}^{1},y_{a_{n}}^{1}\\ x_{a_{1}}^{2},y_{a_{2}}^{2},x_{a_{2}}^{2},y_{a_{2}}^{2}\cdot\cdots\cdot x_{a_{n}} ^{2},y_{a_{n}}^{2}\\ x_{a_{1}}^{3},y_{a_{1}}^{3},x_{a_{2}}^{3},y_{a_{2}}^{3}\cdot\cdots\cdot x_{a_{n}} ^{3},y_{a_{n}}^{3}\\ x_{a_{1}}^{n},y_{a_{1}}^{n},x_{a_{2}}^{n},y_{a_{2}}^{n}\cdot\cdots\cdot x_{a_{n}} ^{n},y_{a_{n}}^{n}\end{array}\right] \tag{13}\]  
where \(x_{a_{i}}^{k},y_{a_{i}}^{k}\) denotes the location of \(k\)th anchor. The target of the PSO algorithm is to minimize the traveling path of the mobile agent and we still adopt the fitness function as the ACO used. We set an initial speed for each dimension of the particle and the restriction of speed and location of particles are as follows:  
\[limit(v_{i}^{k})=[-10,10] \tag{14}\]  
\[dis(anchor^{k},CH^{k})<R \tag{15}\]  
We use the following steps to execute our POS algorithm.  
**Step 1**: We randomly set the initial location and speed of particles. The location and speed satisfy the restriction of Formulas (14) and (15).  
**Step 2:** The fitness value of particles is calculated in accordance with Formula (9). Each particle compares the current fitness value with its previous optimal fitness value and chooses the better one as its \(P_{best}\). Similarly, we compare the current global fitness value with the previous optimal global fitness value and choose the better one as \(G_{best}\).  
**Step 3**: The speed and the location of particle \(p^{i}\) is updated using the following formulas respectively.  
\[V_{i}(t+1)=\eta V_{i}(t)+c_{1}\times rand()\times(P_{lbest}-P_{i}(t))+c_{2} \times rand()\times(G_{best}-P_{i}(t)) \tag{16}\]  
\[P_{i}(t+1)=P_{i}(t)+V_{i}(t{+}1) \tag{17}\]  
where \(\eta\) denotes the inertia factor. \(c_{1}\),\(c_{2}\) denote the weight factor and they satisfy \(c_{1}+c_{2}=1\).  
**Step 4:** After updating the speed and location, each particle checks whether the value of its speed and location exceed the boundary. If the speed exceeds the limit, it will be set as the boundary value, and if the location exceeds the limit, the location information will not be updated.  
**Step 5**: Next, it conducts step 2 and iterates until reaching the maximal iteration number.  
Finally, \(G_{best}\) represents the solution for the anchor nodes selection. The sample after the anchor nodes selection is shown as Figure 7.  
The pseudocode of the PSO-based anchor nodes selection is described in Algorithm 2.  
Figure 7: Anchor nodes selection using the PSO algorithm.