# Inverse Coupled Simulated Annealing for Enhanced OSPF Convergence in IoT Networks
## 2 Main Contribution
### Reverse Coupled Annealing Algorithm Design
```
Input: UOSA current temperature: \(T_{0}^{u}\); UOSA termination temperature: \(T_{k}^{u}\); UOSA annealing weight: \(\delta^{u}\); DOSA current temperature: \(T_{0}^{d}\); UOSA heating weight: \(\beta^{u}\); DOSA maximum temperature: \(T_{m}^{d}\); UOSA inner loop iterations: \(M_{1}^{u}\); UOSA current optimal sending interval: \(s_{cb}^{u}\) Current Hello packet sending interval: \(T_{h}\) ; Current fault detection time: \(T_{d}\); Output: next Hello packet sending interval: \(s_{nh}\); next fault detection time: \(s_{nd}\); UOSA optimal sending interval: \(s_{h}^{u}\); DOSA next temperature: \(T_{n}^{d}\)
1: Initialize: \(s_{nh}=T_{0}^{u},s_{b}^{u}=s_{cb}^{u},s_{nd}=T_{d}\)
2: if \(T_{0}^{u}>T_{k}^{u}\) then
3: Initialize: \(k=0\)
4: while \(k<M_{1}^{u}\) do
5: \(s_{nh}=f_{u}(s_{nh})\)
6: difference value: \(\Delta s=s_{nh}-T_{h}\)
7: if \(\Delta s\geq 0\) then
8: \(s_{nh}=\min\{30,s_{nh}\}\)
9: else if \(e^{(\Delta s/T_{0}^{u})}>random(0,1)\) then
10: \(s_{nh}=\min\{30,s_{nh}\}\)
11: end if
12: if \(s_{nh}>s_{b}^{u}\) then
13: \(s_{b}^{u}=s_{nh}\)
14: end if
15: \(k=k+1\)
16: end while
17: \(T_{n}^{u}=\delta^{u}*T_{0}^{u}\)
18: \(s_{nd}=\min\{40,s_{nh}*40\}\)
19: end if
20: \(T_{0}^{d}=\min(\beta^{u}*T_{0}^{d},T_{m}^{d})\)
```  
**Algorithm 1**Upward optimization simulated annealing algorithm (UOSA)  
```
Input: DOSA current temperature: \(T_{0}^{d}\); DOSA termination temperature: \(T_{k}^{d}\); DOSA annealing weight: \(\delta^{d}\); DOSA current temperature: \(T_{0}^{u}\); DOSA heating weight: \(\beta^{d}\); UOSA maximum temperature: \(T_{m}^{u}\); DOSA inner loop count: \(M_{1}^{d}\); DOSA current optimal sending interval: \(s_{cd}^{d}\); Current hello Packet transmission interval: \(T_{h}\); Current fault detection time: \(T_{d}\) Output: next Hello packet transmission interval: \(s_{nh}\); next fault detection time: \(s_{nd}\); DOSA optimal sending interval: \(s_{b}^{d}\); UOSA next temperature: \(T_{n}^{u}\)
1: Initialize: \(s_{nh}=T_{0}^{d}\), \(s_{b}^{d}=s_{cb}^{d}\)
2: if \(T_{0}^{d}>T_{k}^{d}\) then
3: Initialize: \(k=0\)
4: while \(k<M_{0}^{d}\) do
5: \(s_{nh}=f_{d}(s_{nh})\)
6: difference value: \(\Delta s=s_{nh}-T_{h}\)
7: if \(\Delta s\leq 0\) then
8: \(s_{nh}=\max\{1,s_{nh}\}\)
9: else if \(e^{(-\Delta s/T_{0}^{d})}>random(0,1)\) then
10: \(s_{nh}=\max\{1,s_{nh}\}\)
11: end if
12: if \(s_{nh}<s_{b}^{d}\) then
13: \(s_{b}^{u}=s_{nh}\)
14: end if
15: \(k=k+1\)
16: end while
17: \(T_{n}^{d}=\delta^{d}*T_{0}^{d}\)
18: \(s_{nd}=\min\{40,s_{nh}*40\}\)
19: end if
20: \(T_{0}^{u}=\min(\beta^{d}*T_{0}^{u},T_{m}^{u})\)
```  
**Algorithm 2**Downward optimization simulated annealing algorithm (DOSA)  
The objective of the upward optimization simulated annealing (UOSA) algorithm is to optimize the Hello packet transmission interval \(T_{h}\) and the fault detection time \(T_{d}\), gradually increasing both parameters to their maximum values. In line 2 of the pseudocode, it first checks whether the initial temperature \(T_{0}^{u}\) has reached the termination temperature \(T_{k}^{u}\); if not, it enters the inner loop. Lines 4 to 16 describe the inner loop process of the simulated annealing algorithm. The algorithm generates a random number in the range of \(-2\) to 4 using the random seed generation function \(f_{u}(s_{nh})\) and adds it to \(s_{nh}\) to obtain a new \(s_{nh}\). Subsequently, it assesses whether the generated difference \(\Delta s\) meets the Metropolis criterion, ultimately updating \(s_{nh}\) and the current optimal state \(s_{b}^{u}\). Line 17 implements the cooling operation of the annealing process, and line 18 calculates the new fault detection time \(s_{nd}\) based on the updated \(s_{nh}\). Line 20 executes the heating operation for the downward optimization simulated annealing (DOSA); each time UOSA is completed, the initial temperature \(T_{0}^{d}\) for DOSA is increased. In summary, the code structure of this algorithm consists of only one outer loop, with the number of iterations being \(M_{1}^{u}\). The algorithm's complexity is \(O(M_{1}^{u})\).