## 5 The Proposed GMDPSO for Our Protocol
### GMDPSO: Greedy Discrete PSO with Memory
\begin{array}{ll}E_{cons}^{Path_{j}}&=\sum\limits_{k=1}^{N_{path_{j}}}E_{ cons}\left(RN_{j}^{k}\right)=\sum\limits_{k=1}^{N_{path_{j}}}N_{indata}\left(RN_{j}^{k} \right)\times m\times\left(\gamma_{1}+\beta_{1}+\beta_{2}\times dis\left(RN_ {j}^{k},RN_{j}^{k+1}\right)^{n}\right)\\ &=\sum\limits_{k=1}^{N_{path_{j}}}N_{in}\left(RN_{j}^{k}\right)\times m\times \left(\gamma_{1}+\beta_{1}\right)+\beta_{2}\times\sum\limits_{k=1}^{N_{path _{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)^{n}\end{array}  \tag{14}\]

Therefore, \(E_{cons}^{PTree_{i}}\) can be calculated as follow:

\[E_{cons}^{PTree_{i}}=\sum\limits_{j=1}^{N_{path_{j}}^{neigh_{i}}}E_{cons}^{Path _{j}}=\sum\limits_{j=1}^{N_{path_{j}}^{neigh_{i}}}\sum\limits_{k=1}^{N_{path _{j}}}N_{indata}\left(RN_{j}^{k}\right)\times m\times\left(\gamma_{1}+\beta_{1 }\right)+\beta_{2}\times\sum\limits_{j=1}^{N_{path_{j}}^{neigh_{i}}}\sum \limits_{k=1}^{N_{path_{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)^{n} \tag{15}\]

For each \(Path_{j}\) assume that no packet is lost during routing data to agent, then \(N_{in}(RN_{j}^{k})\) is the same for each relay node in \(Path_{j}\) which can be considered as a constant value. Let \(N_{in}(RN_{j}^{k})=N_{in}\). Then Equation (14) is improved as follows:

\[E_{cons}^{Path}\left(Path_{j}\right)=N_{Path_{j}}\times N_{in}\times m\times \left(\gamma_{1}+\beta_{1}\right)+\beta_{2}\times\sum\limits_{k=1}^{N_{path _{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)^{n} \tag{16}\]

where \(\sum\
olimits_{i=1}^{N_{path_{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)\) is length of the routing path \(Path_{j}\). It is can be seen that \(E_{cons}^{Path_{j}}\) is only positively correlated with routing path. Therefore, to minimize \(E_{cons}^{PTree_{i}}\), the total routing tree length \(Len(PTree_{i})\) needs to be minimized. That is, our second objective can be described as follows:

\[ \begin{array}{ll}\text{Objective }\mathbf{2}:\text{Minimize }Len\left(PTree_{i} \right)=\sum\limits_{j=1}^{N_{path_{j}}^{neigh_{i}}}\sum\limits_{k=1}^{N_{ path_{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)\end{array}  \tag{17}\]

Smaller \(Len\left(PTree_{i}\right)\) is better. Therefore, \(fitness\) is proportional to the \(Len\left(PTree_{i}\right)\) i.e.,

\[fitness\propto Len\ \left(PTree_{i}\right) \tag{18}\]

Now, we normalize \(Len\left(PTree_{i}\right)\) by \(allLen\), i.e.,

\[Len\left(PTree_{i}\right)=\sum\limits_{j=1}^{N_{path_{j}}^{neigh_{i}}}\sum \limits_{k=1}^{N_{path_{j}}}dis\left(RN_{j}^{k},RN_{j}^{k+1}\right)^{n}/allLen \tag{19}\]

_allLen_ can be calculated as follows:

\[ \begin{array}{ll}allLen=\sum\limits_{i=1}^{N_{V}}\sum\limits_{j=1}^{N_{V}}dis (i,j)\times a_{ij}&\quad\text{where}\\ a_{ij}=\left\{\begin{array}{ll}1&if\ node_{j}\ within\ the\ communicaiton\ rang\ of\ node_{i},\quad\forall i,j:1\leq i,j\leq N_{V}\\ 0&\quad\text{Otherwise}\end{array}\right.\end{array}  \tag{20}\]



**Illustration 1**. : _Consider mobile sink \(\mathit{Sink}_{i}\) masters a subnet of MWSN \(G\) (V, E) with 13 sensor nodes and one mobile node as shown in Figure 4a. \(V=\{\mathit{node}_{1}\), \(\mathit{node}_{2}\),..., \(\mathit{node}_{13}\}\). \(\mathit{node}_{13}\) is selected as agent, \(\mathit{node}_{11}\) and \(\mathit{node}_{12}\) are two source nodes, which means two routing paths will be built. The dimension of the particle position vector is \(N^{\prime}=N-1=13-1=12\). As shown in Figure 4b. Particle \(i\) is encoded as \(X_{i}=\{x_{i}^{1}\), \(x_{i}^{2}\), \(x_{1}^{3}\),..., \(x_{i}^{12}\)} = {6, 9, 10, 5, 9, 5, 5, 13, 13, 4, 3}, in \(X_{i}\), for example, \(x_{1}^{11}=4\) indicates that source node node\({}_{11}\) sends data packet to node\({}_{4}\).