# A Node Placement Algorithm Utilizing Mobile Nodes in WSN and IoT Networks +
## 4 The Node Placement Algorithm
### Dynamic Node Placement (Locally-Significant Paths)
#### 4.1.1 Identification of Defective and \"Defecting\" Nodes  
The identification of the node that is defective and the nodes that defect this node is the first step of the algorithm. This operation is normally performed by existing detection algorithms based on the problem to be solved. This information, along with the position of these nodes, is communicated to the sink.  
```
1:functionDynamicMobileCCAlgorithm
2:forall\(n_{j}\in downNodes\)do
3:// find the downstream nodes that have a higher receiving rate than AR
4:if\(numR>AR\)then
5:add\(n_{j}\in defNeighbors\)
6:endif
7:endfor
8:iflist_length(\(defNeighbors\)) == 1 then
9:// find the intersection point from the line that starts from the sink and ends to node \(n_{j}\) with the circle created from the range of the node \(n_{j}\)
10:p = intersectionPofL&C(\(n_{j}\),sink)
11:else
12:forall\(n_{j}\in defNeighbors\)do
13:p = intersectionPofL&C(\(n_{j}\),sink) // calculate the distance between two points
14:dist = distance2P(p,sink)
15:add\(dist\in DistanceTable\) // create the distance list
16:endfor
17:// find the point with the smallest distance to the sink from the Distance List
18:p = getBestPosition(\(DistanceTable\))
19:endif
20:// determine if the point is in range of an active node
21:flags = checkInRangeNode(p)
22:ifflags == TRUE then
23:madtr = selectMobileNodetoUse()
24:send newPosition(p) message to \(madtr\)
25:else
26:set second_priority = p
27:set flagsp = TRUE
28:endif
29:ifflags == FALSE then
30:set \(n\) = 2
31:while\(n\leq 7\)&\(cnt\leq list\_length(downNodes)\)do
32:if\(n==2\)then
33:set i = 0
34:// find a group of two nodes that will get assist from the mobile node
35:forall\(n_{i}\in downNodes\)do
36:forall\(n_{j}\in downNodes\)do
37:totalAR = ar_n_\(i\) + ar_\(i_{j}\)
38:if\(totalAR\geq AR\)then// find the intersection point from the two circles created from the range of each nodes
39:p = intersectionPof2C(\(n_{i}\),\(n_{j}\))
40:dist = distance2P(p,sink)
41:add\(dist\in DistanceTable\)
42:\(i=i+1\)
43:endif
44:endfor
45:endfor
46:if\(i>0\)then
47:pos = getBestPosition(\(DistanceTable\))
48:flags1 = checkInRangeNode(\(pos\))
49:ifflags1 == true
50:addr = selectMobileNodetoUse()
51:send newPosition(pos) message to \(madtr\)
52:else
53:second_priority1 = pos
54:flagsp1 = true
55:endif
56:endif
57:endif
```  
**Algorithm 1** The Dynamic MobileCC Algorithm
```
58:else
59:// find a group of more than two nodes that will get assist from the mobile node
60:for all\(n_{i}\in downNodes\)do
61:for all\(n_{j}\in downNodes\)do
62:p = intersectionPopI&C(\(n_{i}\),\(n_{j}\))
63:for all\(n_{z}\in downNodes\)do
64:totalAR = ar\({}_{n}\) + ar\({}_{n}\)\({}_{j}\) + ar\({}_{n}\)\({}_{z}\)
65:if\(totalAR\geq AR\)then
66:isRange = checkIsRange(\(p\),\(n_{z}\))
67:ifisRange == TRUE then
68:count = count + 1
69:endif
70:endif
71:endfor
72:if count == \(n-2\)then
73:dist = distance2P(p,sink)
74:add\(dist\in DistanceTable\)
75:endif
76:endfor
77:endfor
78:pos = getBestPosition(\(DistanceTable\))
79:flagyes1 = checkInRangeNode(\(pos\))
80:if flagyes1 == TRUE then
81:madr = selectMobileNodetoUse()
82:send newPosition(pos) message to \(madr\)
83:else
84:disp = distance2P(pos,sink)
85:disp1 = distance2P(second_priority,sink)
86:if\(distp\leq distp1\)then
87:second_priority1 = pos
88:flagsp1 = true
89:endif
90:endif
91:endif
92:endwhile
93:endif
94:if flagsp1 == FALSE && flagsp == TRUE then
95:madr = selectMobileNodetoUse()
96:send newPosition(second_priority1) message to \(madr\)
97:else
98:addr = selectMobileNodetoUse()
99:send newPosition(second_priority1) message to \(madr\)
100:else
101:distp = distance2P(second_priority,sink)
102:distp1 = distance2P(second_priority1,sink)
103:if\(distp\leq distp1\)then
104:addr = selectMobileNodetoUse()
105:send newPosition(second_priority) message to \(madr\)
106:else
107:addr = selectMobileNodetoUse()
108:send newPosition(second_priority1) message to \(madr\)
109:endif
110:endif
111:endfunction
```  
**Algorithm 1**\(Cont\).