# Trajectories and Resource Management of Flying Base Stations for C-V2X
## 4 Aerial Operation
### UAV Trajectory Planning  
The design of the UAV trajectory followed a number of rules to ensure an efficient operation. In this work we started from the approaches of [12; 47], and we revised them to adapt to the vehicular scenario. In particular, the path planning was defined according to a number of factors: the position of vehicles, their application requirements, the traffic density and the sum throughput estimation based on the resource pool capacity. Algorithm 2 represents the protocol implemented for the UAV trajectory. Let us assume it is located in \(Q\) (\(x\), \(y\), \(h\)) at a given instant \(t\), when a new flight direction has to be chosen. In our case, the flight lasts 10 minutes. The UAV knew, through a network controller, the updated information on the positions and traffic demand of the vehicles not served yet. Based on this:  
* the vehicles out of TBSs service were grouped in \(K\) clusters, where \(K=P_{v}\cdot 100\) (e.g., 10 clusters for 10% of active vehicles, 20 clusters for 20%, etc.) using the centroid-linkage UPGMC algorithm [48];
* for each cluster (\(i=1,\ldots,K\)), its central point, the centroid, was computed;
* for each centroid (\(i=1,\ldots,K\)), a cost function, \(C_{i}\), was computed (see below);
* the centroid having the smallest cost value was selected as the next stop and its distance from \(Q\) is denoted as \(d_{k}\);
* the UAV started flying in the direction of the chosen centroid along a segment path and reached the centroid in \(d_{k}/s\) seconds, where \(s\) is the UAV speed;
* during its entire flight, the UAV served all vehicles encountered in its coverage area. Now, to pursue system efficiency, the cost function design should include parameters such as the UAV energy consumption, its RR availability and the number of users that could be served in one spot. For these reasons, the travel distance, the estimation of network throughput and the density of vehicles are the factors affecting the cost function, which is defined as  
\[C_{i}=\frac{d_{i}}{d_{\max}}\cdot\frac{\delta_{\min}}{\delta_{i}}\cdot\frac{S_ {\min}}{S_{i}} \tag{10}\]  
where \(d_{i}\) is the distance of the \(i\)-th centroid to the UAV, \(d_{\max}\) is a normalizing factor equal to the distance of the farthest centroid to the UAV, \(\delta_{i}\) is the number of vehicles inside the \(i\)-th cluster, \(\delta_{\min}\) is a normalizing factor equal to the smallest number of vehicles inside a cluster, \(S_{i}\) is the estimated sum throughput (ST) obtained in the \(i\)-th centroid, and \(S_{\min}\) is the minimum estimated ST among all clusters. The rationale behind the cost function is to jointly give priority to a region near to where the drone is presently, to a cluster with a large number of vehicles, and to an option allowing to offload a high throughput. Each of these factors corresponds to a number between zero and one, and the cost function results from their product. This approach determines a UAV trajectory made of segments of different length, each of them covered by the UAV at constant speed \(v\) and fixed height from the ground \(h\).