# Weight-Based PA-GPSR Protocol Improvement Method in VANET
## 4 Proposed Protocol
### The Overall Process of the Protocol  
The process of the W-PAGPSR is shown in Figure 7. The sender or source node was first sent to obtain the location information of the neighbor node through the OBU device and GPS, before sending a HELLO message and waiting for the node to respond. The next step was to calculate the Euclidean distance from each neighbor node to the destination node in the communication range to determine the reliable neighbor node. We then checked for routing voids. If they were present, we used the weight-based perimeter forwarding strategy. If they were not present, we used the following steps: we calculated the angle between each neighbor and the destination node within the reliable communication range, the reliable node density of the neighbor, the cumulative communication duration between each neighbor, and the sender or source node, and, finally, calculated the weight of each candidate neighbor and selected the best relay node to deliver the message. In the perimeter forwarding strategy where the greedy forwarding strategy failed, the current node first calculated and compared the perimeter weight of the neighbor node, and then selected the neighbor node with the largest weight in the left and right half planes as the next hop to forward the packet. We executed Algorithm 1 when the data packet was transmitted.  
Figure 7: A flow chart of the proposed protocol.  
```
Input: Source node \(\mathrm{N_{C}}\); Destination node \(\mathrm{N_{D}}\); Output: Best relay node;
1. While \(\mathrm{N_{C}}\) is the receive packet, p is
2. If \(\mathrm{N_{C}}==\mathrm{N_{D}}\), then
3. The best relay node is \(\mathrm{N_{C}}\);
4. If p is HELLO packet, then
5. Use the content in p to update or create the content in NT, such as the number of neighbors, location, co-ordinates, speed, etc.
6. End if
7. If p is the data packet, then
8. If using greedy forwarding mode, then
9. Calculate \(\mathrm{D_{cd}}\) and \(\mathrm{D_{neighbor-4d}}\) according to formula (5)
10. For (All neighbors \(\mathrm{N_{neighbor}}\) in NT and \(\mathrm{D_{neighbor-4d}}\leq\mathrm{D_{cd}}\)) do
11. Calculate angle \(\theta_{\mathrm{neighbor}}\) according to Formula (6)
12. Calculate \(\mathrm{T_{neighbor}}\) according to Formula (1)
13. Calculate \(\mathrm{RN_{n}}/\mathrm{S}\) according to Formula (8)
14. Calculate \(\mathrm{G_{neighbor}}\) according to Formula (4)
15. If \(\mathrm{G_{neighbor}}>\mathrm{G_{n}}\)then
16. \(\mathrm{G_{max}}\leftarrow\mathrm{G_{neighbor}}\)
17. \(\mathrm{N_{next}}\leftarrow\mathrm{N_{neighbor}}\)
18. End if
19. End for
20. Update p and then forward p to \(\mathrm{N_{next}}\)
21. Else
22. For (All neighbors \(\mathrm{N_{neighbor}}\) in NT), perform the following actions
23. Calculate \(\theta_{\mathrm{left}}\) and \(\theta_{\mathrm{right}}\) according to Formulas (10) and (11)
24. Calculate \(\mathrm{RN_{n}}/\mathrm{S}\) according to Formula (8)
25. Calculate \(\mathrm{P_{neighbor-left}}\) and \(\mathrm{P_{neighbor-right}}\) according to Formula (9)
26. If \(\mathrm{N_{neighbor}}\) is in the left half plane and \(\mathrm{P_{neighbor-left}}>\mathrm{P_{left}}\), then
27. \(\mathrm{P_{left}}\leftarrow\mathrm{P_{neighbor-left}}\)
28. \(\mathrm{N_{next-left}}\leftarrow\mathrm{N_{neighbor-left}}\)
29. End if
30. If \(\mathrm{N_{neighbor}}\) is in the right half plane and \(\mathrm{P_{neighbor-right}}<\mathrm{P_{right}}\), then
31. \(\mathrm{P_{right}}\leftarrow\mathrm{P_{neighbor-right}}\)
32. \(\mathrm{N_{next-right}}\leftarrow\mathrm{N_{neighbor-right}}\)
33. End if
34. End for
35. If \(\mathrm{P_{left}}\leq\mathrm{P_{right}}\), then
36. \(\mathrm{N_{next}}\leftarrow\mathrm{N_{next-right}}\)
37. Else
38. \(\mathrm{N_{next}}\leftarrow\mathrm{N_{next-left}}\)
39. End if
40. Update p and forward p to \(\mathrm{N_{next}}\)
41. End if
42. End if
43. End while
```  
**Algorithm 1**W-PAGPSR.