## 4 Mobility Model of the MS
### Optimization Method
To do so, CH calculates the cosine of the angle between the vector from \(CH_{i}\) to \(CM_{k}\) (vector \(\vec{d^{\prime}}_{k}\)) and the vector from the current \(CH_{i}\) to the next \(CH_{j}\) (vector \(\vec{u}\), see Figure 6). If the cosine angle is greater than 0, then the \(CM_{k}\) is in the same direction of MS trajectory. Otherwise, the \(CM_{k}\) is not in the same direction of the MS trajectory. The cosine angle between the vectors \(\vec{u}\) and \(\vec{d^{\prime}}_{k}\) in Equation (4):

\[\cos\alpha=\frac{\vec{u}\cdot\vec{d^{\prime}}_{k}}{\left\|\vec{u}\right\| \cdot\left\|\vec{d^{\prime}}_{k}\right\|} \tag{4}\]

where \(\vec{u}=\left( \begin{array}{c}x_{CH_{j}}-x_{CH_{i}}\\ y_{CH_{j}}-y_{CH_{i}}\end{array} \right)\), \(\vec{d^{\prime}}_{k}=\left( \begin{array}{c}x_{CM_{k}}-x_{CH_{i}}\\ y_{CM_{k}}-y_{CH_{i}}\end{array} \right)\) and \(\vec{u}\cdot\vec{d^{\prime}}_{k}\) is the dot product or scalar product of vectors \(\vec{u}\) and \(\vec{d^{\prime}}_{k}\). \(\left\|\vec{u}\right\|\) and \(\left\|\vec{d^{\prime}}_{k}\right\|\) are the length of vectors \(\vec{u}\) and \(\vec{d^{\prime}}_{k}\) in Equations (5) and (6):

where:

\[\left\|\vec{u}\right\|=\sqrt{\left(x_{CH_{j}}-x_{CH_{i}}\right)^{2}+\left(y_{ CH_{j}}-y_{CH_{i}}\right)^{2}} \tag{5}\]

\[\left\|\vec{d^{\prime}}_{k}\right\|=\sqrt{\left(x_{CM_{k}}-x_{CH_{i}}\right)^ {2}+\left(y_{CM_{k}}-y_{CH_{i}}\right)^{2}} \tag{6}\]

The result of Equation (4):

\[\cos\alpha\left\{ \begin{array}{ll}>0,&\quad\mbox{the CM is in the same direction as the MS}.\\ \leq 0,&\quad\mbox{the CM is not in the same direction as the MS}.\\ \end{array} \right.\]

(2) Distance between CMs and MS's trajectory line

After selecting all the CMs which are in the same direction of the sink trajectory, CH finds the closest CM to the MS trajectory line. To find the distance between \(CM_{k}\). and the MS trajectory line, we need to find the line equation of the trajectory then calculate the distance between CMs and trajectory line. CH determines the equation of the MS trajectory using its coordinates (current CH coordinates) and the coordinates of the next destination (next CH coordinates to visit, CH gets this information from the ALLOW_SENDING packet). The trajectory line equation of the MS from a cluster head \(i\) (\(CH_{i}\)) to a cluster head \(j\) (\(CH_{j}\)) is defined in Equation (7):

\[y=m_{ij}x+b_{ij} \tag{7}\]where \(m_{ij}\) is the slope between \(CH_{i}\Big{(}x_{CH_{i}},y_{CH_{i}}\Big{)}\) and \(CH_{j}\Big{(}x_{CH_{j}},y_{CH_{j}}\Big{)}\). \(m_{ij}\) is calculated in Equation (8):

\[m_{ij}=\frac{y_{CH_{j}}-y_{CH_{i}}}{x_{CH_{j}}-x_{CH_{i}}} \tag{8}\]

In some cases, the two cluster heads \(CH_{i}\) and \(CH_{j}\) have the same \(x\) coordinates, i.e., \(x_{CH_{j}}-x_{CH_{i}}=0\) then \(m_{ij}\) is undefined. In this case, Equation (7) becomes as follows:

\[\left\{ \begin{array}{c}y=m_{ij}x+b_{ij},\ if\ x_{CH_{j}}\
eq x_{CH_{i}}\\ x=x_{CH_{j}}\ or\ x=x_{CH_{i}},\ if\ x_{CH_{j}}=x_{CH_{i}}\end{array} \right.\]

\(b_{ij}\) is determined after \(m_{ij}\) is calculated in Equation (7) and using the coordinates of \(CH_{i}\). \(b_{ij}\) is calculated in Equation (9):

\[b_{ij}= y_{CH_{i}}-m_{ij}x_{CH_{i}} \tag{9}\]

The distance \(d_{k}\) is the distance from a \(CM_{k}\) to the trajectory line of the MS. This distance is calculated in Equation (10):

\[d_{k}=\frac{\left|ax_{CM_{k}}+by_{CM_{k}}+c\right|}{\sqrt{a^{2}+b^{2}}} \tag{10}\]

where:

\[a=m_{ij}^{-1}m_{ij} \tag{11}\]

\[b=-m_{ij}^{-1} \tag{12}\]

Also:

\[c=m_{ij}^{-1}b_{ij} \tag{13}\]

With \(m_{ij}^{-1}\) in Equation (11), is the inverse of \(m_{ij}\) thus, \(m_{ij}^{-1}\) is calculated from Equation (8) in Equation (14):

\[m_{ij}^{-1}=\frac{x_{CH_{j}}-x_{CH_{i}}}{y_{CH_{j}}-y_{CH_{i}}} \tag{14}\]

Therefore \(a\) in Equation (11) is, \(a=1\).