# Gathering Big Data in Wireless Sensor Networks by Drone +
## 6 Algorithm for Big Data Gathering during Drone Movement
### The Algorithm to Create the Subsets  
A tour \(P\) created by Incremental or Decremental heuristic is a sequence of hovering points. We named as a _path_, part of the tour between two consecutive hovering points. Each tour has \(|P|+2\) paths among its hovering points since the drone always starts flying from the initial point \(p_{0}=0,0\) and always returns to the initial point. Consequently, the proposed algorithm creates \(|P|+2\) subsets of sensor nodes. It uses the Equations (4) and (5) to verify if each sensor node is in every subset. Algorithm 3 presents the pseudocode to define how the proposed algorithm works.  
```
1:procedureCreateSubsets(\(P\),\(S\),\(d_{\mathit{goal}}\),\(b\),\(m\),\(r\))
2:\(\mathit{trs}=MinDist(d_{\mathit{agent}},b,m,r)\)
3:\(\mathit{Paths}\longleftarrow\{p_{0}\}+P+\{p_{0}\}\)
4:\(\mathit{CG}\longleftarrow\mathit{SpanningTrave(P,S)}\)
5:\(D_{\mathit{move}}\longleftarrow\oslashash\)
6:\(T_{\mathit{moving}}\longleftarrow 0\)
7:\(i=0\)
8:for\(i<|\mathit{Paths}|\)do
9:\(d_{(i\in i+1)}\longleftarrow\oslash\)
10:\(u\gets 0\)
11:for\(i<|S|-1\)do
12:if\(DS(\mathit{Paths}_{i},\mathit{Paths}_{i+1:s},\mathit{s}_{u},r)\geq\mathit{ trs}\)then
13:if\(s_{u}\
otin D_{\mathit{move}}\)then
14:\(d_{(i\in i+1)}\longleftarrow s_{u}\)
15:endif
16:endif
17:endfor
18:\(D_{\mathit{move}}\longleftarrow D_{\mathit{move}}\cup\mathit{OverlappingNodes }(d_{(i\in i+1)},\mathit{CG})\)
19:endfor
20:\(T_{\mathit{moving}}\longleftarrow CalcTmove(D_{\mathit{move}},\mathit{CG})\)
21:\(\mathit{show}(D_{\mathit{move}},T_{\mathit{moving}})\)
22:endprocedure
```  
**Algorithm 3** Gathering Big Data During Drone Movement.  
Figure 9: Verifying if a node \(s_{i}\) can send data to drone flying between the hovering points \(p_{1}\) and \(p_{2}\).  
Algorithm 3 receives as parameters a tour \(P\), the set \(S\) with the locations of all sensor nodes, the drone speed _dspeed_, the network bandwidth \(b\), the amount of data stored in the memory of each sensor node \(m\), and the sensor nodes radio range \(r\), the same as the drone. The line 2 calculates a threshold (\(trs\)) that is the minimal distance the drone has to fly inside the area covered by the radio of a sensor node to receive data from it. The function \(MinDist()\) works according to Equation (5). In line 3, the variable _Paths_ receives the tour \(P\) with the initial point \(p_{0}\) at the beginning and at the end, in order to represent the entire drone trip. The Connecting Graph is created by the _SpanningTree\(()\)_ function in line 4. \(D_{mow}\) is initialized in line 5. It is the set of subsets of nodes that send data to drone when it is moving. The variables \(T_{moving}\) and \(i\) are initialized in lines 6 and 7, respectively.  
From line 8 to 19, there is a loop that takes separately each pair of consecutive hovering points in _Paths_. From line 11 to 17, the loop takes separately each sensor nodes. In line 12, it checks if the drone will fly at least \(trs\) meters inside the radio range of the sensor node. In line 13, it verifies if this sensor node already is in one of the subsets of \(D_{mow}\). If not, in line 14, this sensor node is added to the set that will send data to the drone between the points _Paths_ and _Paths\({}_{i+1}\)_. In line 18, the algorithm searches for sensor nodes that are in the same coverage region. As only one sensor node can send data at a time, the procedure _OverlappingNodes\(()\)_ checks which sensor node will send data in each region of coverage. We describe this procedure in Section 6.2.1. In line 20, it calculates \(T_{moving}\), which is the time that will be removed from the collection time (\(T_{collecting}\)), according to Equation (2). The Section 6.2.2 describes how to calculate \(T_{moving}\). The result is shown in line 21.