# Minimum-Cost-Based Neighbour Node Discovery Scheme for Fault Tolerance under IoT-Fog Networks
## 3 Materials and Methods
### Problem Formulation and Objective Function
```
Initialization: Fog server, \(\mathbf{F_{s}}\) = {S\({}_{1}\), S\({}_{2}\),........., S\({}_{s}\)}, and Fog node, \(\mathbf{F_{n}}\) = {N\({}_{1}\), N\({}_{2}\),......, N\({}_{n}\)} //Replication from S to S\(-\)replicating the entire source task information for fault-free task-processing //Forwarding occurs from N to N within the same server; S\(\rightarrow\) Fog server and N\(\rightarrow\) Fog access node Begin
1:  If \(\mathbf{F_{si}}\
eq\mathbf{F_{lan}}\) {\(\mathbf{\Phi}\)}//task-processing within the same server
2:  Find min-cost candidate fog access node \(\mathbf{F_{lsq}}\) {C\({}_{lsq}\)} = {min (C\({}_{lsq}\), C\({}_{lsq}\),...., C\({}_{lsq}\))} from Algorithm 2
3:  Check whether if \(\mathbf{F_{lsq}}\) is min-cost compared with other fog access nodes (C\({}_{lsq}\) \(\leq\) C\({}_{lsq}\)), C\({}_{lsq}\),...., C\({}_{lsq}\))
4:  Otherwise, conduct a pre-emptive self-forwarding within the source server
5:  Send the task to the neighbouring candidate Fog access node with min-cost \(\mathbf{F_{lsq}}\) {C\({}_{lsq}\)} for task-processing
6:  End if:
7:  Otherwise, {\(\mathbf{F_{lsq}}\) \(\rightarrow\) \(\mathbf{F_{si}}\) }, conduct a replication/initiator forwards the task to neighbouring Fog server
8:  Find \(\mathbf{F_{sq}}\) {C\({}_{gs}\)} = {min (C\({}_{S1}\), C\({}_{S2}\),...., C\({}_{Ss}\))}//Fog server with min-cost
9:  Replicate and pre-emptively forward the task to neighbouring server {\(\mathbf{F_{si}}\) \(\rightarrow\) \(\mathbf{F_{si}}\)}
10:  Find min-cost neighbouring Fog access node \(\mathbf{F_{lsq}}\) {C\({}_{lsq}\)} = {min (C\({}_{lsq}\), C\({}_{lsq}\),...., C\({}_{lsq}\))} and update the process as {\(\mathbf{F_{sq}}\) \(\rightarrow\) \(\mathbf{F_{lsq}}\) } replication
11:  Declare min-cost neighbouring Fog access node \(\mathbf{F_{lsq}}\) as a processing node
12:  End if:
13:  End
```

**Algorithm 3** Replication and Pre-Emptive Forwarding (RPF) Algorithm

In case 1 of the MCNCND algorithm, the task-offloading is achieved with the source server itself by finding the minimum-cost candidate Fog access node for task-offloading, and this process is called pre-emptive self-forwarding. The replication will be performed in case 2 of the MCNCND algorithm due to the unavailability of candidate Fog access nodes within the corresponding source Fog server. In this condition, the task will be directly replicated with the neighbouring Fog server that has the minimum cost and the most appropriate candidate Fog access node will be selected for task-processing. ## 5 Results and Discussion

This section explains the experimental parameter setup and provides a comparative result analysis of the proposed algorithms for various scenarios using existing methods. The proposed algorithms are simulated and analysed with the MATLAB R2022a software platform in Intel Core i5 HP computers with 8 GB RAM to evaluate the performance of task-offloading activities, and this is compared with other existing fault-tolerant algorithms. Table 2 represents the simulation parameters used for the proposed algorithms. ### Average Response Time for Various Tasks with Different Lengths

A Fog environment is created with a Fog server, Fog control nodes, Fog access nodes, and users to estimate the performance of the proposed PTFT algorithm. In this research work, the proposed PTFT algorithm is tested and implemented for 1000 users with 50-1500 tasks, with the task length varying from 1000 to 10,000 bytes, 20 Fog servers, 100 Fog control nodes, and 1000 Fog access nodes in order to analyse the scalability of the proposed Fog-IoT networks. In this simulation environment, it is clearly observed that the proposed methods will efficiently work in a large-scale environment. The performance of the proposed PTFT algorithm in terms of the average response time is illustrated in Figure 5a for various tasks with a variable length, and in Figure 5b for multiple tasks of a variable length. It is observed that the average response time increased exponentially, while the tasks generated by the IoT device increased, and task length also increased.