## 5 Proposed Heuristic
### Stage I and II: Determining Sojourn Locations and RPs
#### 5.1.3 Sojourn Locations Selection
Since in our approach, it is assumed that the sojourn locations are some specific points that the mobile-sink stops to harvest data from the RPs, there will be three situations as follows:  
1. If there is only one RP in the periphery of the trajectory and this RP cannot contact with other RPs, then the mobile-sink considers the closest distance to the RP as sojourn location. 2. If there are two RPs which are in the communication range of each other, as shown in Figure 6, we should balance energy consumption among the RPs for data communication. To illustrate our solution, we follow the example in Figure 6 in which there are two RPs \(A\) and \(B\). The line \(\overline{SE}\) specifies the intersected trajectory that the sojourn location should be selected for covering the two RPs. To obtain the position that can balance energy consumption, we select the middle of \(\overline{SE}\) which is identified as \(M\). By comparing \(\overrightarrow{AM}\) with \(\overrightarrow{BM}\) the point \(M\) moves to the direction that has larger amount of energy consumption in the line \(\overline{SE}\). If \(\overrightarrow{AM}=\overrightarrow{BM}\) then we can obtain the optimal solution. And if in \(\overline{SE}\) we cannot obtain the optimal solution but obviously we can achieve to the most possible near optimal solution. 3. For the condition that there are more than two RPs in the periphery of the trajectory, we proposed Algorithm 2 that is described with details in the following. Figure 7 illustrates the situation in that there are more than two RPs in the periphery of the trajectory. Since the main task in the process of selecting the sojourn locations is to minimize the delay-time, in Algorithm 2, we concentrate on choosing a point that can cover all of the RPs which are in the communication range of each other. However, as shown in Figure 7, by selecting a sojourn location which can cover the RP \(C\), the RP \(A\) and/or the RP \(B\) cannot send data to that sojourn location. Therefore, it is essential to select at least one more sojourn location in that specific part of the trajectory. In Algorithm 2, we designed an effective method to select a set of appropriate sojourn locations. The input of the algorithm is a set of RPs \(\Delta=\{\delta_{1},...,\delta_{m}\}\) such that \(m\leq|S|\) and a set of sub-trajectories \(\Gamma=\{\gamma_{1},\gamma_{2},...,\gamma_{l}\}\) such that \(l\leq|\Delta|\) and each sub-trajectory is in the communication range of at least one RP (The mobile-sink can harvest all of the related information about RPs and sub-trajectories by completing one tour and then runs our algorithm to identify the set of sojourn locations). Lines 2-4 consider the condition in which there is only one RP in relation with a sub-trajectory. And Lines 5-13 address the situation in that there are only two RPs in corresponding with a sub-trajectory. And finally Lines 14-22 discusses about the existence of more than two RPs for a sub-trajectory. In Line 15 the function \(MaxPoint(\gamma_{i})\) finds the point(s) in the sub-trajectory \(\gamma_{i}\) that if the mobile-sink stands in that point(s), it can cover the maximum number of RPs. The function \(MaxLine(\gamma_{i})\) in Line 16 does the same process but it is for the situation to find a continues line in the sub-trajectory that covers the maximum number of RPs. Line 17 converts the continuous line from the previous step to one specific point with the condition for finding a point that minimizes total energy consumption for RPs to do data transformation and in case of equal values it considers the middle point. Between all of the candidate points in Line 18 the function \(MidPoint(\mathrm{Y})\) finds the middle point or the point which is closer to the real middle point in the sub-trajectory among the candidate sojourn points. Afterward, that point will be selected as the first sojourn location in the sub-trajectory. In Line 20 the function \(score()\) determines the score of other candidate sojourn locations based on the current selected sojourn location.