## 4 The Proposed Routing Protocol
### Routing Procedure in the Proposed Protocol  
Rounds of data generation are determined by the Poisson distribution. The status of the sensor nodes are checked at the beginning of each round. When a sensor node has a sensed data or a buffered data packet, which it has received from one of its neighbors, it checks the position of the base station; if the base station is located in the node range, it directly sends the packet to the base station; otherwise it  
Figure 7: Schematic of the fuzzy rules, (**a**) rules based on _receiving probability_ and _distance_; and (**b**) rules based on _receiving probability_ and _number of neighbors_. chooses one of its own neighbors as the _selected node_ to forward the packet on its path to the base station. The sender node first updates its neighbors' information by broadcasting the ND message and receiving the NA messages from its neighbors. Moreover, every neighbor node sends its _node ID_, number of neighbors, and three-dimensional position to the sender node by the NA message. Then, the sender node feeds the gathered information of the neighbors into the inputs of the proposed fuzzy system to determine the receiving probability at each neighbor node. The fuzzy sets of the input variables are determined by the related membership functions, before the fuzzy output set is extracted from the fuzzy system using fuzzy decision making. This decision making uses the fuzzy input variables, fuzzy rules, and the interference engine. Finally, the receiving probability at each neighbor is inferred by the proposed fuzzy system and is converted to a crisp value by the center-of-gravity method. The neighbor node with the maximum receiving probability is chosen as the selected node to forward the packet toward the base station. The selected node becomes one of the intermediate nodes in the transmission path. When a selected node gets a data packet, it becomes the sender node of the next step in the transmission path. A schematic of SFRRP functionality to choice the appropriate selected node in a step of transmission procedure is shown in Figure 8. The distance between each neighbor node and the nearest point should be calculated before entering in the fuzzy system. For this purpose, first the straight-line distance between sender node and the base station is calculated by Equation (3) as follows:  
\[ \begin{cases}Y_{x}=BS_{x}-Node_{x}\\ Y_{y}=BS_{y}-Node_{y}\\ V_{z}=BS_{z}-Node_{z}\\ magV=\sqrt[2]{{}^{x}_{x}+V_{y}^{2}}+V_{z}^{2}\end{cases}  \tag{3}\]  
Then three-dimensional coordinates of the nearest point is calculated by Equation (4) based on the position of the sender node, radio range and distance between sender node and base station as:  
\[ \begin{cases}P_{x}=Node_{x}+[(V_{x}/magV)*R]\\ P_{y}=Node_{y}+[(V_{y}/magV)*R]\\ P_{z}=Node_{z}+[(V_{z}/magV)*R]\end{cases}  \tag{4}\]  
Finally, the distance between each neighbor node and the nearest point is determined by using the three-dimensional coordinates of each neighbor and the nearest point as follows:  
\[D\textit{(t)}=\sqrt{\left(\text{P}_{x}-\text{Neighbor}_{x}\right)^{2}+\left( \text{P}_{y}-\text{Neighbor}_{y}\right)^{2}+\left(\text{P}_{z}-\text{Neighbor }_{z}\right)^{2}} \tag{5}\]  
Note that (_BSx, BSy, BSz_) specifies the position of the base station, (_Node, Node, Nodez_) describes the position of the sender node, _magV_ represents the straight-line distance between the sender node and the base station, \(R\) is the radio range of the sender node, (_Px, Py, Pz_) specifies the position of the nearest point, and (_Neighbor, Neighbor, Neighbor,_) determines the position of each neighbor node. The primary design criterion of the routing protocols for WSN is usually the lifetime of the sensor nodes, which prolongs the lifetime of network. Total energy consumption of nodes, network traffic and delay time of the transmitted packet are some of the other important criterions for the performance evaluation of the routing protocols for WSN.