# Rendezvous Based Adaptive Path Construction for Mobile Sink in WSNs Using Fuzzy Logic
## 4 Proposed Approach
### Updating the RPs Locations
Sensor node \(j\) will then attract RP \(i\) to its location and calculate its new position (\(X_{RPi-j}\), \(Y_{RPi-j}\)) after calculating its weight value \(w_{j}\) using the FIS as follows:  
\[X_{RPi-j}=w_{j}\times(X_{j}-X_{RPi})+X_{j} \tag{6}\]  
\[Y_{RPi-j}=w_{j}\times(Y_{j}-Y_{RPi})+Y_{j} \tag{7}\]  
The actual new updated position of RP \(i\) is based on all sensor nodes that are associated with RP \(i\), and it is calculated as:  
\[X_{RPi}^{New}=\frac{\sum\limits_{j=1}^{|S_{j}|}X_{RPi-j}}{|S_{j}|} \tag{8}\]  
\[Y_{RPi}^{New}=\frac{\sum\limits_{j=1}^{|S_{j}|}X_{RPi-j}}{|S_{j}|} \tag{9}\]  
where \(|Sj|\) represents the total number of sensor nodes associated with RP \(i\). After the locations of the RPs are updated, the MS constructs the adaptive path that passes through the new RPs set using Traveling Sales Man Problem Algorithm. Based on the new set of RPs, the mobile sink updates the corresponding RP of each sensor based on the nearest distance between each sensor with the new corresponding RP. When the mobile sink is  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline \multirow{2}{*}{**Rule**} & \multicolumn{3}{c}{**Inputs**} & \multirow{2}{*}{**Output**} \\ \cline{2-2} \cline{4-4}
**Number** & & & & **Input** \\ \hline
1 & Near & Low & Low & Average \\
2 & Near & Low & Average & Large \\
3 & Near & Low & High & Very Large \\
4 & Middle & Low & Low & Average \\
5 & Middle & Low & Average & Large \\  
about to reach an RP, it broadcasts a new polling message to the corresponding sensors with the ID of the new respective RP. Therefore, the sensors based on the polling message prepare the data and transmit it to the MS when it stops at the RP. Once the MS finishes the collection of the data from all corresponding sensor nodes, it moves to the next RP and repeats the process until it passes the whole set of RPs. Algorithm 2 presents the steps for updating the RPs' locations using FIS. ```
INPUT: \(S\), \(C\), \(U\) /* U is the period value to update the path */ /* C is the set of RPs that are used to build the MS path */ /* S is the set of sensor nodes */  OUTPUT: updated path for MS
1: BeginFUZZY_RPs
2: Round = 1; /* current round of collection data */
3:while there is still active nodes AND (mod(Round, U) = 1) OR Round = 1)do
4:for j = 1 to sizeof(\(S\))do
5: Determine the Nearest Corresponding RP of sensor s\({}_{j}\)
6: Discover number of the One-Hop nodes of sensor s\({}_{j}\)
7:Endfor
8:for i = 1 to sizeof(\(C\))do
9: RP\({}_{i}\) = C
10:for each sensor s\({}_{j}\) associated with RP\({}_{i}\)do
11:\(w_{j}\) =FIS [energy(s\({}_{j}\)), dist(s\({}_{i}\) to RP\({}_{i}\)), Num of one Hop nodes (s\({}_{j}\))
12: Calculate XRP\({}_{i\to j}\) using Equation (6)
13: Calculate YRP\({}_{i\to j}\) using Equation (7)
14:Endfor
15: New X of RPi = Calculate New XRPi using Equation. (8)
16: New Y of RPi Calculate New YRPi using Equation (9)
17: Endfor
18: Round = Round + 1
19:Endwhile
20: Use TSP algorithm [25] to construct the path that passes through the RPs in C
21:End
```  
**Algorithm 2**Fuzzy-based Adaptive Path Selection