# Inspired from Ants Colony: Smart Routing Algorithm of Wireless Sensor Network
## 3 Proposed Algorithm
```
1 initialization: initialize \(\tau_{i,j}\) and \(\eta_{i,j}\);
2\(n=\) number of node, \(m=\) number of iteration;
3\(ls\): list of all nodes;
4 while\(t\leq m\)do
5 calculate \(p_{i,j}\) for each candidate of neighbour nodes, belongs to \(ls\) ;
6 while\(i\leq n\)do
7 for each candidate create a vector containing p times the candidate;
8 create a vector contains all these vectors;
9 mix the elements of this vector;
10 arbitrarily choose an element of this vector;
11 the next node is the one selected from this vector;
12 remove \(i\) in the ls list (\(ls=ls-i\));
13 send data and new ls list to the next node;
14\(i\gets i+1\);
15
16 end while
17 the node sends to the sink;
18 update \(\tau_{i,j}\) and \(p_{i,j}\);
19\(t\gets t+1\). 20 end while
```  
**Algorithm 1**Smart Routing Algorithm (SRA)  
The energy expended by the radio sender is offered in Equation (5) and by the receiver in Equation (6). Equation (7) is the power needed to aggregate data:  
\[E_{t(x)}(k,\delta)=\left\{ \begin{array}{ll}k.E_{dec}+k.E_{fs}\delta^{2}& \text{ if }\delta<\delta_{0},\\ k.E_{dec}+k.E_{mp}\delta^{4}&\text{ if }\delta\geq\delta_{0},\end{array} \right. \tag{5}\]  
\[E_{Rx}=k.E_{elec}, \tag{6}\]  
\[E_{agr}=k.E_{DA}, \tag{7}\]  
where:  
* \(\delta\) is the distance among the sender and the addressee,
* \(E_{fs}\) and \(E_{mp}\) are the amplifier energy, for the first, in the free space model, and, for the second, in the multipath model. If \(\delta\) is below a threshold \(\delta_{0}\), then the parameters \(\delta^{2}\) and \(E_{fs}\) are used; otherwise, the elements \(\delta^{4}\) and \(E_{mp}\) are employed. The value of the threshold \(\delta_{0}\) is shown in [17], and presented in Equation (8):  
\[\delta_{0}=\sqrt{\frac{E_{fs}}{E_{mp}}}. \tag{8}\]  
In this paper, the first sensor that will send its data takes the value 1, the second takes the value 2, and so on until reaching the base station. These numbers given by the path will be followed along each iteration, using SRA: 1 is the first node that will transmit its data, the number 2 will receive the data of 1, aggregate with its own data and will then send all to node 3. The sensors will receive the data of their predecessors, aggregate with their own data and then send the whole to their successors. This is will repeat until the base station. The routing follows a path that will be chosen using SRA as dynamically. Using Equations (5)-(8), it is possible to adjust for each sensor, 1 to 25, its consumed energy during iterations in Equation (9). \[E_{iter}(i)=\left\{ \begin{array}{ll}k.(i-1).(E_{dec}+E_{DA})+k.i.(E_{elec}+E_{fs}. \delta^{2})&\text{if }\delta<\delta_{0},\\ k.(i-1).(E_{elec}+E_{DA})+k.i.(E_{elec}+E_{mp}.\delta^{4})&\text{if }\delta\geq\delta_{0}, \end{array} \right. \tag{9}\]  
where:  
\(\bullet\)\(i\) is the sensor number. The average energy consumed in a network at each iteration, Equation (10), is the sum of energy consumed by each sensor up to this iteration divided by the number of sensors participating in this network:  
\[E_{avg_{iter}}=1/n\cdot\sum_{i=1}^{n}E_{iter}(i), \tag{10}\]  
where:  
\(\bullet\)\(n\) is the number of participating sensors in this network. The total consumed energy by a sensor, Equation (11), is the energy consumed until the last iteration:  
\[E_{total_{iter}}(i)=\sum_{iter=1}^{it}E_{iter}(i). \tag{11}\]  
The average consumed energy of network, Equation (12), is the total energy consumed by all sensors divided by sensor number:  
\[E_{avg}=1/n\cdot\sum_{i=1}^{n}E_{total_{iter}}(i). \tag{12}\]