# A Failure Risk-Aware Multi-Hop Routing Protocol in LPWANs Using Deep Q-Network
## 5 Detailed Description of the Proposed Protocol
### Power Regulation Mechanism  
By default, ENs operate at maximum power to maintain periodic neighbor information exchange. However, this configuration becomes inefficient during data transmission, as excessive power causes resource wastage (e.g., redundant EN activations). To address this issue, FFDR introduces a Power Regulation Mechanism (PRM) that adaptively adjusts transmission power levels based on the average SNR of received signals from neighbors, thereby reducing overhead. As detailed in Algorithm 1, the standard Adaptive Data Rate (ADR) algorithm [29] adjusts data rates based on SNR to optimize throughput and energy efficiency. Building upon the standard ADR framework, we propose the PRM, which redirects optimization from data rates to transmission power levels. The workflow of PRM operates as follows:  
Step 1: Calculate the average SNR \(SNR_{avg}\) of the most recently received signals transmitted by \(n\) neighbors. Step 2: Subtract a predefined margin \(Ma\) (default: 10 dB) from the difference between \(SNR_{avg}\) and \(SNR_{th}\) to determine the SNR margin \(SNR_{margin}\), i.e., \(SNR_{margin}=\left(SNR_{avg}-SNR_{th}\right)-Ma\). Step 3: Adjust the current transmission power level \(l_{tx}\) based on \(SNR_{margin}\). If \(SNR_{margin}>0\), it suggests that \(l_{tx}\) can be reduced without compromising communication reliability. ```
1:\(\text{S}NN_{\text{req}}\leftarrow\text{demodulation floor (current data rate)}\)
2:\(\text{S}NN_{\text{max}}\leftarrow\text{max (SNR of last 20 frames)}\)
3:\(\text{S}NN_{margin}\leftarrow\text{S}NN_{\text{max}}-\text{S}NN_{\text{req}}- Margin\_dB\)
4:\(\text{N}\text{S}\text{tep}\leftarrow\text{int}(\text{S}NN_{\text{max}}/3\,)\)
5:while\(\text{N}\text{S}\text{tep}>0\)and\(\text{S}\text{S}\text{S}\text{F}_{\text{min}}\)do
6:\(\text{S}\text{S}\leftarrow\text{S}\text{S}-1\)
7:\(\text{N}\text{S}\text{tep}\leftarrow\text{N}\text{S}\text{tep}-1\)
8:endwhile
9:while\(\text{N}\text{S}\text{tep}>0\)and\(\text{T}\text{P}>\text{T}\text{P}_{\text{min}}\)do
10:\(\text{T}\text{P}\leftarrow\text{T}\text{P}-3\)
11:\(\text{N}\text{S}\text{tep}\leftarrow\text{N}\text{Step}-1\)
12:endwhile
13:while\(\text{N}\text{S}\text{tep}<0\)and\(\text{T}\text{P}<\text{T}\text{P}_{\text{max}}\)do
14:\(\text{T}\text{P}\leftarrow\text{T}\text{P}+3\)
15:\(\text{N}\text{S}\text{tep}\leftarrow\text{N}\text{S}\text{tep}+1\)
16:endwhile
17:Output:\(\text{T}\text{P}\) and \(\text{S}\)
```  
**Algorithm 1** Standard Adaptive Data Rate Algorithm. Given the dynamic nature of the link environment, relying on a fixed neighbor count, \(n\), may lead to inaccurate decisions. To overcome this limitation, PRM adaptively adjusts \(n\) based on link variability. Specifically, the DEN randomly selects \(n\) neighbors from its routing table and calculates the volatility rate of the link environment, \(R_{change}\), using Equation (13). \[R_{change}=\frac{1}{n}\sum_{i=1}^{n}\frac{|RSSI_{\text{SL}}(i)-RSSI_{\text{L}}( i)|}{|RSSI_{th}-RSSI_{\text{L}}(i)|}, \tag{13}\]  
where \(RSSI_{\text{L}}(i)\) and \(RSSI_{\text{SL}}(i)\) denote the RSSI of the last and penultimate signals received by DEN from the \(i\)-th EN, respectively. Higher values of \(R_{change}\) indicate a more volatile link environment. When \(R_{change}\) exceeds the threshold \(R_{change}^{-}\), to enhance decision accuracy, PRM increases \(n\) by 1 to incorporate diverse information from additional neighbors into the decision-making process. This adjustment repeats until either \(R_{change}\leq R_{change}^{-}\) or \(n\geq N_{n}\), thereby achieving an adaptive balance between decision accuracy and computational overhead. The initial empirical value of \(n\) is set at 3 according to [29; 30]. The detailed PRM workflow is described in Algorithm 2.