# Fuzzy Logic and Bio-Inspired Firefly Algorithm Based Routing Scheme in Intrabody Nanonetworks
## 3 Fuzzy Logic and Bio-Inspired Firefly Algorithm Based Routing Scheme
### Bio-Inspired Firefly Algorithm Based NBSs Selection  
The firefly algorithm is inspired by the flashing pattern and behavior of fireflies. The low-complexity and self-adaptability of this metaheuristic approach make it the most suitable approach for adaptation in IBNNs for designing low-complexity routing schemes. Fireflies use their flashlight for attracting other fireflies for communication and mating; the flashing pattern, rhythm and the rate influence the attractiveness of a firefly. The firefly algorithm is based on the three main assumptions; first, all the fireflies are unisex. Second, the attractiveness of a firefly is proportional to its intensity, as the distance increases both the attractiveness and intensity decreases. If no brighter firefly is found then the particular firefly moves randomly. Third, the objective function determines and influences the intensity of the firefly. The attractiveness of firefly is determined using Equation (5):  
\[\zeta(d)=\zeta_{o}e^{-\beta d^{2}} \tag{5}\]  
where \(\zeta(d)\) expresses the attractiveness of a firefly at a distance \(d\). The attractiveness of a firefly at a distance \(d=0\) is represented as \(\zeta_{o}\). \(\beta\) and \(d\) denotes light absorption coefficient and distance between two fireflies respectively. The distance between two fireflies \(\widehat{FF}_{i}\) and \(\widehat{FF}_{j}\) is calculated using Equation (6):  
\[d(\widehat{FF}_{i},\widehat{FF}_{j})=\sqrt{(\widehat{FF}_{j}(x)-\widehat{FF}_{ i}(x))^{2}+(\widehat{FF}_{j}(y)-\widehat{FF}_{i}(y))^{2}+(\widehat{FF}_{j}(z)- \widehat{FF}_{j}(z))^{2}}, \tag{6}\]  
where \(d(\widehat{FF}_{i},\widehat{FF}_{j})\) is the distance from the coordinates of firefly \(\widehat{FF}_{i}\) given by \((\widehat{FF}_{i}(x),\widehat{FF}_{i}(y),\widehat{FF}_{i}(z))\) to the coordinates of firefly \(\widehat{FF}_{j}\) denoted as \((\widehat{FF}_{j}(x),\widehat{FF}_{j}(y),\widehat{FF}_{j}(z))\). Since all the spatially correlated NBSs are assumed to detect similar types of information, therefore, limiting the participation of NBSs in the data reporting process increases the network lifetime by conserving network resources that are consumed in redundant data transmission. The proposed firefly algorithm optimizes NBSs selection for reducing redundant data transmission, balancing energy consumption and increasing the probability of retrieving more valuable information from NBSs. The proposed firefly algorithm for the optimal selection of NBSs is further provided in Algorithm 2. The detailed demonstration of the main steps of our proposed firefly algorithm is given below:  
1. Solution Initialization: In the firefly algorithm, the potential solution of a problem is represented by each firefly. Similarly, in NBSs selection, each firefly symbolizes as the solution of NBSs selection problem. The proposed algorithm first initializes the initial solution. The initial solution structure is generated randomly (i.e., 0 or 1) depending on the number of NBSs. Figure 6: Mamdani defuzzification process using the centroid (COG) method for the crisp inputs values; x = 16, y = 19 and z = 55. Fitness function calculation: In the view of the influence of the light intensity on the brightness of a firefly, in this work, the attractiveness of the firefly devise its fitness. The fitness value is based on the three main characteristics; remaining energy of the NBSs, distance from the nanorouter and the priority bit. 1. Residual Energy: Selecting NBSs with more residual energy assist in prolonging the network lifetime. Therefore, selecting NBSs with more energy available is a more preferable choice. 2. Distance: Data transmission at less distance requires low energy consumption and ultimately increased network lifetime. Therefore, NBSs that is located at the minimum distance from nanorouter has better fitness value. 3. Priority Bit: The priority bit depends on the content of the last transmitted data, if the NBS has transmitted critical messages in the last interval then priority bit is set to 1 otherwise it is 0.