# A Swarming Approach to Optimize the One-Hop Delay in Smart Driving Inter-Platoon Communications
## 4 Swarming Approach Description
### Minimum Average One-Hop Delay
#### 4.1.2 Iteration Procedure
We will further analyze each iteration procedure in detail. For the \(t\)th iteration, the inputs are the \(m\) combinations updated at the end of the (\(t-1\))th iteration. Let \(cw_{ij}(t)\) be the minimum contention window size of backbone vehicle \(i\) in combination \(j\). In the system model, the backbone vehicle \(i\) in combination \(j\) transmits packets with the minimum contention window size \(cw_{ij}(t)\). The one-hop delay of the backbone vehicle \(i\) in combination \(j\) is calculated by Equation (1),  
\[D_{ij}(t)=\frac{T_{ij}(t)}{x_{ij}(t)}, \tag{1}\]  
where \(D_{ij}(t)\) is the one-hop delay of backbone vehicle \(i\) in combination \(j\), \(T_{ij}(t)\) is the time duration that backbone vehicle \(i\) in combination \(j\) takes to transmit packets, and \(x_{ij}(t)\) is the number of the packets that are transmitted successfully by backbone vehicle \(i\) in combination \(j\) (Line 9). Then, the closeness between the one-hop delays of the backbone vehicles with the minimum contention window sizes in combination \(j\) and \(D_{avg}\) is measured through an objective function, i.e., the variance between them, which is given by (2),  
\[f(CW_{j}(t))=\sum_{i=1}^{N}[D_{ij}(t)-D_{avg}]^{2}, \tag{2}\]  
where \(CW_{j}(t)\) denotes the set of minimum contention window sizes of \(n\) backbone vehicles in combination \(j\), i.e., \(CW_{j}(t)=\{cw_{1}(t)\), \(cw_{2}(t)\),..., \(cw_{ij}(t)\),..., \(cw_{nj}(t)\};f(CW_{j}(t))\) denotes the closeness between the one-hop delays of backbone vehicles with the minimum contention window sizes in combination \(j\) and \(D_{avg}\) (Lines 10-13). Given \(m\) combinations, the objective function values of them can be derived according to (2). The minimum objective function value among these combinations is \(gmin(t)\) (Line 14). Denote \(gmin_{i}(t)\) as the minimum contention window size of backbone vehicle \(i\) in \(gmin(t)\), \(g_{i}(t)\) as the minimum contention window size of backbone vehicle \(i\) in  
when \(t=1\), \(g_{i}(t)\) is selected as \(gmin_{i}(t)\) and \(p_{ij}(t)\) is selected as \(cw_{ij}(t)\)(Lines 15-17). The basic idea of the above equations is to determine the one-hop delays by comparing how much the one hop delays of these vehicles are close to \(D_{avg}\). If \(f(g(t))\) is smaller than a threshold value or the number of iterations reaches the iteration limit, the iteration procedure would be stopped and the one-hop delays of backbone vehicles that get close enough to the optimization objective \(D_{avg}\) are obtained (Line 37). If \(f(g(t))\) is not smaller than a threshold value and the number of iterations does not reach the iteration limit, \(cw_{ij}(t)\) would be updated according to \(g(t)\), \(p_{j}(t)\) and some parameters at the end of the \(t\)th iteration. When \(t>1\), \(cw_{ij}(t)\) is updated according to (5)-(7),  
\[ \begin{split}\Delta cw_{ij}(t)&=w\cdot\Delta cw _{ij}(t-1)+c1\cdot r1\cdot(g_{i}(t)-cw_{ij}(t))\\ &+c2\cdot r2\cdot(p_{ij}(t)-cw_{ij}(t)),\end{split}  \tag{5}\]  
\[cw^{{}^{\prime}}_{ij}(t+1)=cw_{ij}(t)+\Delta cw_{ij}(t), \tag{6}\]  
\[cw_{ij}(t+1)=\left[cw^{{}^{\prime}}_{ij}(t+1)+0.5\right], \tag{7}\]  
where \(c1\) and \(c2\) are the learning coefficients and are positive constants, \(r1\) and \(r2\) are the random parameters in [0, 1], \(w\) is the inertia coefficient, \(\Delta cw_{ij}(t)\) is the variation of \(cw_{ij}(t)\), (7) is used to guarantee that the value of the updated \(cw_{ij}(t)\) is the integer that equals the rounded-off value of \(cw^{{}^{\prime}}_{ij}(t+1)\). Here, \(\Delta cw_{ij}(t)\) cannot be larger than a constant \(\Delta cw_{max}\). If \(\Delta cw_{ij}(t)\) is larger than \(\Delta cw_{max}\), it would keep \(\Delta cw_{max}\). When \(t=1\), \(\Delta cw_{ij}(t)\) is a random value ranging from 0 to 1, and \(cw_{ij}(t+1)\) is updated according to (6) and (7) (Lines 30-35).