# Topology-Aware Anchor Node Selection Optimization for Enhanced DV-Hop Localization in IoT
## 5 Proposed Algorithm  
### Anchor Node Selection Mechanism Using BGWO  
In continuous optimization problems, the grey wolf's position can take any value within a defined range. However, in BGWO for discrete problems, the position vector can only take values of \"0\" or \"1\". To develop an anchor node selection mechanism using BGWO, the grey wolf's position values must be determined based on the characteristics of DV-Hop localization. Anchor nodes either participate in the localization of unknown nodes or do not. Thus, the position vector of the optimal grey wolf in BGWO indicates whether an anchor node is involved in localization. Assume there are \(M\) grey wolves and \(N_{a}\) anchor nodes in the network. The position vector of the \(i\)-th grey wolf is represented as follows: \(\mathbf{X}_{i}=(x_{i1},\,x_{i2},\,\ldots,\,x_{iN_{a}})\), where the dimensionality of the vector corresponds to the total number of anchor nodes. The position vector is initialized using Equation (17) and updated based on Equation (19) during each iteration. If \(x_{i\bar{k}}=1\), it indicates that the \(k\)-th anchor node is a suitable anchor node for localization. If \(x_{i\bar{k}}=0\), the \(k\)-th anchor node does not participate in the localization process. To better illustrate the anchor node selection mechanism, consider a non-uniformly distributed network with six anchor nodes. If the grey wolf's position vector is [0, 1, 1, 0, 1, 0], it means that localization of the unknown node will use only the second, third, and fifth anchor nodes, while the others will not participate.  
After determining the values of the grey wolf's position vector, the coordinates of the corresponding anchor nodes, which have a value of \"1\", can be calculated using the least squares method. Additionally, due to the limited available information in the network during the localization phase, only the position coordinates of the anchor nodes and the estimated distances from unknown nodes to anchor nodes are known. Thus, when using BGWO to select anchor nodes, Equation (21) serves as the fitness function to evaluate the quality of the grey wolf's position.  
\[fitness\_bgwo(\mathbf{X})=\frac{\sum\limits_{i=1}^{N_{a}}{{{(\sqrt{{{(x_{i}- x_{u})^{2}+{(y_{i}-y_{u})^{2}}}}-d_{ui})}^{2}}}}}{{N_{a}\cdot R}} \tag{21}\]  
where \((x_{u},y_{u})\) represents the estimated coordinates of the unknown node \(u\), obtained using the corresponding anchor nodes with a value of \"1\" in the position vector. \((x_{i},y_{i})\) represents the position coordinates of the anchor node \(i\), and \(R\) is the communication radius of nodes.  
The fitness function, corresponding to Equation (21), exhibits high sensitivity to the quality of anchor nodes involved in the calculation. When lower-quality anchor nodes participate in localization, significant deviations arise between the estimated distances from the unknown node \(u\) to these anchors and the actual distances. This subsequently leads to a larger fitness function value resulting from the least squares localization solution. Conversely, when all participating anchor nodes are of high quality, the deviations between the estimated and actual distances from the unknown node \(u\) to anchor nodes are smaller. In this case, the least squares localization solution yields a relatively smaller fitness function value. Consequently, based on this characteristic, this paper selects Equation (21) as the fitness function and employs the BGWO algorithm for optimization. The position vector of the grey wolf obtained through this algorithm's optimization determines the final set of anchor nodes participating in the calculation.