## 4 SF-Partition-Based Clustering and Relaying (SFPCR) Scheme
### Density-Based Subspace Clustering in the HSFZ
The attributes of an LD(i) include, but are not limited to, the residual energy (\(E_{re\_N_i}(t)\)), the link quality (\(L^{(i)}\)) between LD(i) and its neighbour, and the distance ratio \((D_{ratio}(n_{i},N_{i}))\) evaluated as the minimum distance of a source node \(n_{i}\) to the relay LoRa device \(N_{i}\) in the LSFZ. As a result, a vector of attributes can be expressed as Equation (19). \[A^{(i)}=\{E_{re\_N_i}}(t),L^{(i)},D_{ratio}(n_{i},N_{i})\}\] (19) Here, \(E_{re\_N_i}(t)\) (24) and \(L^{(i)}\) (13) are considered as the primary parameters, and \(D_{ratio}(n_{i},N_{i})\) is considered as the secondary parameter and is calculated using Equation (20). \[D_{ratio}(n_{i},N_{i})=\left[\frac{d_{i}}{\sum_{i=1}^{N}\left[\frac{d_{i}}{N} \right]}\right]^{min}\] (20) In Equation (20), \(n_{i}\) is the source LD in the \(i\)th cluster, \(N_{i}\) is the selected relay LD at a time (t), and \(d_{i}\) is the distance from the source LD to the relay LD, respectively. Then, the goal of the CH selection is to find an appropriate mapping relationship between \(C\) and \(A^{(i)}\), where \(C\) is the binary score of attributes to which the LD belongs, either a cluster member (CM) or a cluster head (CH), and is expressed as \(C=\{b_{0},b_{1}\}\). \[P(C=b_{1}|A^{(i)})=\frac{P(A^{(i)}|C=b_{1})P(C=b_{1})}{P(A^{(i)})}\] (21) \(P(C=b_{1}|A^{(i)})\) expresses the probability of LD(i) becoming the CH with the classification \(A^{(i)}\) using the Bayesian theorem expressed in Equation (21). Finally, the GW selects the LoRa device with the highest probability of becoming a CH within the clustered region based on Equation (22), which is also represented in Algorithm 2. \[C\leftarrow\underset{b_{1}}{\text{argmax}}\left(P(A^{(i)}|C=b_{1})\right)\] (22) In order to create connectivity between LoRa devices LD(i) in the HSFZ, each CH communicates with cluster members within a transmission radio range \((T_{r})\) shown as \(CH_{i}|d(LD(i),CH_{i}<T_{r}\). In addition, after a certain number of rounds at a time (t), the network carries out the clustering procedure again for reclustering. Once reclustering is complete, the GW continuously monitors the residual energy and link quality of LoRa devices in the HSFZ to choose new CHs based on the updated parameter values to ensure network continuity. The energy threshold \((E_{th})\) is established to prevent the early death of some LoRa devices owing to their uneven energy decrease. In the SFPCR scheme, the energy threshold was assessed using the average energy of all LDs. ```
1:\(X=X_{1},X_{2},\ldots,X_{n}\): set of LoRa Devices (LDs)
2:\(A^{(i)}\): LoRa Device metric attributes
3:N: number of LoRa Devices
4:\(\kappa\): optimal number of CHs
5:Output: Clusters of all LDs in HSFZ, CH allocation
6:Network initialization
7:All \(C^{(i)}=b_{0}\)
8:for\(i\gets 1:N\)do
9: Calculate the \(E_{re\_N_{i}}(t),L^{(i)},D_{ratio}(n_{i},N_{i})\)
10:if\(L^{(i)}\geq L_{th}\)&&\(E_{re\_N_{i}}(t)\geq E_{th}\)then
11: Add LD(i) to CH candidate set
12:else
13: Add LD(i) to cluster member (CM)
14:endif
15:endfor
16:for All LDs\(\in CH\)candidate setdo
17: Calculate the \(P(C=b_{1}|A^{(i)})\)
18:if\(P(C=b_{1}|A^{(i)})=\max\{P(C=b_{1}|A^{(i)})\}\)then
19:\(C^{(i)}=\{b_{1}\}\)// LD(i) is set as a CH
20:else
21:\(C^{(i)}=\{b_{0}\}\)// LD(i) is set as a CM
22:endif
23:endfor
24:return\(CH\)
```  
**Algorithm 2**Pseudocode to select cluster heads in the HSFZ.