# 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
Based on the fitness parameters, the overall fitness value of a NBS is determined using Equation (7): \[NBS_{i}(Fitness)=\alpha_{1}\times E_{i}+\alpha_{2}\times\frac{1}{d(i,r)}+\alpha_ {3}(Prioritybit),\] (7) where weights \(\alpha\) are used to balance the weight of three parameters expressed as \(\alpha_{i}\in(0,1)\) and \(\alpha_{1}+\alpha_{2}+\alpha_{3}=1\). 3. New Solution Updating: After determining the light intensity of each solution, the firefly with less brightens moves to the next firefly with more brightness. The position of the next firefly is updated using the Equation (8): \[\widehat{F}\widehat{F}_{i}(pos+1)=\widehat{F}\widehat{F}_{i}(pos)+\zeta_{o}^{ -\beta d^{2}_{FFi,Ff}}(\widehat{F}\widehat{F}_{j}(x),\widehat{F}\widehat{F}_{ i}(x))+\alpha(random-1/2),\] (8) where \(\widehat{F}\widehat{F}_{i}\) and \(\widehat{F}\widehat{F}_{j}\) are two fireflies, \(\alpha\) denoted the randomization parameter and \(random\) function is used to generate random value between [0,1]. ```
**Algorithm 2**Firefly algorithm based NBSs selection
```
1:Initialize population \(nbs=(nbs_{1},nbs_{2},\ldots nbs_{i})T\)
2:Perform the generation of initial firefly population, (1,2,...i)
3:Calculate the light intensity \(I\) at \(nbs_{i}\) using Equation (7) and obtain the \(I_{best}\). 4:While t\(<\)MAXGeneration
5:For every i
6:For every j
7:update fitness function and find light intensity. 8:For\(n_{f}=1:N_{files}\)
9:If\(max(I_{nf}>I^{best})\) then
10:Replace with updated firefly. 11:Else Randomly change function and generate new intensity. 12:EndIf
13:EndFor
14:Determine the new solution using Equation (8) and update the light intensity. 15:EndFor
16:EndFor
17:Make a ranking of the fireflies to locate the present best. 18:EndWhile

### Data Transmission

Once the selected NBSs receive announcement message \(P_{AM}\), NPSs transmit the response messages according to the assigned transmission status. The status is allocated to the NSBs according to the following Equation (9):

\[NBS_{i}(status)=\frac{EV_{CR(r)}+FV_{NBS(i)}}{TotalNo.ofselectedNBSs}, \tag{9}\]

where \(EV_{CR(r)}\) is the enrichment value of the correlated region indexed \(r\) and \(FV_{NBS(i)}\) is the fitness value of the NBS indexed \(i\). ### The Lifetime of an IBNN

Network lifetime is the fundamental characteristic of an IBNN for evaluating its potential in specific applications. In the existing literature, various factors are considered, such as the alive number of nodes, sensor coverage and connectivity for defining the lifetime of a WSN [59]. Similarly, the lifetime of IBNN is also associated with the number of alive NBSs, defined as the time when NBSs exhaust themselves and have no energy left for carrying out primary operations. The definition provides information that when NBSs do not have enough energy to transmit data packets, the network can no longer provide useful information to the external healthcare system. Therefore, the IBNN should be considered dead. The evaluation of IBNN lifetime based on the alive number of NBSs is briefly discussed in this section. The detailed comprehension of IBNN lifetime is possible by briefly explaining the life cycle of an NBS. The life span of an NBS depends on the number of messages transmitted and received by the nano-transceivers. Nano-transceivers use TS-OOK modulation scheme for communication in the THz band as THz band transceivers are not able to handle the shape or phase complexity of the transmitted signal [60]. At the physical layer, TS-OOK modulation scheme is used with pulse duration, pulse time interval and transmission range equal to 100 fs, 100 ps and 10 mm, respectively. According to TS-OOK modulation scheme the energy consumed by a NBS for transmitting a pulse is 1 pJ (i.e., \(E_{tx}\) = 1 pJ) and the amount of energy needs for a pulse reception is 0.1 pJ (i.e., \(E_{rx}\) = 1 pJ).