## 3 Problem Formulation
If the cluster heads (UDAPs) do not connect in a single jump to the base station (due to the coverage radius restriction), they could do it by multiple jumps supported in the transition UDAPs. In such a way, the point-to-point distances that are part of the accumulated distances from the initial node to the destination node will be determined by the maximum distance allowed between the UDAPs and the base station. Finally, Equation (12) expresses that the necessary optical fiber distance must exist, guaranteeing the connectivity between the BSs, toward the central office. ```
1:\(aux_{i,j}\gets dist_{i,j}\);
2:\(pairs(i)\leftarrow\gamma_{i,j}\);
3:\(s\gets 1;h\gets 0\);
4:if\(length(pairs)\
eq empty\)&&\(r_{ni}\leq r_{ds}\)then
5:while\(s\leq m\parallel h\leq w\)do
6:\(flag\gets 1\);
7:\(path\leftarrow pairs(i)\);
8:while\(flag==1\)do
9:add\(\leftarrow\) find next adjacent node index \((aux_{i,j})\);
10:\(path\leftarrow[path\)add];
11:\(s=s+1\);
12:if\(m\leq s\)then
13:\(flag\to 0\);
14:\(group\leftarrow path\);
15:\(dist(group)\gets inf\);
16:Send\((group)\);
```  
**Algorithm 1** Nearest-neighbor spanning tree: receive (m, \(r_{ds}\), w, \(\gamma_{i,j}\), \(dist_{i,j}\)). ```
1:for\(i\to 1:length(group)\)do
2:\(x_{UDAP}\leftarrow x_{s}[group(i)]\);
3:\(y_{UDAP}\gets y_{s}[group(i)]\);
4:\(k^{\prime}\), \(j^{\prime}\gets Dijkstra(group,[x_{UDAP},y_{UDAP}])\);
5:\(path\leftarrow[k^{\prime}\), \(j^{\prime}]\);
6:\(G^{\prime}(path)=1\);
7:\(\alpha\gets End\) to end delay, FSPL ;
8:\(Sol\leftarrow[Sol\) a];
9:\(\alpha\gets min(Sol)\);
10:\(index(i)\gets find(\alpha)\);
11:\(UDAP\gets group(index)\);
12:Send\((UDAP,\,\alpha)\);
```  
**Algorithm 2** Optimal delay balancing: receive (group, \(x_{s}\), \(y_{s}\)). Algorithm 3 requires the input of the coordinates (_SMs_, \(BS\) and \(C_{off}\)). The coordinates are georeferenced. Therefore, it allows rehearsing a real scenario. Following that, a distance matrix is obtained using the haversine formula between the displayed SMs. Once the distance matrix is identified, a \(\gamma\) vector is created with the pairs of adjacent SMs and is ordered according to the distance between pairs from least to greatest. It is important to mention that the starting criterion for the exploration and construction of the clusters begins from the pair of SMs with the minimum distance. In addition, Algorithms 1 and 2 are iteratively called from Algorithm 3 to obtain the results. Once obtained \(\gamma\), Algorithm 3 calls Algorithm 1 (N-NST) to solve the wireless network deployment by minimizing the number of UDAPs through a heuristic based on the Prim algorithm. Thus, it is possible to guarantee the coverage of SMs as long as they comply with the restrictions. Recall that one of the objectives is to reduce the use of cellular links (higher cost) and exchange them with WiFi links (lower cost). Firstly, from the \(\gamma\) vector, the SM that has the shortest distance to the BS is selected. This SM is a candidate that could be a UDAP. What has been done brings about a pre-clustering of a wireless network that achieves the connection of SMs forming a tree of minimum expansion. This problem is NP-complete. The end to end delay and the losses in the obtained topology are verified by propagation of the wave in the free space. This topology is recorded in the adjacency binary matrix (G) Subsequently, Algorithm 3 verifies by means of Algorithm 2 whether it is possible to decrease the end to end delay and the losses by propagation of the wave in the free space by means of the intra-cluster modification previously obtained. If this decrease is possible, the algorithm takes the latter as the best solution, otherwise it takes the first option. Therefore, the model iterates and corrects what was originally obtained as a result with Algorithm 1. The model iterates until the objective function (subject to restrictions) is the minimum. It also verifies that there is no option to further reduce the cost of cellular links, delays and losses by propagation of the wave in free space.