# An Adaptive Data Rate Algorithm for Power-Constrained End Devices in Long Range Networks
## 5 Adaptive Data Rate Algorithm Design
### Adaptive Data Rate Control Algorithm Based on Network Performance Optimization
#### 5.2.2 Adaptive Data Rate Algorithm for Network Performance Optimization  
The main factors affecting network performance are the number of different data rates and the number of EDs using the same data rate. As the receiver of data from LoRa EDs, the GW can simultaneously demodulate LoRa signals with different data rates without interference. However, most GWs can demodulate a maximum of eight different data rates at the same time, which serves as a constraint for network performance optimization. Using the optional communication parameters for each ED obtained in Algorithm 1 as constraints, the implementation of the network performance optimization algorithm becomes a solution to an engineering optimization problem. Assuming there are \(n\) EDs in the network and different data rates, the selectable transmission power for each ED obtained through Algorithm 1 is \(TP_{i}\), the selectable SF list is \(listSF_{i}\), and the selectable BW list is \(listBW_{i}\). The number of EDs using data rate \(DR_{k}\) is \(num_{k}\). The optimization objective of this problem is to maximize the network performance score \(\text{S}\left(\Gamma,E_{avg},T_{avg}\right)\), and this optimization problem is represented by Equation (46). \[s.t.\begin{cases}\max\text{S}\left(\Gamma,E_{avg},T_{avg}\right)\\ \sum\limits_{k=1}^{m}num_{k}=n\\ m\leq 8\\ TP_{i}=TP_{i  
``` Input:\(\{node_{num},TP_{i},list(BW),list(SF)\}\), where \(i\in(1,2,\ldots,N)\) Output:\(list(node_{num},TP,SF,BW)\) \(Bestscore=0\), \(list(node_{num},TP,SF,BW)=[]\) for each node\({}_{num}\)do \(TP=\min(list(SF))\), \(BW=\max(list(BW))\)  append \((node_{num},TP,SF,BW)\) to \(list(node_{num},TP,SF,BW)\) \(Score=calculate\_score(list(node_{num},TP,SF,BW))\) if\(Score>Bestscore\)then \(Bestscore=Score\) endif endfor \(Zebra\_population=initialize\_population(list(node_{num},TP,SF,BW))\) for\(iter=1\) to \(max\_iterations\)do \(P_{s}=random(0,1),r=random(0,1)\) if\(P_{s}\leq 0.5\)then for each terminal in Zebra_population do \(node_{num},TP,SF,BW=terminal\) \(SF_{new}=random(list(SF))\), \(BPs_{new}=random(list(BW))\) \(terminal=(node_{num},TP,SF_{new},BW_{new})\) endfor else for each terminal in Zebra_population do \(node_{num},TP,SF,BW=terminal\) \(AZ_{terminal}=best\_solution(node_{num})\) \(SF_{new}=SF+r\cdot(AZ_{SF}-SF)\) \(BW_{new}=BW+r\cdot(AZ_{BW}-BW)\) \(terminal=(node_{num},TP,SF_{new},BW_{new})\) endfor endif \(Score=calculate\_score(list(node_{num},TP,SF,BW))\) if\(Score>Bestscore\)then \(Bestscore=calculate\_score(list(node_{num},TP,SF,BW))\) \(Bestscore=calculate\_score(list(node_{num},TP,SF,BW))\) \(Bestscore=calculate\_score(list(node_{num},TP,SF,BW))\) \(Bestscore=calculate\_score(list(node_{num},TP,SF,BW))\) if\(Score>Bestscore\)then \(Bestscore=Score\) endif endfor \(Zebra\_population=initialize\_population(list(node_{num},TP,SF,BW))\) for\(iter=1\) to \(max\_iterations\)do \(P_{s}=random(0,1),r=random(0,1)\) if\(P_{s}\leq 0.5\)then for each terminal in Zebra_population do \(node_{num},TP,SF,BW=terminal\) \(node_{num},TP,SF,BW=terminal\) \(SF_{new}=random(list(BF))\) \(terminal=(node_{num},TP,SF_{new},BW_{new})\) endfor else for each terminal in Zebra_population do \(node_{num},TP,SF,BW=terminal\) \(AZ_{terminal}=best\_solution(node_{num})\) \(SF_{new}=SF+r\cdot(AZ_{SF}-SF)\) \(BW_{new}=BW+r\cdot(AZ_{BW}-BW)\) \(terminal=(node_{num},TP,SF_{new},BW_{new})\) endfor endif \(Score=calculate\_score(list(node_{num},TP,SF,BW))\) if\(Score>Bestscore\)then \(Bestscore=calculate\_score(list(node_{num},TP,SF,BW))\) \(BestscoreDuring the iterative process, the zebra population is updated using random probabilities and adjustment values. The selection method involves either randomly generating new configurations or adjusting based on the current best solution. For each updated configuration, the algorithm recalculates the network performance score. If the new score is higher than the current best score and meets the constraints (such as the maximum number of ED data rate combinations and the total number of EDs), the best score and configuration are updated.