Jamming-aware optimization for UAV trajectory design and internet of things devices clustering

Radio jamming represents a serious threat in wireless networks that can cause denial of service (DoS) attacks for the network users. The jammer transmits jamming signals to disrupt the normal operation of the wireless networks. With proliferation of unmanned aerial vehicle (UAV)-based wireless networks and Internet of Things technologies, jamming attacks have become a major challenge to the practical adoption of these technologies. In this paper, we investigate the problem of optimizing the performance of the UAV data collection from ground IoT devices in presence of a malicious jammer. The IoT devices are clustered, and the UAV collects the data from the cluster heads (CHs) such that the harmful effect of the jammer is mitigated. The objective is to minimize the flight time of the UAV while collecting the data from the ground IoT devices in presence of the jamming attack. We modeled our problem mathematically as an integer linear program (ILP). Due to the difficulty of solving the optimization problem when the scale of the problem is large, we proposed Jamming-Aware UAV Routing and IoT Devices Clustering Algorithm (JA-RC). This algorithm is Genetic-based and can solve the original optimization problem in a more efficient way. Then, we investigate the performance of the proposed algorithm under different settings and scenarios.


Introduction
Unmanned aerial vehicles (UAVs) have emerged as promising solutions for many challenges in communication networks [1]. Equipping the UAV with a communication capability can support the communication networks with a more flexible infrastructure and a better quality of services. Moreover, the use of UAVs in communication networks revolutionized the services provided to the users and introduced new disruptive technologies. The benefits of the UAVs motivate the researchers to adopt them in important applications. For example, the use of UAVs in emergency reporting [2], data dissemination to the IoT devices [3] and extending the wireless coverage of the remote areas [4] are investigated.
Although we witness a huge advancement in wireless networks technologies, radio jamming attacks are still one B Abdullah Almasoud am.almasoud@psau.edu.sa 1 Department of Electrical Engineering, College of Engineering in Al-Kharj, Prince Sattam Bin Abdulaziz University, Al-Kharj 11942, Saudi Arabia of the major challenges in wireless networks. Hence, wireless networks are still vulnerable to many jamming attacks techniques. Jamming attacks refers to the unlawful generation of interference to the ongoing communication to disrupt or mislead the users in wireless networks. In other words, the jammer transmits an interfering signal using the same frequency used by the wireless network users. Several antijamming techniques have been introduced in the literature including frequency hopping, spectrum spreading, adjusting transmission power, MIMO-based jamming resilient networks and jamming-aware protocols and network design [5]. Interestingly, some of these techniques may not be effective for some applications. For instance, the high mobility of the user in the Vehicular Ad-hoc Networks (VANETs) can make frequency hopping-based anti-jamming techniques less effective [6]. Hence, the selected anti-jamming technique should be suitable for the desired application.
One of the recent and promising anti-jamming techniques is the use of the UAV in mitigating the jamming attacks in wireless networks [5]. Thanks to the high flexibility of the UAV in adjusting its location and operation to alleviate the jamming attack or even avoid the negative effect of the jam- Fig. 1 Attacker is jamming the uplink communication between the IoT device and the UAV mer. However, the UAV itself can be the target for the jammer to impair the normal operation of the UAV-based communication networks. For example, Fig. 1 shows a jammer attacking the uplink transmission from an on ground IoT device transmitting to a UAV. In this paper, we investigate this challenge and propose a jamming-aware scheme for data collection from the IoT devices based on jamming-aware UAV routing and IoT devices clustering techniques.

Related works
In [7], anti-jamming trajectory design for the UAV under a jamming attack in Wireless Sensor Networks is investigated. The goal is to maximize the average data rate for the ground users in the presence of a malicious ground jammer. In [8], the authors proposed a scheme for UAV communication with ground users in the presence of multiple jammers. The aims of this scheme are optimizing the UAV trajectory and maximizing the energy efficiency of the UAV. UAV relaying schemes are proposed in [6] and [9] to relay the data from the On Board Unit (OBU) in vehicular ad-hoc networks (VANETs) when the designated Roadside Unit (RSU) is under a jamming attack. The UAV relays the message of the user to another RSU not suffering from the jamming attack.
In [10], the authors proposed an UAV-aided anti-jamming framework for cellular networks. The UAV uses reinforcement learning methods to choose the relay policy for users in the cellular networks. To resist the jamming attack, the UAV relays the traffic of the jammed base station to a backup base station. In [11], UAV path planning and the signal-tointerference-plus-noise ratio (SINR) is maximized when a jammer exists in the network. A Bayesian Stackelberg game is proposed in [12] to mitigate the problem of jamming in UAV communication networks. The work considers the incomplete information regarding the co-channel interference in the UAV communication networks. The jammer acts as the leader and the users function as followers in the pro-posed game. Accordingly, the users select their transmission power policies such that the effect of the jammer is mitigated.
The authors in [13] considered an anti-jamming communication in a UAV swarm in the presence of jamming. The UAV exploits the degree-of-freedom in frequency, motion, antenna and spatial domain to optimize its data reception, while a jammer is attacking the network. In [14] and [15], the authors proposed a joint optimization for the transmission power and the UAV trajectory in anti-jamming communication networks. A Stackelberg framework and Q-learning-based anti-jamming scheme are utilized to solve the optimization problems.
In [16], the authors proposed a fair data collection scheme for intelligent transportation systems. The storage devices are clustered, then the UAV collects the data from the cluster heads. For fair data collection, the UAV controls its speed such that it slows down when the cluster size is large. This helps in providing the cluster head of the large cluster more time for sending its larger data messages. In [17], UAV is utilized to collect data from sensor clusters and charge the sensors using wireless energy transfer technology. The sensors are located in harsh terrains, and the objective for the UAV is to maximize the data collection from the sensors.
The authors in [18] considered the problem of data collection for large scale wireless sensor networks. They proposed to cluster the sensors into clusters, where the forwarding rule within the cluster is based on the value of the information and the power of the nodes. The value of the information concept means that the value of the event is highest when it first happens, where the value of information decreases with time. The UAV is used to collect the data from the cluster heads. The objective is to maximize the value of information of the collected data. In [19], an energy-efficient and fast data collection scheme is designed to gather sensing information from sensors. A UAV collects data from sensors located in hilly terrains, where it acts as a data mule. Energyefficient distributed clustering algorithm is utilized to cluster the sensors, then a modified tabu search algorithm is used to optimize the UAV position. In [20], the authors proposed to use a UAV for data collection in dense wireless sensor networks. Projection-based Compressive Data Gathering is used to reduce the number of transmissions and energy consumptions. The sensor nodes are clustered and the forwarding tree is built such that the sum of total transmission power and the UAV flight distance is minimized.
In [21], the work studied the data ferrying problem using a UAV to deliver the collected data between separate and unconnected points. The goal is to improve delay-tolerant communication while collecting and ferrying data. It is shown that considering the radio propagation in designing the routing path of the UAV can reduce the delay significantly. On the other hand, transmission mode between two nodes can be direct, through a relaying process or by data ferrying. Accordingly, the authors in [22] optimize the selection of transmission mode based on several parameters, such as the distance between the nodes and the tolerable delay. Moreover, the work in [23] integrates nonparametric learning with path planning in UAV-based data ferrying communications. Radio environment is observed and the UAV improves the communication model over time. This results in a more accurate plan for the UAV path.
Data ferrying mechanism is proposed in [24] to collect data from isolated location and offloads within a certain tolerable delay. The problem is formulated, where the objective is to minimize the distance traveled by the UAV. In [4], an energy-efficient scheme for collecting and forwarding the collected data from isolated remote fields is proposed. Each field is associated with a UAV that conveys the sensing data of that field and delivers it to a sink node. The delivery of the data can be directly from the field to the sink node or through cooperative UAVs. The objective is to maximize the minimum battery level among all UAVs to prolong the lifetime of the network.
The authors in [25] proposed to utilize a UAV for data collection from IoT devices in the presence of a jammer. Intelligent Reflecting Surface (IRS) is employed to assist in improving the signal reception by the UAV. The proposed scheme aims in enhancing energy efficiency by jointly optimizing the beamforming of the RIS, power allocation, scheduling and planning the UAV trajectory. The authors in [26] studied how to maximize the lifetime of a UAV-assisted network when there are multiple sources of interference. The UAV collects data from distributed sensors in presence of jamming, where the authors assume that the clusters of the IoT devices and their CHs are given. In [27], a data collection framework is proposed that utilizes multiple UAVs in wireless sensor networks. Given the locations of the sensor nodes, these nodes are clustered based on k-means clustering and the CHs are selected. Then, the number of used UAVs and their trajectories such that the flight time is minimized.
A UAV-based data collection system for sensors located in a straight line is introduced in [28]. The speed of the UAV and the sensors' transmission powers is optimized. The objective is to minimize the total flight time. Another UAV-based data collection system for collection data from ground sensors is introduced in [29]. The goal is to minimize the mission time while considering the UAV trajectory, velocity, altitude and link scheduling. Similarly, mission completion time is minimized for a UAV-based data collection system introduced in [30]. In addition, the UAV charges the ground terminals using wireless power transfer. Accordingly, the proposed work considered optimizing the UAV trajectory, transmission scheduling and charging. In [31], data collection from timeconstrained IoT devices using a UAV is investigated. The objective is to maximize the number of served IoT devices within a certain period of time restricted by a deadline.
Many anti-jamming techniques are investigated in the literature, e.g., in [5], including the use of UAVs to mitigate the jamming attacks. Although the UAV provides an effective method to alleviate the jamming attack, the UAV may suffer from the scalability issue when it is required to collect data from a large number of IoT devices. By jointly designating a jamming aware IoT devices clustering and UAV path planning, the UAV can serve more IoT devices under a jamming attack in a shorter time. To the best of our knowledge, there is no existing work investigating a jointly jamming-aware IoT device clustering and UAV path planning. Table 1 presents a comparison between the most relevant works and our proposed scheme. Our goal is to minimize the time required for data collection from the IoT devices using a UAV and in the presence of a jammer. Instead of visiting all IoT devices to collect data from them, the IoT devices are clustered and only the CHs are visited by the UAV. Interestingly, we proposed a jamming-aware clustering such that the UAV can collect the data from the CHs successfully even with a presence of the jammer. Therefore, we compared our work with the other works based on the consideration for (1) Data Collection (DC), (2) Flight Time Minimization (FTM), (3) Jamming-aware system (JA) and (4) Clustering (C). To the best of our knowledge, this is the first work aiming at minimizing the UAV mission completion time for data collection process in the presence of a jamming attack by optimizing the UAV routing trajectory and jamming-aware clustering. As shown in Table 1, none of the existing related works jointly considered minimizing the UAV flight time while optimizing its path during data collection and considering a jamming-aware clustering. Most of the existing-related works either focus on data collection in the presence of a jammer without considering the clustering to minimize the mission completion time or focus on data collection but without the consideration for the jamming attack. We compare our joint clustering and UAV path planning with other works such as optimizing the trajectory and clustering separately and with no clustering. The results presented in the Simulation Results Section (Section "Simulation results") show that our proposed work reduces the required time by the UAV to complete its data collection task.

Motivations and contributions
With adoption of the UAV data collection in the IoT, jamming attacks for the communication between on ground IoT devices and a flying UAV is a critical challenge. Without mitigating this challenge, utilizing the UAV in data collection can be an inefficient and unreliable method. Therefore, we propose in this paper a jamming-aware scheme for clustering the IoT devices and routing the UAV such that the UAV collects the data from all CHs successfully. Accordingly, the Relaying messages in VANET in presence of a jammer [7] Maximizing the minimum average data collection rate [8] Maximizing energy efficiency of the UAV [9] Relaying messages in VANET in presence of a jammer [10] Anti-jamming relaying in cellular communications [11] Maximize the SINR at the UAV [12] Optimizing power control to support anti-jamming communications [13] Improving the signal-to-interference power [14] Jointly optimizing power and trajectory [15] Anti-jamming power control in UAV networks [16] Maximizing the amount of collected data by controlling the UAV' speed [17] Maximizing data collection from the sensors and charging them [18] Maximizing the value of the collected data [19] Optimizing energy consumption and received signals strengths [20] Minimizing the weighted sum of transmission power and flight distance [21] Minimizing delay of data ferrying [22] Optimizing the selection of communication mode between nodes [23] Optimizing trajectory design for the UAV [24] Minimizing the distance traveled by the UAV [4] Maximizing the minimum battery level among all UAVs [25] Improving energy efficiency [26] Maximizing lifetime of the network [8] XXX [27] Minimizing flight times of the UAVs [28] Minimizing flight time of the UAV [29] Minimizing mission completion time [30] Minimizing mission completion time UAV can withstand a jamming attack from a ground jammer in the IoT. The contributions of our paper can be summarized as follows: • We propose an anti-jamming scheme for collecting data from IoT devices in presence of a malicious jammer attacking the uplink channels between the IoT devices and the UAV. • Proposing a jamming-aware clustering method for the IoT devices to minimize the number of way points visited by the UAV and to reduce the mission completion time. • Modeling our problem mathematically, where the objective is minimizing the number of required time slots while collecting data from all IoT devices.
• Proposing a Genetic-based algorithm to solve our problem in a more efficient way due to the high complexity of solving the original problem optimally. • Studying the performance of the proposed algorithm under several scenarios.
The remainder of this paper is organized as follows. We introduce the system model in Section "System model". Then, we formulate our problem mathematically in Section "Problem formulation". Section "Problem solution" presents our proposed Algorithm for solving the optimization problem. Then, we show the simulation results in Section "Simulation results" and conclude our paper in Section "Conclusion".

System model
We consider an area of size x max m × y max m, which is gridded into a certain number of locations. The set of all locations is N , and the set of all IoT devices is I . These IoT devices are clustered, then one device from each cluster is selected to be the cluster head, CH. Starting from an initial location α, the UAV visits all CHs to collect data from them then flies to its final location β. The height and speed of the UAV are H and S, respectively. During the data collection from a CH, the UAV hover over the CH and sends beacons/poll messages to notify it about the readiness to collect the data. The UAV sends the poll message over a Common Control Channel (CCC) shared between the UAV and the IoT devices. Once the CH receives the poll message, it starts sending its data to the UAV. To accelerate data collection from the IoT devices, they are clustered and the UAV visits only the cluster heads. We assume that the time is slotted, where the set of time slot indices is T , i.e., the number time slots is |T |. When we mention in the paper that the UAV moves from location i to location j, we mean that the UAV is initially above location i and flies toward location j with height H .
We assume the IoT devices are fixed, and their locations are known before planning for the UAV flying trajectory. Moreover, the IoT devices can discover the location of the jammer using a jammer localization method introduced in [32]. Initially, the assumption is that no jammer exists in the network. Hence, the UAV plans its flying trajectory from its initial location to the final location after deciding the cluster heads to be visited. Once the UAV receives messages from IoT devices reporting the existence of a jammer during its flight nearby these IoT devices, the UAV considers its current location to be the new initial location, re-cluster the unvisited IoT devices and recalculate the flying trajectory again to mitigate the effect of the jammer. Then the UAV continues its flight according to the updated flying path. We will show in Section "Problem solution" our proposed algorithm that can solve the optimization problem efficiently. When the UAV has a very limited computing power, the calculation can be done in a ground terminal with high computing power, then the solution is relayed to the UAV. In other words, the UAV can visit this ground terminal and support it with the locations of the IoT devices and the jammer. Then, it will receive the optimal flying path including the cluster heads to be visited.

Channel model
To model the uplink transmission from the CHs and the jammer to the UAV, we utilize a probabilistic ground-to-air channel model [33]. This model provides the LoS probability based on the elevation angle. We assume that the UAV hovers over the location of the CH during the data collection process, i.e., the elevation angle between a transmitting CH and the receiving UAV is 90 • . Accordingly, the LoS probabilities for the uplink channel between the UAV and a CH located at location i or the jammer located at location J are given, respectively, by [33] and where q and v are parameters related to the environment and θ i J is the elevation angle between the jammer located at location J and the UAV when it is above location i. Therefore, the probabilities for the uplink channel between a CH located at location i or the jammer located at location J being NLoS are given, respectively, as follows: and

Jamming model
We assumed that there is a hostile jammer trying to jam the uplink communications between the CH and the UAV, as shown in Fig.1. Accordingly, the CHs are selected such that the received signal by the UAV from the CHs withstand the noise generated by the jammer. Hence, the Signal-to-Interference-plus-Noise Ratio (SINR) of the signal received by the UAV should be greater than a threshold γ . Moreover, we assume that the location of the jammer can be derived using a jammer localization method with a high accuracy [32]. The uplink communication between a ground terminal (an IoT device or the jammer) and the UAV can be Line-of-Sight (LoS) or Non-Line-of-Sight (NLoS). Hence, we have four possibilities for the status of the links between the CH and the UAV and the link between the jammer and the UAV: 1. NLoS channels for the link between the CH and UAV and the link between the jammer and UAV (NN).

NLoS channel for the link between the CH and UAV and
LoS for the link between the jammer and UAV (NL).

LoS channel for the link between the CH and UAV and
NLoS for the link between the jammer and UAV (LN). 4. LoS channels for the link between the CH and the link between the jammer and UAV (LL).
Based on these four possibilities, we calculate the SINR for the signal transmitted by a CH located at location i and received by the UAV, respectively, as follows [7]: where γ q i is the SINR for the signal sent by a CH located at location i and received by the UAV, and q ∈ {NN, Nl, LN, LL}. N and L refer to the NLoS and LoS channels between a ground terminal (CH or the jammer) and the UAV, respectively. β 0 is the channel power at 1 m reference distance, P I oT and P J are the transmission powers of the IoT device and the jammer, respectively, α L and α N are average path loss exponents for LoS and NLoS links, respectively, σ 2 is the power of the additive white Gaussian noise (AWGN) at the receiver, u is NLoS additional signal attenuation factor, andd i J is the distance between the UAV and the jammer when the UAV is hovering above location i.
When the UAV is hovering over location i, the expected SINR for the signal transmitted by a CH located at location i, is given by

Anti-Jamming IoT devices clustering
The UAV is required to collect data from all IoT devices and relay it to a communication network when it arrives at its final location β. Instead of collecting data directly from each single IoT device, the IoT devices are clustered, and the UAV collects data directly from the CHs. This process helps the UAV to expedite its data collection process. The CHs form clusters with radius not greater than meter. Within each cluster, the IoT devices forward their data to their CH. The CH receives data from its cluster members and stores it along with its data. Then, it waits for the UAV to arrive and relays the whole data of the cluster to the UAV. We assume that the IoT devices of each cluster communicate with their CH using different channels than the uplink channel used by the CHs to communicate with the UAV. For a successful reception of the message set by a CH located at location i to the UAV, the expected SINR of the signal received by the UAV should be greater than or equal to a threshold γ , that is Once the condition above is satisfied, the UAV can successfully receive the message from the CH. Accordingly, the cluster is formed such that the SINR of the signal transmitted by the CH to the UAV satisfies the condition in Eq. (10).

Illustrative scenarios
In Fig. 2, 3, 4, 5, 6 and Fig. 7, we present two scenarios for IoT devices clustering and UAV routing. These scenarios illustrate how a jamming attack affects IoT devices clustering and the UAV's trajectory. Figure 2 shows IoT devices distributed over an area of x max m × y max m meters, where Table 2 describes the symbols used in the figures of this section. First, we cluster the IoT devices and assign a CH to each cluster as shown in Fig. 3. Then, the UAV visits only the CHs to collect data and flies to its final location as depicted in Fig. 4. Assume that a jammer starts jamming the uplink channels dedicated for transmissions from CHs to the UAV as shown in Fig. 5. Three CHs are affected by the jamming signals   Jamming-aware data collection from the cluster heads and UAV routing (located inside the blue highlighted shade), where the jammer generates noise that affects the successful reception by the UAV. Therefore, the IoT devices are re-clustered, as presented in Fig. 6, such that the UAV can successfully receive the messages sent by all CHs. Finally, Fig. 7 presents the flying trajectory of the UAV, which avoids the areas under the jamming attack. By comparing Figs. 4 and 7, it is shown that the flying trajectory under a jamming attack results in a longer UAV routing path.

Problem formulation
In this section, we mathematically formulate the problem of IoT devices clustering and UAV trajectory planning. Our goals are planning the trajectory of the UAV such that all CHs' data is collected and the UAV finishes its data collection task as soon as possible. The constraints of our problem can be categorized into two categories: (1) UAV trajectory planning constraints and (2) IoT devices clustering constraints. In the following, we describe these constraints and show the problem formulation.

Jamming-aware UAV trajectory planning constraints
We assume that the UAV is located initially at location α. All CHs' data are ready to be collected before the UAV starts its mission. Hence, the UAV should start flying in the first time slot to finish its task as soon as possible, that is where L i j (t) is a binary variable that equals one only when the UAV moves from location i to location j during slot t. After finishing the data collection from all CHs, the UAV flies to its final location β. Accordingly, the UAV should go to the final location β during a certain time slot, that is Note that the UAV should not go back to its initial location nor fly to another location after reaching the final location. Therefore, we have and During each time slot, the UAV either flies between two points or stays at the same location. Hence i∈N j∈N Given that the UAV has visited location i ∈ N \β, it leaves that location only once and does not come back to it again. Therefore, we use the following constrain: When the UAV is visiting an intermediate node j during slot t, where j ∈ N \(α ∪ β), it leaves location j to another location during the next time slot. Hence The max distance that the UAV can travel between two locations i and j is restricted by the following constraint: where d i j is the distance between location i and location j. LetL i (t) be a binary variable that equals to one only when the UAV reached location i by the end of time slot t, that iŝ The UAV can receive a message successfully from a CH located at location i only when the expected SINR of the received signal is not below a certain threshold γ . Therefore, we add the following constraint: where T t x i (t) is a binary variable that equals one only when the message sent by the CH located at location i during slot t is received successfully by the UAV.  Since each IoT device can be a member to only one cluster, we add the following constraint: Within each cluster, only one IoT device can be a CH. Hence, we have In addition, The IoT device cannot be a CH for more than one cluster, that is When there is an IoT device belonging to a cluster, there must be a CH for that cluster. Therefore, we include this constraint to our formulation: Moreover, the distance from each IoT device within a certain cluster to its CH should not be greater than the cluster radius . Accordingly, we have If an IoT device is selected to be a CH for a cluster, this device must transmit its cluster's messages to the UAV during a time slot, that is Note that the variable T t x h (t) is related to the SINR threshold γ as shown in constraint (38). Therefore, T t x h (t) = 0 when γ ≤ E[γ h ]. Consequently, c∈C H c h = 0 when T t x h (t) = 0. Accordingly, the IoT device h will not be a CH transmitting to the UAV when γ ≤ E[γ h ]. We conclude that the clustering method used is jamming-aware and mitigates the effects of the jamming attack.

Optimization problem
Our objective is to minimize the arrival time of the UAV to its final location β. Accordingly, we minimize the index of the time slot in which the UAV arrives at its final location. In other words, we minimize the maximum time slot index t for the variableL β (t) whenL β (t) = 1. Hence, the mathematical model for our optimization problem is given by subject to: The Objective function and constraint (28) ensure that we minimize the maximum time slot index t in whichL β (t) = 1. Note thatL β (t) = 1 when the UAV reaches its final location β. The remaining constraints are described in subsections 3.1 and 3.2.

Linearization of the optimization problem
The formulated problem in subsection 3.3 is nonlinear due to the product of U c i and H c h in constraint (44). To facilitate solving this problem, we linearize it by linearizing constraint (44). Therefore, we introduce a new binary variable η(i, h, c), where η(i, h, c) = U c i H c h . Therefore, we add the following three constraints to make η(i, h, c) = U c i H c h : and Then, we replace constraint (44) by Accordingly, we reformulate the optimization problem in subsection 3.3 by the following: subject to: Constraints (28-43), (45)

Problem solution
In Sect. 3.3, The reformulated problem is in the form of the Integer Linear Program (ILP). Even after we linearize the problem, it is still hard to solve, since it is an NP-Complete problem [34]. Therefore, we propose in this section a heuristic algorithm to solve the optimization in a more efficient way. In the following, we provide a background about genetic algorithms. Then, we describe our proposed Jamming-Aware UAV Routing and IoT Devices Clustering Algorithm (JA-RC).

Genetic algorithms background
A Genetic Algorithm (GA) [35] is a metaheuristic search algorithm that is inspired by natural selection and genetics. The algorithm starts by initial feasible population, iteratively selects the best solutions and performs some GA operations to discover better solutions in the next iterations until a stopping condition is reached. The main elements of GAs are described as follows [35]: • Populations of chromosomes: The chromosome in GAs is a string of parameters that defines a certain solution.
In biology, a single gene is a locus on a chromosome. Hence, we call each single value in the string representing a chromosome a gene. A simple genetic algorithm includes the following main steps [35]: 1. Generate a random population of chromosomes (candidate solutions). 2. Evaluate each chromosome in the population by calculating the fitness function value. 3. Select chromosomes from the population, and perform crossover operations on them to generate two offspring from each crossover operation. 4. Perform mutation operations on the new generated offsprings. 5. Replace current population with the modified population. 6. Go to step 2 until a stopping condition is met (e.g., reaching a certain number of iterations or the improvement over iterations becomes very small).

Stopping Condition?
Generate a random population of popSize chromosomes Select CHs for each chromosome such that each IoT device is associated with a cluster.

Jamming-aware UAV routing and IoT devices clustering algorithm (JA-RC)
In this subsection, we propose a jamming-aware genetic algorithm for UAV trajectory planning and IoT device clustering. Based on the location of the jammer, the IoT devices are clustered and the CHs are selected such that the UAV is able to receive the messages from the CHs when the UAV hovers above them. Our proposed algorithm is based on the concepts of the genetic algorithms. The population consists of popSi ze chromosomes, and each chromosome is represented by a vector of IoT devices' indices with a certain order. Figure 8 shows the flowchart of the JA-RC algorithm (Algorithm 1). First, the JA-RC algorithm starts by initializing a random population of size popSi ze chromosomes. Then, certain genes in each chromosome are selected to be CHs and each CH is associated with certain IoT devices located within the distance . After selecting the CHs for each chromosome, the cost of each chromosome is calculated using a fitness function, Eq. (57), that we will describe below. Then, we set the cost of the chromosome to infinity when we find that one or more CHs in the chromosome suffer from harmful interference. This step aims in eliminating the selection of the solution that is not feasible. After that, we find the chromosome that has the lowest cost and set it to be the best current solution. Finally, Algorithm 2 is used to perform selection, crossover and mutation operations. Once the stopping condition is met, Algorithm 1 terminates. Otherwise, Algorithm 1 iterates until the stopping condition is met. After each iteration, Algorithm 1 derives new solutions and tests them to discover new candidate solutions. Figure 9 shows the flowchart of Algorithm 2 that is used by Algorithm 1 to perform selection, crossover and mutation operations. Algorithm 2 starts by shuffling the population randomly. The goal of this step is to improve the chance of discovering a better solution. Then, each 4 consequent chromosomes in the population is grouped in one group. Consequently, a pair of chromosomes in each group are selected and crossover operations are performed over them. In addition, mutation operations are performed between chromosomes within each group. Finally, we get a new modified population of chromosomes that can be used by Algorithm 1 to discover more solutions.
Let P O P be a matrix of size popSi ze × |I |, where each row represents a certain chromosome. In addition, the binary matrix P O Pch of size popSi ze × |I | represent the CHs of each chromosome in the population. In other words, the indices associated with the ones in row p of the matrix P O Pch represent the CHs when chromosome p is selected.
Let p be a vector containing the cluster heads that the UAV needs to visit in order when chromosome p is selected from the population. To evaluate the solution of each chromosome p, the following Faintness Function F F( p) is used in our algorithm: where d α l p (1) is the distance from the initial location of the UAV (α) to the first CH in the vector p , d l p (i) l p (i+1) is the distance between the i th CH and the (i + 1) th CH in the vector p , and d l | p | β is the distance between the last CH in p and the final location of the UAV (β).

4:
Select the first cluster head, C H, for population p, where C H = P O P( p, 1).

5:
Set the first cluster head for population p to be C H, P O Pch( p, 1) = C H. 6: Let r be the distance between C H and P O P( p, 2). 7: for (m = 2 to |I |) do 8: Let d be the distance between C H and P O P( p, m). 9: if (d ≤ r ) And (d ≤ ) then 10: Add the IoT device associated with index m to the recently created cluster. 11: else 12: if (m = |I |) then 13: Create a new cluster with a cluster head C H = P O P( p, m). 14: P O Pch( p, m) = C H.

15:
Set r to the value of the distance between C H and P O P( p, m + 1). 16 Solve Tournament Selection, Crossover and Mutation Algorithm (Algorithm 2). 35: end for Algorithm 1 shows the required steps of Jamming-Aware UAV Routing and IoT Devices Clustering Algorithm (JA-RC). The maximum number of iterations of Algorithm 1 is Max I ter, and the population size is popSi ze. First, we initialize the minimum cost, MinCost, among all chromosomes in the population, as shown in step 3. In steps 4-5, the IoT device associated with the first index in chromosome p is selected as a CH for the first cluster. Then, we set r in step 6 to the distance between the first selected CH in chromosome p to the IoT device associated with index 2 of chromosome p. In steps 7-22, we check the remaining IoT devices in chromosome p and decide whether to include the IoT device to an already existing cluster or make it a CH to a new cluster.
In step 8, we calculate the distance, d, between the recently selected CH and the m th IoT device in chromosome p. If the distance d ≤ r and d ≤ , then include the m th IoT device in chromosome p to the recently created cluster. Otherwise, create a new cluster and make the m th IoT device in chromosome p a CH as shown in steps 12-20. In Step 23, we create a list of CHs for the p th chromosome, p . In steps 24-28, we check the feasibility of the selected solution then calculate the fitness function accordingly. If there is a CH in p such that the UAV cannot successfully receive the message from becuase the jamming interference, then the solution of chromosome p is not feasible and the cost of the solution is ∞, i.e., T otalCost( p) = ∞. Otherwise, T otalCost( p) is calulated based on the fitness function F F( p) defined in Eq. (57).
After deriving the cost of each candidate solution in the population, we find the best solution, Best Solution, among all derived solutions, as shown in steps 30-33. Then, the chromosomes in the population are modified to discover more solutions in the next iterations. We use Algorithm 2 to select chromosomes and perform crossover and mutation operations. Then, Algorithm 1 repeaters its steps 2-34 iteratively to search for a better solution after getting a new generation for the population.

Algorithm 2 Tournament Selection, Crossover and Mutation Algorithm
1: Shuffle the population randomly, i.e., shuffle the rows of the matrix P O P randomly. 2: Group each 4 consequent rows in the population P O P into a group. 3: for each grouped rows, g, in the population do 4: Select two random integer numbers, a and b, such that a < b ≤ |I |.

5:
Select two chromosomes from g randomly, and perform order crossover [36] operations for the genes indexed from a to b. 6: In the first row of g, perform a circular shift for the elements of the row from index a to index b. 7: In the second row of g, replace the element in index a with the element in index b, and vice versa. 8: In the third row of g, flip the subvector of the elements from a to b. 9: Keep the fourth row as is, then replace the original 4 rows in the population matrix, P O P, with these mutated rows. 10: end for Algorithm 2 shows how we get a new generation of chromosomes. In step 1, the rows (i.e., chromosome) in the population matrix (P O P) are shuffled randomly. Then, we divide in step 2 the rows of the P O P matrix into groups of four rows, i.e., the number of groups are popSi ze on two randomly selected chromosomes in group g. We select two integer numbers a and b randomly such that a < b, then we perform an order crossover operation the genes indexed from index a to index b. The order crossover makes sure that no repeated IoT device indices appear in the child chromosome. We perform order crossover rather than the typical crossover operation to make sure that each chromosome does not contain duplicate elements. When the chromosome contains duplicate IoT device indices, the resulting clustering may miss some IoT devices. Hence, it may provide an infeasible solution.
In steps 6-7, Algorithm 2 performs mutation operations over each group g of chromosomes. The algorithm performs circular shift, element replacement and flipping the elements for the indices between a and b as shown in step 6, 7 and 8, respectively. The fourth line of the group g is kept without a modification. The order crossover and mutation operations are performed over all popSi ze 4 groups to create a new generation of chromosomes. Then Algorithm 1 utilizes the new generation of chromosomes to search for a better solution.

Simulation results
We consider in our simulations an area of size 1000 m × 1000 m. This area is gridded using two scales: 1) Sparse grid and 2) Dense grid. We divide the area in the spare and dense grids into 5 × 5 and 10 × 10 possible locations, respectively. Then, the IoT devices are distributed over these locations randomly. We use the sparse grid in the simulation when we compare the optimal and our proposed algorithm to reduce the computational complexity. When the grid is dense, the number of possible locations (also the number of variables) will be higher. Hence, deriving the optimal solution may not be possible. We use the dense grid to further explore the proposed algorithm when the scale of the problem is larger. In this section, we run the simulation for 30 random scenarios and calculate the average value for each calculated result. Unless specified otherwise, the simulation parameters are shown in Table 4.
We compute the optimal solution using CPLEX solver [37] over General Algebraic Modeling System (GAMS) [38]. Since our optimization problem is in the form of Integer Linear Programming, CPLEX solver utilizes branch-and-cut search to derive the solution [39]. Branch-and-cut is a method for solving Integer Programs using Branch and Bound algorithm and cutting plane [40]. It is shown that CPLEX can provide the optimal solution when it is used to solve the Integer Linear Programming problems [39].
In addition to comparing our proposed algorithm (JA-RC algorithm) with the optimal solution, we aim to compare it with other benchmarks to get more insight about the performance. As discussed in subsection 1.1, none of the existing-related works provides a solution for the problem of data collection in the IoT using a UAV and in the presence of a jamming attack. Hence, we cannot compare the JA-RC algorithm with another one that solves the same problem. However, we can compare the JA-RC algorithm with the performance of the traditional Genetic algorithm with no clustering to study the effect of the joint clustering and UAV trajectory design used by our algorithm. Moreover, we compare the performance of the JA-RC algorithm with another algorithm based on k-means clustering [41] and the traditional Genetic algorithm. We call this algorithm min k-means and Genetic Algorithm, as described in Fig. 10. Figure 10 shows that min k-means and Genetic Algorithm stars by deriving the minimum number of clusters, min_c, using k-means clustering such that the diameter of all clusters is not greater than . This can be done by incrementally increasing the number of k-mean clusters until we reach a point, where all clusters have distances not greater than . Then, we run k-means clustering algorithm with min_c clusters and select the CHs to be the IoT devices closest to the centroids of the clusters. Finally, the traditional Genetic algorithm is used to solve the Travelling Salesman Problem for visiting the CHs while minimizing the UAV flight time.
In Fig. 11, we present the solution of JA-RC algorithm and compare it with three benchmarks: 1) The optimal solution, 2) min k-means and Genetic Algorithm and 3) Genetic Algorithm without clustering. As the number of IoT devices increases, the number of required clusters increases, Find the minimum number of clusters, min_c, using kmeans clustering such that the diameter of each cluster is not greater than ϵ.
Cluster the IoT devices into min_c clusters using k-means clustering.

Start
End Set the CH of each cluster to be the IoT device closest to the centroid of the cluster.
Derive the UAV flying trajectory by solving the Travelling Salesman Problem using Genetic Algorithm. Time (number of slots)

JA-RC Algorithm Performance
Optimal JA-RC Algorithm min k-means + GA No clustering GA Fig. 11 Optimal vs. JA-RC algorithms' solutions as depicted in Fig. 12. The reason is that the CH can include only the IoT devices within its cluster radius, which is 250 m ( = 250 m). Hence, the probability of having more clusters increases as the number of IoT devices increases, given that the IoT devices are distributed randomly. Since the UAV needs to visit more cluster heads as the number of IoT devices increases, Fig. 11 presents that the total required time slots is increasing as we increase the number of ioT devices. On the other hand, Fig. 11 shows that the JA-RC algorithm achieves a close performance to the optimal solution, where the gap is within 10%. Compared with min k-means and Genetic algorithm and Genetic algorithm without clustering, JA-RC algorithm significantly reduces the total number of time slots required by the UAV to complete its task. Hence, joint clustering and UAV path planning results in a better performance compared with optimizing only the UAV path without clus- tering and disjoint optimization for the UAV path planning and clustering. Figure 13 presents the performance of our proposed algorithm when the scale of the problem is larger. A larger scale for the problem implies larger numbers of IoT devices and their possible locations. It is showing that the clustering technique significantly reduces the total number of time slots needed by the UAV to complete its task. Without clustering, the UAV may not be able to successfully receive messages from some IoT devices suffering from jamming. Hence, clustering technique is important in mitigating the effect of the jammer by relaying the messages of jammed IoT devices to CHs that are able to relay their messages to the UAV. Hence, Fig. 13 shows that both JA-RC algorithm and min kmeans and Genetic Algorithm significantly outperform the Genetic algorithm that does not consider clustering. On the other hand, min k-means and Genetic Algorithm sequentially optimizes the UAV trajectory after minimizing the number of required clusters. In contrast with min k-means and Genetic Algorithm, JA-RC algorithm jointly optimizes the number of clusters and UAV trajectory. Therefore, Fig. 13 shows that the JA-RC algorithm outperforms min k-means and Genetic Algorithm and results in a fewer number of required time slots. Figure 13 shows that the JA-RC algorithm outperforms min k-means and Genetic Algorithm. However, we may need to perform a statistical test to ensure the superiority of the JA-RC algorithm over min k-means and Genetic Algorithm. To perform the statistical test, we use the Wilcoxon rank sum test [42] which is a nonparametric test for two populations with independent samples. The Wilcoxon rank sum test is computed using MATLAB statistical toolbox [43]. We used the MATLAB function ranksum, with a confidence level of 95%; The null hypothesis is that the independent sample results of JA-RC algorithm and min k-means and Genetic Algorithm of 35 randomly generated scenarios with equal median. The function returns the p-value and h, where h = 0 when there is no significant difference between the two samples and h = 1 otherwise. Accordingly, h = 0 when the p-value is greater than or equal to the significance level, where the significance level is 0.05. Table 5 presents the statistical test result after performing the Wilcoxon rank sum test. We repeated the test over different network sizes ranging from 10 IoT devices to 70 IoT devices. It is shown that the null hypothesis of equal medians at the 5% significance level is rejected, since h = 1 in Table 5. The zval in Table 5 represents the p-value calculated using a normal approximation of the normal statistics, and it is used when the sample size is large. From Table 5, JA-RC algorithm provides a superior performance compared with min k-means and Genetic Algorithm. Table 6 gives information about the computational time of solving the optimization problem when it is solved optimally and when the JA-RC algorithm is used to provide a heuristic solution. We run our simulation on a computer equipped with Intel(R) Core(TM) i7-7500U processor with 2.70 GHz base frequency and 8 GB of RAM memory. In the small and large networks, we consider sparse and dense grids for the possible locations for the IoT devices, respectively. Moreover, we consider 20 and 70 IoT devices in the small and large networks, respectively. When the network scale is small, the JA-RC algorithm reduces the required time to derive the solution significantly. On the other hand, deriving the optimal solution when the network is large is computational heavy and cannot be found in a reasonable time. However, the JA-RC algorithm can efficiently find a solution for our problem when the network is large. In other words, the JA-RC algorithm is scalable and can provide a solution even when the number of variables is large. Figures 14 and 15 investigate the effect of the cluster radius on the objective function and the number of clusters, respectively. A larger radius allows the CH of the cluster to serve more IoT devices. Hence, the required number of clusters will be smaller, as shown in Fig. 15, and the average number of served IoT devices per cluster will be larger. For example, the average number of served IoT devices per cluster is 70 5 and 70 16 when the cluster radius is 400 and 200, respectively, when the number of IoT devices is 70. There-  On the other hand, Figs. 14 and 15 show how many time slots and clusters, respectively, are required as we increase the number of served IoT devices. Figure 15 indicates that having more IoT devices results in more required clusters. Hence, the UAV needs to visit more CHs to collect the data from them. Moreover, the UAV will take more flying time as we have more CHs to be visited, as shown in Fig. 14. Interestingly, it is shown from these two figures that the number of clusters, and consequently the number of time slots, increases significantly as we reduce value from 200 to 300. Therefore, the radius of the cluster should be selected carefully based on the size of the served area, density of the IoT devices and transmission ranges of the IoT devices. Figure 16 investigates the effect of γ (SINR threshold for the received signal from the CH to the UAV) on the UAV flying time while considering different numbers of ioT devices. It is shown that the flight time of the UAV increases by increasing the threshold γ . The reason is that increasing the threshold γ means more restricted flying area for the UAV. Consequently, the UAV may incur a longer flying trajectory to avoid the area under more jamming. Therefore, the UAV flying time increases by increasing the flying trajectory length given that the UAV speed is fixed. In other words, reducing the threshold γ gives the UAV more flexibility in designing a shorter routing trajectory that results in less flying time. Figure 17 shows how varying the jammer's transmission power affects the flight time of the UAV. When P J = 0, then the jammer is not transmitting and the flight time of the UAV should be the minimum. As the value of P J increases, Fig. 17 presents how the flying time is affected when the number of served IoT devices ranges from 50 to 70. When the number of IoT devices is higher, the impact of the jamming signal is larger. The reason is that the jamming signal generally will affect more IoT devices as the density of total IoT devices distributed over the serving area is larger. Hence, we may require having more CHs distributed close to the edge of the footprint of the jammer's transmission to collect data from the IoT devices nearby the jammer. Then, the UAV may incur a longer flying trajectory to avoid collecting data from IoT devices severely affected by the jamming signal, as shown in Fig. 7. Hence, the UAV needs more time slots to complete its task.

Conclusion
This paper investigates the problem of UAV trajectory design and IoT devices clustering in presence of a malicious jammer. The goal is to successfully collect data from ground IoT devices using a UAV and mitigate the interference caused by the jammer. To eliminate the effect of the jammer and to accelerate data collection, the IoT devices are clustered based on their locations and location of the jammer, then the UAV collects the data only from the CHs. We modeled the problem mathematically as an ILP program and proposed a Genetic-based algorithm to solve the problem in a more efficient way. We studied the performance of the proposed algorithm and compared it with the optimal solution. In addition, we showed how the number of IoT devices, cluster size, the SINR threshold and transmission power on the UAV flight time.