## 3 Multi-MAF: A Hybrid Adaptive Algorithm for Routing in WSNs
### Reactive Component: SID
Figure 3: SID algorithm. \(Sd\) is the data size in bytes, \(Nh\) is the approximated number of hops from source to sink, and \(Nn\) is the approximated number of neighbors of a node. The significant cost differences of the algorithms are due to the routing infrastructure formation. For the EF-Tree this energy cost is given by periodic broadcasts of tree construction messages, which is estimated by:  
\[Ctree=(Pt\cdot Sc\cdot N+Pr\cdot Sc\cdot Nn\cdot N)\cdot\lceil(T/Ttree)\rceil \tag{2}\]  
where \(Sc\) is the control packet size (in bytes), \(N\) is the number of nodes in the network, \(T\) is the execution time and \(Ttree\) is the tree reconstruction period (both in seconds). The relation \(\lceil(T/Ttree)\rceil\) represents the number of tree buildings in the execution time. SID does initial broadcasts for each source and the sink sends requisitions messages towards source nodes for path definition. In this case, we have:  
\[Csid = Ns\cdot(Pt\cdot Sd\cdot N+Pr\cdot Sd\cdot Nn\cdot N+ \tag{3}\] \[+\left(Pt\cdot Sc\cdot Nh+Pr\cdot Sc\cdot Nn\cdot Nh\right) \cdot\lceil(Tev/Tsid)\rceil)\]  
where \(Ns\) is the number of source nodes sending data, \(Tev\) and \(Tsid\) are, respectively, the average traffic duration for every source and the sink's requisition messages interval (in seconds). The relation \(\lceil(T/Tsid)\rceil\) gives the number of requisitions in the execution time. **Proposition 1**: _The cost of SID can exceed the cost of EF-Tree regarding the number of sources (Ns) in a time interval \(T\)._  
**Proof. ** We can see that EF-Tree has a constant energy cost in function of the network lifetime (\(T\)). On the other hand, SID has an energy cost proportional to the number of sources (\(Ns\)). A crossing-point in the energy costs of the algorithms is expected to occur as the number of source nodes increases in a given execution time. This can be seen by making \(Ctree\) = \(Csid\). For a simpler analysis, we can eliminate the second term of \(Csid\) by assuming that \(Nh\) (number of hops from source to sink) is much smaller than \(N\) (number of nodes), and \(Tev\) (event duration) tends to be much smaller than \(T\) (network lifetime). Also, we can consider a little difference between \(Sd\) and \(Sc\), because \(Sd\) represents broadcasts for path discovery in \(Csid\) and, in practice, either this broadcast could be replaced by control packets (best case) or data packet are not much larger than control packets (\(Sc\) in \(Ctree\)), due to platform limitations (as it happens in Mica and is also considered in our simulation scenarios). Thus, the crossing point happens when the number of sources exceeds the number of tree-building in a given execution time. \(\Box\)  
Therefore, it is not appropriate to use the EF-Tree algorithm during inactive periods of traffic that are expected in event-driven applications, and the SID algorithm should be used when the event detection rate, which impacts in the number of sources, is low. These facts are explored on the proposed hybrid adaptive approach to achieve the best performance from both solutions.