## 5 Heuristic Algorithm
### VANET Routing Path  
CH and RSU are used as nodes to establish the topology graph \(G(\mathcal{V},\mathcal{E})\). First, initialize \(\mathcal{E}=\varnothing\). Second, establishing a communication link between CHs is similar to establishing a communication link between a CM and a CH in Section 4.1, so we also use Equation (3) to determine whether a VANET communication link can be established between the two CHs. If \(D^{vehicle}_{ij}\geq D^{vehicle}_{Threshold}\), then \(\mathcal{E}\bigcup\{e(i,j)\}\). We use the average of the delays generated by the past \(x\) packets transmitted through \(e(i,j)\) to represent the weight \(w_{ij}\) of \(e(i,j)\). After completing the establishment of \(G(\mathcal{V},\mathcal{E})\), we discuss how to establish the routing paths of VANET. First, the CHs are sorted by distance to the RSU from near to far. Second, the Dijkstra algorithm is selected to identify the shortest path from each node to the RSU. Due to the capacity limitation of the communication link, every time a path is identified, it is necessary to check whether the remaining capacity of the link in the path can accommodate the data volume of the newly added node, and if not, a new path needs to be determined. In practice, there are cases where there is no path between the CH and the RSU in the topology graph. If there is no path between \(a_{i}\) and RSU, then find \(c_{j},j\in\{j\}|^{vehicle}_{j,RSU}\leq d^{vehicle}_{i,RSU}\}\) closest to \(c_{i}\). Split \(\max\{c_{i},c_{j}\}\) and remove \(\max\{c_{i},c_{j}\}\) from \(\mathcal{C}\) and add to \(\mathcal{C}\) the resulting clusters from the split. The topology map is updated, and the routing path can be identified. If the path by which the remaining capacity can meet the needs of the current cluster is not identified, then the current cluster will be set to an unreachable state, and all data for the cluster will be sent over the cellular network. The pseudocode for the establishment of routing paths for VANETs is shown in Algorithm 2, where \(r\) represents the data transmission rate of the vehicle. The functions involving Lines 4 to 17 are to try to find the shortest paths. If the identified path is not available, mark the weight of the edge with insufficient capacity as infinite according to Line 12. If there is no path between the CH and the RSU, the processing is performed according to Lines 18-20. ```
Input:\(G(\mathcal{V},\mathcal{E}),\mathcal{C},r\) Output:Paths
1 Path\(\leftarrow\varnothing\);
2 Nodes\(\leftarrow\)\(\mathcal{V}\backslash\{RSU\}\);
3 SortNodes in ascending order based on the distance from CH to RSU;
4 whileNodes\(\
eq\varnothing\)do
5 forall\(a_{i}\) in Nodesdo
6 ifThere is a path between \(a_{i}\) and \(RSU\)then
7\(path_{i}\leftarrow\mathrm{Dijkstra}(node_{i},RSU,G)\);
8 if\(C_{(n,n)\in Path_{i}}^{\mathrm{Dijkstra}}-r\geq 0\)then
9\(Path\bigcup\{Path_{i}\}\);
10\(Nodes\gets Nodes\backslash\{node_{i}\}\);
11 else
12 Set the weight of \(e(m,n)\) as \(+\infty\);
13
14 end if
15
16 else
17 break;
18
19 end if
20
21 end for
22
23 end for
24
25 returnPaths;
```  
**Algorithm 2**Path Construction. The algorithm is used to establish VANET communication links between clusters. Figure 4 shows the general workflow of Algorithm 2. Figure 4a is the topology diagram between CH and RSU, which includes RSU and four clusters. First, each cluster will be sorted by the distance to the RSU from near to far. Suppose the order is \(\mathcal{C}=\{c_{1},c_{4},c_{2},c_{3}\}\). Then, in the edge server, the Dijkstra algorithm is used to find the shortest path from \(c_{1}\) to the RSU to obtain \(Path_{1}=\{e(1,RSU)\}\), as shown in Figure 4b. As shown in Figure 4c,d, we successively find paths \(Path_{4}=\{e(4,RSU)\}\) and \(Path_{2}=\{e(2,1),e(1,RSU)\}\) for \(c_{4}\) and \(c_{2}\). However, when establishing the path of \(c_{3}\), it is found that there is no path between \(c_{3}\) and the RSU in the topology diagram.