# Minimum-Cost-Based Neighbour Node Discovery Scheme for Fault Tolerance under IoT-Fog Networks
## 3 Materials and Methods
### Problem Formulation and Objective Function
14: Select the min-cost candidate node, C\({}_{\mathrm{Lai}}\) = minI \(\mathrm{C_{Lai1}}\), C\({}_{\mathrm{Lai2}}\),...., C\({}_{\mathrm{lan}}\) \(l\), and select the corresponding candidate Fog access node \(\mathbf{F_{laj}}\) for task-processing
15: If \(\mathbf{F_{lai}}\) (C\({}_{\mathrm{Lai}}\)) < \(\mathbf{F_{laj}}\) (C\({}_{\mathrm{Laj}}\))//_cost of initiator is less than neighbouring nodes_
16: Declare the initiator node as \(\mathbf{F_{lai}}\) (C\({}_{\mathrm{Lai}}\)), a processing node
17: Otherwise:
18: Consider the min-cost neighbouring candidate Fog access node as the initiator node for further processing (replace \(\mathbf{F_{laj}}\) with \(\mathbf{F_{lai}}\))
19: End if:
20: Repeat from line 13 to find the min-cost candidate Fog access node \(\mathbf{F_{lan}}\)
21: Otherwise: //_Source server with no candidate Fog access nodes_
22: For \(\mathbf{F_{si}}\), j = 1, 2, 3,...., n-1 //_neighbouring Fog server_
23: Calculate the cost of all neighbouring Fog servers \(\mathbf{F_{sf}}\) (C\({}_{\mathrm{Sj}}\))
24: End for:
25: Identify the next min-cost neighbouring \(\mathbf{F_{sf}}\), C\({}_{\mathrm{Sj}}\) = {min (C\({}_{\mathrm{S1}}\), C\({}_{\mathrm{S2}}\),...., C\({}_{\mathrm{S3}}\))} \(\rightarrow\)\(\mathbf{F_{sf}}\)
26: Select the min-cost neighbouring Fog server (\(\mathbf{F_{sf}}\)) with candidate Fog access nodes for task-processing
27: Select the nearest candidate Fog access node (\(\mathbf{F_{lai}}\)) as the initiator in the respective Fog server (\(\mathbf{F_{si}}\))
28: Fog control nodes (\(\mathbf{F_{nc}}\)) will compute the cost function of all possible linked Fog access nodes as follows: C\({}_{\mathrm{Lai1}}\), C\({}_{\mathrm{Lai2}}\),...., C\({}_{\mathrm{lan}}\)
29: The initiator node receives the list of the cost of all linked neighbouring nodes and identifies the Fog access node states, and whether the node is a candidate node or a busy node. 30: Select the min-cost candidate node, C\({}_{\mathrm{Laj}}\) = minI { C\({}_{\mathrm{Lai1}}\), C\({}_{\mathrm{Lai2}}\),...., C\({}_{\mathrm{lan}}\) \(l\), and select the corresponding candidate Fog access node \(\mathbf{F_{laj}}\) for task-processing
31: If \(\mathbf{F_{lai}}\) (C\({}_{\mathrm{Lai}}\)) < \(\mathbf{F_{laj}}\) (C\({}_{\mathrm{Laj}}\))//_cost of initiator is less than neighbouring nodes_
32: Declare the initiator node, \(\mathbf{F_{lai}}\) (C\({}_{\mathrm{Lai}}\)), a processing node
33: Otherwise:
34: Consider the min-cost neighbouring candidate Fog access node as the initiator node for further processing (replace \(\mathbf{F_{laj}}\) with \(\mathbf{F_{lai}}\))
35: End if:
36: Repeat from line 29 to find the min-cost candidate Fog access node \(\mathbf{F_{lan}}\)
37: End if:
38:End for:
39:End
```
**Algorithm 2** Minimum-Cost-Based Neighbour Candidate Node Discovery (MCNCND) Algorithm

### Replication and Pre-Emptive Forwarding (RPF) Algorithm

The RPF algorithm is proposed to forward the task, carrying information from the source Fog access node to the selected neighbouring candidate Fog access node for task-offloading with the same Fog server or a neighbouring Fog server. The proposed Replication and Pre-emptive Forwarding (RPF) algorithm is summarized in Algorithm 3.