## 5 The Proposed GMDPSO for Our Protocol
### GMDPSO: Greedy Discrete PSO with Memory
\(RN_{j}^{k}\) must consume energy to forward the incoming data packets, which come from source node whose routing path to sink goes through it. Before calculating the routing energy consumption, it is needed to calculate the total number of incoming packets, which come from other relay node toward sink. Since multi routing paths may share some relay nodes, the number of incoming packets can be recursively calculated as follows:

\[N_{in}\left(RN_{j}^{k}\right)=\left\{ \begin{array}{ll}0&if\ Next\ Relay\left(RN _{l}^{x}\right)\
eq RN_{j}^{k},\ \forall l\quad 1\leqslant l\leqslant N_{path}^{sink_{i}}, \forall RN_{l}^{x}\in Path_{l}\\ \sum\left\{N_{in}\left(RN_{l}^{x}\right)\middle|Next\ Relay(RN_{l}^{x})=RN_{j }^{k}\right\},\ otherwise\end{array} \right. \tag{8}\]

The relay node \(RN_{j}^{k}\) will consume its energy to receive \(N_{in}(RN_{j}^{k})\) incoming packets and forward them. Therefore, the total data forwarding energy consumption of \(RN_{j}^{k}\) can be calculated as follows:

\[ \begin{array}{ll}E_{cons}(RN_{j}^{k})&=N_{in}\left(RN_{j}^{k}\right)\times E _{R}+N_{in}\left(RN_{j}^{k}\right)\times E_{T}\left(RN_{j}^{k},RN_{j}^{k+1} \right)\\ &=N_{in}\left(RN_{j}^{k}\right)\times\left(E_{R}+E_{T}\left(RN_{j}^{k},RN_{j}^ {k+1}\right)\right)\\ &=N_{in}\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)\end{array}  \tag{9}\]

where \(m\) is the size of data packet. Let \(minL_{fPTree_{i}}\) be the minimum lifetime of the routing tree \(PTree_{i}\). Therefore, our first objective is:

\[\text{Objective }\mathbf{1}:\text{Maximize }minL_{fPTree_{i}}=\min\left\{lf \left(RN_{j}^{k}\right)\middle|RN_{j}^{k}\in PTree_{i}\right\} \tag{10}\]

Using Equation (9) to substitute the \(E_{cons}(RN_{j}^{k})\) in Equation (7), then,

\[\small{lf\left(RN_{j}^{k}\right)=E_{res}\left(RN_{j}^{k}\right)/E_{cons}\left( RN_{j}^{k}\right)=E_{res}\left(RN_{j}^{k}\right)/N_{in}\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)} \tag{11}\]

It can be seen that, if \(E_{res}(RN_{j}^{k})\) and \(N_{in}(RN_{j}^{k})\) are fixed, then \(\small{lf(RN_{j}^{k})}\) is negatively correlated with \(\text{dis}(RN_{j}^{k},RN_{j}^{k+1})\). Therefore, it can be deduced that relay node with minimum lifetime is the relay node with the longest transition distance. That is,

\[\small{minL_{fPTree_{i}}=RN_{j}^{k}=\arg\max}dis\left(RN_{j}^{k},RN_{j}^{k+1} \right)\ \left|\forall j,1\leqslant j\leqslant N_{path}^{sink_{i}}\text{ and }\forall k,1 \leqslant k\leqslant N_{Path_{j}} \tag{12}\]

where \(\arg\max\{x}(x)\) returns the value of \(x\) that maximizes \(f(x)\). Bigger \(minL_{fPTree_{i}}\) means smaller fitness value. Therefore, \(\small{fitness}\) is inversely proportional to the \(minL_{fPTree_{i}}\), i.e.,

\[\small{fitness}\propto 1/minL_{fPTree_{i}} \tag{13}\]

where \(0<1/minL_{fPTree_{i}}\leqslant 1\). \(minL_{fPTree_{i}}\) is used to avoid node with lower residual energy being selected as sharing relay node whose load burden is heavy. (2) Routing Path Length

In our network mode, the energy is mainly consumed to collect network statuses and forward data to sink. The unicast local flooding mechanism is adopted to save energy for collecting network statuses. It is well known that the energy consumption of sensor node in WSNs is subject to the transmission distance--shorter data dissemination paths lead to decreased energy consumption together with increased throughput and reliability, which also can be deduced from Equation (9). Therefore, our second objective is to minimize the length of the routing tree to minimize the forwarding data energy consumption. Let \(Path_{j}\) be routing tree of \(Agent_{i}\). Now, we calculate the total energy consumption of \(PTree_{i}\) (i.e., \(E_{cons}^{PTree_{i}}\)). According to Equation (9), the energy consumption of each routing path \(Path_{j}\) (\(Path_{j}\subseteq PTree_{i}\)), i.e., \(E_{cons}^{Path_{j}}\), can be calculated as follows:

\[