# 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 first introduce the global optimal solution and the individual optimal solution of the swarming approach. In the iteration procedure, each combination including \(n\) minimum contention window sizes is updated iteratively to enable the one-hop delays of backbone vehicles to get close to \(D_{avg}\). Specifically, in each iteration, there is a global optimal solution for all combinations and an individual optimal solution for each combination. In the \(t\)th (\(t>1\)) iteration, the global optimal solution \(g(t)\) is equal to the combination that minimizes the objective function value during the previous (\(t-1\))th iterations. The individual optimal solution of combination \(j\), i.e., denoted as \(p_{j}(t)\), is the combination that minimizes the objective function value of combination \(j\) during the previous (\(t-1\))th iterations. In the first iteration (\(t=1\)), \(g(1)\) is the combination that minimizes the objective function value among all of the initial combinations and \(p_{j}(1)\) is the initial value of combination \(j\). ```
1:\(t=1\); //initialization procedure
2: Determine \(D_{avg}\);
3:for\(j=1\) to \(m\) (combinations) do
4:for\(i=1\) to \(n\) (backbone vehicles) do
5: initialize \(cw_{ij}(t)\); // select randomly from [1; 64]
6:endfor
7:endfor //iteration procedure
8:repeat
9: calculate \(D_{ij}(t)\) through simulation;//Equation (1)
10:for\(j=1\) to \(m\)do
11:\(CW_{j}(t)=\{cw_{1j}(t),\,...,\,cw_{ij}(t),\,...,\,cw_{mj}(t)\}\);
12: calculate \(f(CW_{j}(t))\) under \(D_{avg}\);//Equation (2)
13:endfor // update \(gmin(t)\) to the combination that //minimizes the value of the objective function
14:\(gmin(t)=f^{-1}(\min(f(CW_{j}(t))))\);
15:if\(t==1\)then
16:\(g(t)=gmin(t)\);
17:\(p_{j}(t)=CW_{j}(t)\);
18:else
19:if\(f(gmin(t))<f(g(t-1))\)then
20:\(g(t)=gmin(t)\);//Equation (3)
21:else
22:\(g(t)=g(t-1)\);//Equation (3)
23:endif
24:if\(f(CW_{j}(t))<f(p_{j}(t-1))\)then
25:\(p_{j}(t)=CW_{j}(t)\);//Equation (4)
26:else
27:\(p_{j}(t)=p_{j}(t-1)\);//Equation (4)
28:endif
29:endif
30:for\(j=1\) to \(m\)do
31:for\(i=1\) to \(n\)do
32: compute \(\Delta\)\(cw_{ij}(t)\) ; //Equation (5)
33: update \(cw_{ij}(t+1)\) ; //Equation (6), Equation (7)
34:endfor
35:endfor
36:\(t\)++;
37:until\(f(g(t))<\) threshold or number of iterations == limit // output procedure
38: average \(D_{ij}(t)\);
39: return the average result;
```  
**Algorithm 1**The Optimal Contention Window Sizes  
In addition, we briefly introduce the procedure of the swarming approach. For the first iteration, the inputs are the initial \(m\) combinations; the one-hop delays corresponding to each combination and the objective function value corresponding to each combination are calculated. Hence, the global optimal solution \(g(1)\) is determined by the combination corresponding to the minimum objective function value while the initial value of combination \(j\) is set as its the individual optimal solution \(p_{j}(1)\). If \(g(1)\) is smaller than a threshold, the iteration procedure would stop and the one-hop delays are the output. Otherwise, the related values of each combination is updated according to \(g(1)\), \(p_{j}(1)\) and some parameters at the end of the first iteration. Similarly, for the \(t\)th (\(t>1\)) iteration, the inputs are the \(m\) combinations updated at the end of the (\(t-1\))th iteration; the one-hop delays and the objective function value of each combination are calculated like the first iteration. Then, \(g(t)\) is determined by the combination with the minimum objective function value until the \(t\)th iteration, while \(p_{j}(t)\) is set as the minimum objective function value of combination \(j\) until the \(t\)th iteration. In this case, if \(g(t)\) is smaller than a threshold or the number of iterations reaches the predefined maximum value, i.e., the iteration limit, the iteration would be stopped and the corresponding one-hop delays are the output. Otherwise, each combination is updated according to \(g(t)\), \(p_{j}(t)\) and some parameters at the end of the \(t\)th iteration.