# Unmanned Vehicles' Placement Optimisation for Internet of Things and Internet of Unmanned Vehicles
## 6 Proposed Algorithm: Communication Optimisation Integration
### Position Optimisation Algorithm
**Output:** Optimum latitude \(\phi_{opt,n_{i}}\), longitude \(\lambda_{opt,n_{i}}\), elevation \(\epsilon_{opt,n_{i}}\) for each UV
1: Initialize \(d_{th}\) {Maximum allowed distance offset}
2: Compute initial 2D and 3D distances between each node, \(d_{i,j}^{2D}\), \(d_{i,j}^{3D}\)
3: Assign path loss model based on the IDs and position parameters of each two nodes (A-G, A-W, A-A, W-G, W-W, G-G)
4: Compute initial path loss \(PL(n_{i},n_{j})\)
5: Generate path loss graph G(PL)
6:\(cr\gets n_{GW}\)
7:\(k\gets 0\)
8:while\(k\leq N_{vm}\) & \(P=\emptyset\)do
9:\(ek\gets 0\) {Height exponent}
10:\(t\gets 0\)
11:\(next\gets CN[k]\)
12:if\(next>n_{UAV}\)then
13:\(changed\gets 0\) {USVs cannot change antenna height}
14:else
15:\(changed\gets 1\)
16:endif
17:\(im\gets 1\) ```
**Algorithm 3** Path loss-based placement optimisation algorithm  
**Input:**\(n_{ULAV}\), \(n_{USV}\), \(N_{cm}\), \(N_{m}\) GPS coordinates; served WSN; \(h_{th}\) {Maximum allowed UAVs altitude}; \(h_{FSPL}\) {Minimum UAVs altitude to apply FSPL model};\(\beta h\) {Height step} \(LB\) {Link Budget}, \(\delta d\) {Distance step for \(PL<LB-\Delta_{LB}\)}, \(\delta d\) {Adaptive distance step for \(PL>LB\)}, \(\rho\) {Coefficient for adaptive distance step \(\Delta d\)}. **Output:** Optimum latitude \(\phi_{opt,n_{i}}\), longitude \(\lambda_{opt,n_{i}}\), elevation \(\epsilon_{opt,n_{i}}\) for each UV
1: Initialize \(d_{th}\) {Maximum allowed distance offset}
2: Compute initial 2D and 3D distances between each node, \(
```
33: Restore previous state: \(\phi_{next}\leftarrow\phi_{0}\) (old latitude), \(\lambda_{next}\leftarrow\lambda_{0}\) [old longitude], \(PL\gets PL_{0}\), \(d^{2D}\gets d_{0}^{2D}\), \(d^{3D}\gets d_{0}^{3D}\))
34:endif
35:else
36: Repeat Steps 32-33
37:endif
38:endwhile
39:\(imp\gets 1\)
40:
41:Height optimisation
42:
43:if\(changeh=1\)then
44:while\((imp=1)\) & \(((w_{cr,next}>1+\zeta))\)do
45:\(h_{next}\gets h_{next}^{0}+((-1)^{ek})*\delta h\)
46:if\(h_{next}<h_{th}\)then
47: Store previous state ( \(w_{0}\gets w\), \(d_{0}^{2D}\gets d^{2D}\), \(d_{0}^{3D}\gets d^{3D}\), \(h_{next}^{0}\) )
48:\(d^{3D}=\mathcal{H}(d^{2D},h_{next})\)
49: Compute \(w_{j,next}\)\(1\leq j\leq N_{m}\)
50:if\(w_{cr,next}<w_{0_{cr,next}}\)then
51:\(imp\gets 1\)
52:else
53: Restore previous state
54:\(trial\gets trial+1\)
55:if\(imp=1\)then\(imp\gets 0\)
56:else
57:if\(trial>2\)then
58:\(imp\gets 0\)
59:else
60:\(ek\gets 1\)
61:endif
62:endif
63:endif
64:else
65:\(imp\gets 0\)
66:endif
67:endif
68:endif
69:\(imp\gets 1\)
70:\(imp\gets 1\)
71:
72:Distance optimisation
73:\(trials\gets 0\)
74:while\((improve=1)\) & \((w_{cr,next}>1+\zeta)\)do
```
**Algorithm 1** \(\phi_{next}\)
```
75: Store previous state ( \(PL_{0}\gets PL\), \(d_{0}^{2D}\gets d^{2D}\), \(d_{0}^{3D}\gets d^{3D}\))
76:\(\Delta d\gets d_{0,next}^{2D}*\rho\)
77:
78:if\(d_{0,next}^{2D}>0\)then
79:\(\Omega\leftarrow\angle(tx_{cr}.tx_{next})\)
80:\(\phi_{next}\leftarrow\mathcal{F}(\phi_{0},d_{0,next}^{2D}-\Delta d,\Omega)\) (new latitude)
81:\(\lambda_{next}\leftarrow\mathcal{G}(\lambda_{0},d_{0,next}^{2D}-\Delta d,\Omega)\) (new longitude)
82: Compute \(w_{cr,next}\)
83:if\(w_{cr,next}<w_{0,next}\)then
84:\(imp\gets 1\);
85:else
86:if\(d_{0,next}^{2D}>d_{cr,next}^{2D}>\)then
87:if\(trials<nt\)then {Avoid values where PL is constant, \(nt\), number of trials}
88:\(trial\gets trial+1\)
89:
90:continue
91:endif
92:else
93:\(imp\gets 0\)
94: Restore previous state
95:endif
96:endif
97:else
98:\(imp\gets 0\)
99:endif
100:endwhile
101:\(P\leftarrow\) shortest path nodes between GW and target WSN
102:\(cr\gets CN[k]\)
103:\(k\gets k+1\)
104:if\(cr=CN[end]\)then
105:break
106:endif
107:endwhile
108:\(\phi_{opt,n_{i}}\leftarrow\phi_{n_{i}}\), \(\lambda_{opt,n_{i}}\leftarrow\lambda_{n_{i}}\), \(\epsilon_{opt,n_{i}}\gets h_{n_{i}}\)
109:return
110:\(\phi_{opt,n_{i}},\lambda_{opt,n_{i}},\epsilon_{opt,n_{i}}\)
```  
**7. Positioning Algorithm Evaluation and Results**  
Algorithm 2 was implemented using MATLAB R2019b IDE and executed on a six-core processor, 12 logical processor station.