## 5 Proposed Method
### Identifying Traffic Conditions
#### 5.1.1 Calculating the Connection Quality of Two Vehicles  
In QFHR, the quality of the connection between \(Vehicle_{i}\) and \(Vehicle_{j}\), namely \(CQ_{i,j}\) is evaluated with regard to two factors, namely the connection time and the hello packet reception rate because the connection time indicates the stability of the link between the two nodes and the packet reception rate also evaluates their connection quality. It is difficult to calculate the connection quality because the nodes are mobile. In the proposed method, \(CQ_{i,j}\) is obtained from the weighted mean of two parameters, including the connection time of \(Vehicle_{i}\) and \(Vehicle_{j}\) (i.e., \(\lambda_{ij}\)) and the hello packet reception rate (i.e., \(\eta_{ij}\)) based on Equation (4):  
\[CQ_{i,j}=\frac{\omega_{1}\lambda_{ij}+(1-\omega_{1})\eta_{ij}}{\sum\limits_{ Vehicle_{j}\in Neighbor_{i}}\left(\omega_{1}\lambda_{ij}+(1- \omega_{1})\eta_{ij}\right)} \tag{4}\]  
So, \(Neighbor_{i}\) represents the neighbors of \(Vehicle_{i}\). Moreover, \(\omega_{1}\) is a weight coefficient and \(0\leq\omega_{1}\leq 1\). In the following, we demonstrate how to obtain the connection time (\(\lambda_{ij}\)) and the hello reception rate (\(\eta_{ij}\)). * **Connection time (\(\lambda_{ij}\)):*
* The connection time of \(Vehicle_{i}\) and \(Vehicle_{j}\) is evaluated by Equation (5): \[\lambda_{ij}=\frac{\left(\frac{R-d_{ij}}{\Delta V_{ij}}\right)}{T_{\max}}\] (5) where, \(R\) is the communication radius of vehicles, \(d_{ij}=\sqrt{\left(x_{i}-x_{j}\right)^{2}+\left(y_{i}-y_{j}\right)^{2}}\) is the Euclidean distance between the two vehicles and \(\Delta V_{ij}=\left|v_{i}-v_{j}\right|\) expresses the relative speed of \(Vehicle_{j}\) with regard to \(Vehicle_{i}\). Moreover, \((x_{i},y_{i})\) and \((x_{j},y_{j})\) represent the spatial coordinates of \(Vehicle_{i}\) and \(Vehicle_{j}\), respectively. In addition, \(v_{i}\) and \(v_{j}\) are their speed. \(T_{\max}\) is the maximum connection time, which is a fixed value determined based on the simulation time. To accurately estimate the connection time in the dynamic environment of VANET, two configuration coefficients are added to Equation (6). As a result: \[\lambda_{ij}=\frac{\left(\frac{R-\alpha_{1}d_{ij}}{\left|v_{i}-\alpha_{2}v_{j }\right|}\right)}{T_{\max}}\] (6) where, \(\alpha_{1}\) and \(\alpha_{2}\) are the configuration coefficients that are determined as follows:
* If \(Vehicle_{i}\) and \(Vehicle_{j}\) move at a similar direction (i.e., \(0\leq\Delta\theta_{ij}\leq\frac{\pi}{3}\), so that \(\Delta\theta_{ij}\) is the movement direction of \(Vehicle_{i}\) with regard to \(Vehicle_{i}\)), then \(\alpha_{2}=1\). Now if \(Vehicle_{i}\) is ahead of \(Vehicle_{j}\), then \(\alpha_{1}=1\). Otherwise, \(\alpha_{1}=-1\). See Figure 5.
* If \(Vehicle_{i}\) and \(Vehicle_{j}\) move in the opposite direction (i.e., \(\frac{2\pi}{3}\leq\Delta\theta_{ij}\leq\pi\)) then, \(\alpha_{2}=-1\). Now, if \(Vehicle_{i}\) approaches \(Vehicle_{j}\), then \(\alpha_{1}=-1\). Otherwise, \(\alpha_{1}=1\). See Figure 6.  
Figure 5: The movement of vehicles in the same direction (**a**) \(Vehicle_{i}\) is ahead of \(Vehicle_{j}\). (**b**) \(Vehicle_{i}\) is behind \(Vehicle_{j}\). In addition, \(\Delta\theta_{ij}\) is obtained from Equation (7):  
\[ \begin{split}&\Delta\theta_{ij}=\cos^{-1}\left(\frac{v_{x,j}v_{x,j}+v_{y,j}v_{y,j}}{\sqrt{\left(v_{x,j}\right)^{2}+\left(v_{y,j}\right)^{2}\times}\sqrt {\left(v_{x,j}\right)^{2}+\left(v_{y,j}\right)^{2}}}\right),\\ & 0\leq\Delta\theta_{ij}\leq\pi\end{split}  \tag{7}\]  
where \(\left(v_{x,i},v_{y,i}\right)\) and \(\left(v_{x,j},v_{y,j}\right)\) are the velocity vectors of \(Vehicle_{i}\) and \(Vehicle_{j}\), respectively. Then, each vehicle updates the connection time (\(\lambda_{ij}\)) using the approach of window mean with exponentially weighted moving average (WMEWMA). WMEWMA is an EWMA-based estimator that approximates the average value. It uses the linear combination of a limited exponentially weighed history [37; 38].