## 5 Proposed Method
### Routing Algorithm at Intersection Level
\begin{table}
\begin{tabular}{c c c c c} \hline \hline  & \multicolumn{3}{c}{**Fuzzy System Inputs**} & \multicolumn{1}{c}{**Fuzzy System Output**} \\ \hline
**Fuzzy Rules** & \(d_{i,target}\) & \(Q_{i}\) & \(CQ_{i,prev-hop}\) & \(S_{i}\) \\ \hline
1 & Low & Low & Low & High \\ \hline
2 & Low & Low & Medium & Very high \\ \hline
3 & Low & Low & High & Externely high \\ \hline
4 & Low & Medium & Low & Medium \\ \hline
5 & Low & Medium & Medium & High \\ \hline
6 & Low & Medium & High & Very high \\ \hline
7 & Low & High & Low & Low \\ \hline
8 & Low & High & Medium & Medium \\ \hline
9 & Low & High & High & High \\ \hline
10 & Medium & Low & Low & Medium \\ \hline
11 & Medium & Low & Medium & High \\ \hline
12 & Medium & Low & High & Very high \\ \hline
13 & Medium & Medium & Low & Low \\ \hline
14 & Medium & Medium & Medium & Medium \\ \hline
15 & Medium & Medium & High & High \\ \hline
16 & Medium & High & Low & Very low \\ \hline
17 & Medium & High & Medium & Low \\ \hline
18 & Medium & High & High & Medium \\ \hline
19 & High & Low & Low & Low \\ \hline
20 & High & Low & Medium & Medium \\ \hline
21 & High & Low & High & High \\ \hline
22 & High & Medium & Low & Very low \\ \hline
23 & High & Medium & Medium & Low \\ \hline
24 & High & Medium & High & Medium \\ \hline
25 & High & High & Low & Externely low \\ \hline
26 & High & High & Medium & Very low \\ \hline
27 & High & High & High & Low \\ \hline \end{tabular}
\end{table} 
Table 4: Fuzzy rule base in proposed fuzzy system. ```
1:\(Vehicle_{S}\): Source vehicle or intermediate node
2:\(Intersect_{S}\): Source intersection
3:\(Vehicle_{D}\): Destination vehicle
4:Next-hop node
5:Begin
6:if\(Vehicle_{S}\) and \(Vehicle_{D}\) are on the same road section then
7:\(P_{Target}=Vehicle_{D}\);
8:elseif\(Vehicle_{S}\) is the source node then
9:\(P_{Target}=Intersect_{S}\);
10:elseif\(Vehicle_{S}\) is the intermediate node then
11:\(P_{Target}=Intersect_{f}^{+1}\) that is obtained using Algorithm 2;
12:endif
13:\(Vehicle_{S}\): Choose the nearest next-hop node to \(Target\) from its \(Table_{neighbor}\);
14:if\(Vehicle_{S}\) cannot find the nearest next-hop node then
15:\(Vehicle_{S}\): Calculate \(S_{i}\) for all neighbors based on \(d_{i,target}\), \(Q_{i}\), \(CQ_{i,prev-hop}\) using a fuzzy system;
16:\(Vehicle_{S}\): Choose the vehicle with maximum \(S_{i}\) as the relay node;
17:endif
18:\(Vehicle_{S}\): Transmit the packet to the relay vehicle; End
```

**Algorithm 3** V2V routing process

#### 5.3.3 Vehicle-to-Infrastructure (V2I) Routing Algorithm

In QFHR, when choosing the next-hop node in a road section, each vehicle uses a greedy routing technique for transferring packets to the intersection area. Then, RSU selects the next intersection by searching in Q-table calculated in the I2I routing algorithm described in Section 5.2. At this step, each RSU employs a greedy strategy to send packets to the related road section. In this case, there are two modes:

* **First mode:**\(Vehicle_{D}\) moves in this road section. In this case, \(Vehicle_{D}\) is determined as a target point (\(P_{Target}\)). * **Second mode:**\(Vehicle_{D}\) does not move in this road section. In this case, the next intersection is considered as \(P_{Target}\). Now, RSU checks its neighbor table to determine whether \(P_{Target}\) is its neighbor or not. If \(P_{Target}\) is in its neighbor table, the data packet is sent to \(P_{Target}\) directly. Otherwise, RSU finds the vehicle closest to \(P_{Target}\) in its neighbor table and transfers the packet to it. If RSU fails to find a vehicle to send the data packet, RSU stores this packet until it discovers the next-hop vehicle.