## 6 The Optimal Energy Consumption Artificial Bee Colony-Based WBAN (OEABC)
### The Generation Formula of the New Path  
**Definition 7**. : _In two paths, if there are sections which have the same starting and ending points, it is said that same segments are Same Area (SA) for the two paths._  
**Conclusion. **\(r_{i}=<v_{0}\ldots v_{r}\ldots v_{s}\ldots v_{n}>r_{j}=<v_{0}\ldots v_{p}\ldots v _{q}\ldots v_{n}>\)_, \(r_{i}\) and \(r_{j}\) have multiple SA, randomly select an SA, denoted as \(SA_{a}\). \(SA_{a}\) in \(r_{i}\) is <r... \(\approx\)>, denoted as \(SA_{a;i}\) in \(r_{j}\) is <p... \(q\)>, denoted as \(SA_{aj}\). If \(SA_{ai}\) in path \(r_{i}\) is replaced by \(SA_{aj}\), so the new path is \(<v_{0}\ldots v_{r-1},v_{p}\ldots v_{q},v_{s+1}\ldots v_{n}>\) and is still connected._  
**Proof. **\(r_{i}\) is a connected path, and its sub-paths \(<v_{0}\ldots v_{r-1}>\) and \(<v_{s+1}\ldots v_{n}>\) are also connected in accordance with the characteristics of the connected path. Using the \(SA_{aj}\) of the \(r_{j}\) path to replace the \(SA_{ai}\) of the \(r_{i}\) path, the \(r_{i}\) becomes \(<v_{0}\ldots v_{r-1},v_{p}\ldots v_{q},v_{s+1}\ldots v_{n}>\), denoted as \({r_{i}}^{*}\). \(p=r\), then \(<v_{0}\ldots v_{r-1},v_{p}>\) is connected. \(q=s\), then \(<v_{q},v_{s+1}\ldots v_{n}>\) is connected. Since \(r_{j}\) is connected, so the \(SA<v_{p}\ldots v_{q}>\) of its must be connected. In summary, the sub-paths \(<v_{0}\ldots v_{r-1},v_{p}>\), \(<v_{p}\ldots v_{q}>\), \(<v_{q},v_{s+1}\ldots v_{n}>\) are connected, so their order combination \({r_{i}}^{*}=<v_{0}\ldots v_{r-1},v_{p}\ldots v_{q},v_{s+1}\ldots v_{n}>\) must be connected. When path \(i\) and \(j\) exist \(k\)\(SA\), then \(SA_{i}\) in the path \(i\) and \(j\) are denoted as \(SA_{ti}\) and \(SA_{ij}\) respectively, so path \(i=<v_{0}\ldots v_{r-1}>SA_{ii}<v_{s+1}\ldots v_{n}>\). The function \(GetSA(i,j,t)\) returns \(SA_{ij}\), then the equation for generating the new path \({r_{i}}^{*}\) is:  
\[{r_{i}}^{*}=\left\{ \begin{array}{l}<v_{0}\ldots v_{r-1}>GetSA(i,j,t)<v_{s+1 }\ldots v_{n}>\\ r_{i}(when\;r_{i}\;and\;r_{j}\;have\;no\;SA)\end{array} \right. \tag{11}\]  
Equation (11) is the search equation for the OEABC algorithm, \(i,j\in\{1,2,\ldots,SN\}\), \(t\in\{0,1,\ldots,m-1\}\), \(m\) is the number of \(SA\) of path \(i\) and path \(j\). For example, the WBANs with 31 nodes, \(v_{0}\) is the starting node, \(v_{30}\) is the sink, there are already two paths \(r_{1}\), \(r_{0}=<v_{0}\), \(v_{1}\), \(v_{6}\), \(v_{12}\), \(v_{14}\), \(v_{17}\), \(v_{24}\), \(v_{27}\), \(v_{30}\)>, \(r_{1}=<v_{0}\), \(v_{4}\), \(v_{6}\), \(v_{11}\), \(v_{13}\), \(v_{16}\), \(v_{17}\), \(v_{23}\), \(v_{29}\), \(v_{30}\)>, as shown in Figure 3. According to Definition 7, there are 5 \(SA\)s for \(r_{0}\) and \(r_{1}\), in \(r_{0}\) <\(v_{0}\), \(v_{1}\), \(v_{6}\), \(v_{12}\), \(v_{14}\), \(v_{17}\)>>, \(<v_{  
```
0: Network topology, starting point, end point
0: Optimal energy consumption path
1. Generate the data structure of the WBANs' topology;
2. Initialize the population of bees according to Equation (10), generate the initial path of SN;
3. For (num = 0\(\rightarrow\)maxCycle){
4. The employed bee search better path[i] in the neighborhood according to Equation (11);
5. Calculate the fitness[i] of path[i] according to Equation (9);
6. Using prob[i] = (0.9*(fitness[i]/maxfit)) + 0.1, calculate the selection probability of path[i];
7. For (\(t\) = 0\(\rightarrow\)SN){
8. randvalue = ((double)rand()/((double)(RAND_MAX) + (double)(1)));
9. If randvalue < prob[i] Then
10. t++;
11. r = ((double)rand()/((double)(RAND_MAX) + (double)(1)));
12. neighbor = (int)(r*FoodNumber);
13. While (neighbour==i)[
14. r = ((double)rand()/((double)(RAND_MAX)+(double)(1)));
15. neighbor = (int)(r*FoodNumber);
16. The onlooker produce new path between path[i] and path[neighbour] according to Equation (11);
17. Calculate the fitness of the path[new] according to Equation (9);
18. If fitness[new] > fitness[i] Then
19. path[i] = path[new];
20. End If
21. End If
22. } 23.