# An Integrated DQN and RF Packet Routing Framework for the V2X Network
## 3 Design of the IDRF System
### Offline Phase
#### 3.1.1 Correction Unit for Correcting the Vehicle Trajectory Data  
Visualization of the vehicle trajectory data from Figure 7 into a 2D format (Figure 9) reveals that, due to GPS positioning issues, the reported latitudes and longitudes from  
Figure 8: The modified trajectory information.  
Figure 7: The Beijing city map used (yellow dots are intersections).  
the vehicles may not accurately align with the actual roads. Furthermore, the trajectory data may not include vehicle passing intersections, causing inaccurate decision-making regarding the original actual vehicle trajectories, leading to packet forwarding failures. The literature has four approaches to the correction of vehicle trajectory data [28; 29; 30; 31]. Most approaches require relevant real-time information from other reference stations or sensors to correct GPS locations and cannot be applied to the offline phase of the proposed IDRF. Therefore, in this study, vehicle trajectory data were corrected by calibrating known GPS trajectory information using accurate map data [28]. By identifying the parts of the trajectory that best match the roads or features on the map, the positions of the historical GPS trajectory can be adjusted before training the AI model. In the following text, we present a series of corrections to the vehicle trajectories through the vehicle trajectory continuity algorithm. First, the distance between two intersections of a road segment and the offset distance of the recorded vehicle coordinates away from the actual road segment are calculated. Then, the Haversine formula [32] is employed to compute the perpendicular distance between the recorded vehicle coordinates and the road segment. It is necessary to find the vertical coordinate points perpendicular to the road segments during the correction process.  
During the correction process, there may be a few instances where a vehicle's coordinates coincidentally have equal perpendicular distances to two road segments. In such cases, we refer to the preceding trajectory information, denoted as \(T_{i}^{1}\), and the subsequent trajectory information, denoted as \(T_{i+2}^{1}\). Based on the vehicle's serial number, trajectory update timestamp (constrained within a 5-min window), and the road segments on which the vehicle is situated at \(T_{i}^{1}\) and \(T_{i+2}^{1}\), the correction unit can determine which road segment is correct. If discontinuity between road segments is found in the actual vehicle trajectory, the correction unit randomly selects one of the two road segments, and the selected segment is then designated as the corresponding trajectory segment. As illustrated in Figure 10, assume vehicle \(v_{1}\) with the \(i\)th trajectory point \(T_{i}^{1}\) is located on road segment 5. During the correction process \(T_{i+1}^{1}\), if \(T_{i+1}^{1}\) has an identical distance to road segments 6 and 9 and \(T_{i+2}^{1}\) is located on road segment 10, the correction unit can determine that the coordinates of \(T_{i+1}^{1}\) should be on road segment 9. If the time difference between two adjacent trajectory points, such as \(T_{i+2}^{1}\) and \(T_{i+3}^{1}\), exceeds 5 min, there is no need to compute the continuity between them.  
Figure 9: Visualization of vehicle trajectory data from Beijing city (the red points represent the trajectory data, and different shades of orange represent varying densities of vehicle trajectory data).