## 4 SF-Partition-Based Clustering and Relaying (SFPCR) Scheme
### SF-Based IoT Network Partitioning  
In the SFPCR scheme, we divided an IoT LoRa network field into two zones, the low spreading factor zone (LSFZ) and the higher spreading factor zone (HSFZ), to resolve the near-far fairness problem in the packet success ratio. In the HSFZ, the LoRa nodes were clustered to enhance data collection ability and transmission reliability, and the cluster head (CH) in each cluster used a LoRa node in the LSFZ as a relay node to forward data to the GW. Algorithm 1 shows an SF partitioning algorithm to find an optimal partitioning threshold point (\(P_{opt}\)) for dividing an IoT LoRa network field into an LSFZ and an HSFZ. Then, a virtual partition threshold point (\(\Theta_{th}\)) is used for making the LSFZ and the HSFZ. The algorithm employs a heuristic process with (\(0\leq\Theta_{th}\leq 100\)) until no packet success probability gaps exist. At each iteration, the algorithm evaluates the modified packet success probability of all the LoRa devices in the respective zones until \(P_{opt}=\Theta_{th}\). Moreover, if \(P_{suc}^{i}(loc(x))<\Theta_{th}\), the packet success probability of LDs in the HSFZ is being improved and the reverse is true for the packet success probability in the LSFZ.  
```
Input:\(P_{suc}^{i}(loc(x))\): LoRa device success probability Input:\(N\): number of IoT LoRa devices Input:\(x\): LoRa device's location Input: BW: bandwidth Input: SF: spreading factor of a LoRa device Output: Boundary point LSFZ and HSFZ, \(P_{th}\)
1: Initialization
2:\(Sum\gets 0\)
3:\(P_{max}\gets 0\)
4:\(P_{opt}\gets 0\)
5:for\(\Theta_{th}=0:100\)do
6:for\(i=\)1:\(N\)do
7: Calculate \(P_{suc}^{i}(loc(x))\) in Equation (13)
8: Calculate \(P_{Asuc}^{i}(P_{suc}^{i}(loc(x)),\Theta_{th})\)
9:\(Sum+=P_{Asuc}^{i}(P_{suc}^{i}(loc(x)),\Theta_{th})\)
10:endfor
11: Calculate \(P_{avg}(\Theta_{th})=\frac{Sum}{N}\)
12:if\(P_{max}<\)\(P_{avg}(\Theta_{th})\)then
13:\(P_{max}=P_{avg}(\Theta_{th})\)
14:\(P_{opt}=\Theta_{th}\)
15:endif
16:endfor
17:return\(P_{opt}\)
```  
**Algorithm 1**Pseudocode for boundary cut-off point of LSFZ and HSFZ.  
Subsequently, the GW was placed at the network's midpoint, and its location was used as a reference point to define the network's zones. It should be noted that the optimal coverage range of each zone determined the LoRa devices density deployed in each zone. The initialization and beaconing processes provided the GW with global knowledge of the entire network. Thence, we deduced the average success probability \(P_{avg}(\Theta_{th})\) for all LoRa devices, necessitating the determination of the partition threshold point \(\Theta_{th}\) for the SF zones. Specifically, distinct virtual zones could be formed based on the network reliability deduced from the average success probability \(P_{avg}(\Theta_{th})\) for all the LoRa devices at a particular distance from the GW as shown in Equation (15) for respective SF among all nodes.  
\[P_{avg}(loc(x),\Theta_{th})=\frac{1}{N}\sum_{i=1}^{N}(P_{suc}^{i}(loc(x)), \Theta_{th}) \tag{15}\]In Equation (15), \(N\) is the number of LoRa devices whose packet success probability has already been registered at the GW. Under the condition that \(P_{suc}^{i}(loc(x))>P_{opt}\), LDs in the LSFZ have a success probability greater than the calculated threshold value. Here, \(P_{opt}\) is based on the average success probability (\(P_{avg}\)) of all the LDs that take up the SF regions with faster chirps. Any LoRa device in the LSFZ, in particular, is a potential relay candidate for CHs. Otherwise, the remaining SF zone is referred to as the HSFZ. LoRa devices in the HSFZ have a lower success probability than the computed threshold if \(P_{suc}^{i}(loc(x))<P_{opt}\), which includes all LDs far from the GW and within the transmission radio range \((T_{r})\) that suffer from near-far effect due to the fading channel and path loss caused by obstacles.