Skip to main content
. 2025 Aug 6;25(15):4838. doi: 10.3390/s25154838
Algorithm 1: Multi-Hop Path Latency Calculation
Input:  source vehicle vn , target RSU rm , task data size Di
Output:  best path P* , minimum latency L*
1: Initialize L*  , P* ← None
2: Raccess  Get all RSUs directly connected to vehicle vn
3: Create RSU-only subgraph Gr
4: for each raccess in Raccess do
5:           Lv2r  Get V2R Latency (vn, raccess, Di)
6:           if raccess is rm then
7:                   Lpath   Lv2r
8:                   Pc [vn, rm]
9:            else
10:     Define edge weights in Gr as R2R latency:
11:     for each edge (ru,rv) in Gr do
12:      W (ru,rv )  Get R2R Latency (Di,ru,rv ) for all edges in Gr
13:      end for
14:     Pv2r  Shortest Path (Gr, source = raccess, target = rm, weights = W)
15:     if Pv2r exists then
16:       Lr2r   Calculate total latency of Pv2r  using weights W
17:       Lpath   Lv2r  + Lr2r
18:       Pc [vn] ⊕Pr2r // ⊕ is path concatenation
19:      else
20:        continue
21:      end if
22:          end if
23:         if Lpath< L* then
24:    L*   Lpath
25:    P*   Pc
26:          end if
27:  end for
28:return   P* , L*