# Minimum-Cost-Based Neighbour Node Discovery Scheme for Fault Tolerance under IoT-Fog Networks
## 3 Materials and Methods
### Problem Formulation and Objective Function
```
Initialization: IoT Device, \(\text{K}_{\text{k}}=\{\text{K}_{1}\), \(\text{K}_{2}\),...... \(\text{K}_{\text{k}}\}\) and Fog Node, \(\text{F}_{\text{n}}=\{\text{N}_{1}\), \(\text{N}_{2}\),......, \(\text{N}_{\text{n}}\}\) Begin  Collect input from \(\text{K}_{\text{k}}\)  Check the task priority (Pi) and measure the residual energy (Er) of the FNs If FN has a higher-priority task (Pi \(\geq\) 8) // Time-sensitive task If residual energy Er \(\geq\) 0.3  Declare source Fog node as the processing node Else  Forward the task to the neighbouring candidate Fog access node through MCNCND and RPF algorithms 2 and 3 End if If residual energy (0.1 \(\leq\) Er < 0.3)  Identify the next neighbouring candidate (auxiliary/reserve) node Reserve and hold the auxiliary node until the execution of the current task Else residual energy Er < 0.1  Declare it a faulty node Remove the faulty node Forward the task to the reserve node, called pre-emptive forwarding New node is updated End if If FN has a lower-priority task (Pi \(\leq\) 8) //Time-tolerance task If residual energy Er \(\geq\) 0.3  Forward the task to the next neighbouring candidate node via Algorithm 2  New node is updated Else residual energy (0.1 \(\leq\) Er < 0.3)  The corresponding node itself processes the task and declares it a processing node End if If residual energy Er < 0.1  Declare it a faulty node Remove the faulty node Identify and forward the task to the next neighbouring candidate node via Algorithm 2  Pre-emptive forwarding process occurs (Algorithm 3)  New node is updated End if End if End if End if End

### Minimum-Cost-Based Neighbour Candidate Node Discovery (MCNCND) Algorithm

The MCNCND algorithm is proposed to discover the alternate candidate Fog access node to achieve task-offloading with minimal cost, which the Fog control nodes will compute. The initial cost of the Fog nodes is calculated and broadcast using all linked neighbouring Fog access nodes. Then, the algorithm will identify whether the node is in a candidate (ready to process) or busy (already processing) state. In the first case, the source server has candidate Fog access nodes; once the task is generated by the IoT/user device, the nearest Fog access node will gather the task for processing, and the cost of all linked neighbouring Fog access nodes is received. The candidate Fog access node with the minimum cost or the exact cost is selected. The task will be offloaded to the neighbouring candidate Fog access node with the minimum cost. This process will be repeated until the selection of the minimum-cost candidate Fog access node in the Fog network. Then, the finalized minimum-cost candidate Fog access node will be declared a processing node. In the second case, the source server does not have a candidate node, and the generated task is directly offloaded to the source server. It identifies the neighbouring Fog server with candidate Fog access nodes for task-processing. Finally, the task-processing is achieved by the candidate Fog access node with the lowest cost in the neighbouring server. It declares the corresponding node the processing node for task-processing. To obtain a better understanding of the first case presented in Algorithm 2, a simple example is illustrated in Figure 3, which contains two Fog servers, along with their Fog nodes. Server 1 has 13 Fog nodes, with 5 Fog control nodes and 8 Fog access nodes, and server 2 has 10 Fog nodes, with 3 Fog control nodes and 7 Fog access nodes. Initially, the user's device sends the task for processing to Fog access node N9; then, this node will act as an initiator (source node), and receives the cost value for all linked neighbouring candidate Fog access nodes by sending a request. In this scenario, Fog access node N9 has the linked neighbouring candidate Fog access node, denoted as N12, and also has a reduced cost compared to N9. Therefore, the task is offloaded to N12, and again will request the cost of the linked neighbouring candidate Fog access nodes. Then, it is identified as node N8, with the exact cost.