# Optimizing Rule Weights to Improve FRBS Clustering in Wireless Sensor Networks
## 2 Materials and Methods
### Clustering Algorithm  
After describing the fuzzy system designed for the clustering method CFC3 PSO, it is necessary to detail the algorithm that governs the CH selection in the whole WSN. As mentioned before, the proposed clustering method is centralized. Consequently, the BS has to perform all the processing and then communicate the results to the nodes. In order to minimize the information exchanged between the nodes and the BS, the BS calculates or estimates all the values it needs from the nodes, because some of them are then related to the node location (\(dBS\), \(C\), \(ND\)), which needs to be communicated or estimated only once based on the received signal strength indicator (RSSI). In the same way, the BS knows the history of each node, so it can perfectly know \(CHR\). Thus, the unique information that the BS has to calculate based on an estimation of the energy used by each node in each \(round\) is the residual energy \(RE\). Therefore, with all these values, in each \(round\) (\(skip=1\)), the BS performs the following steps:  
* The BS calculates or estimates the input values for every alive node in the network. * The BS runs the fuzzy controller for every node to obtain its \(chance\). * The chances are sorted from the maximum value to the lowest. * The BS selects the \(N\) nodes with the highest probability value, which become CHs. The value of \(N\) is determined by the optimum number of CHs defined for LEACH [12], calculated as \(N=0.05*T\), with \(T\) being the total number of nodes. * The BS sends a broadcast message with the selected CHs. * Contributing nodes send their data to the closest CH. * Each CH aggregates the received data and sends them to the BS. Obviously, all the tasks in the previous algorithm assume an energy cost that is mainly consumed by the BS. However, all the alive nodes have to receive and send a message  
Figure 3: Fuzzy set layout for our clustering method. per _round_, so the selection of the right CHs is of paramount importance to reduce the transmission distances and consequently the energy consumed in the communication. Therefore, the right selection of the CHs will increase the lifetime of the WSN and its application can be carried out for a longer time. Thus, in order to evaluate the lifetime of a WSN with the proposed clustering method, the three metrics presented above are used: FND, HND, and LND. As was mentioned previously, the rules of the KB can differently affect these three metrics (FND, HND, and LND). For example, one rule can increase FND, while it decrements HND or LND. Moreover, keeping the same weight for all the rules for the entire lifetime of the network may not be beneficial for all the metrics. Consequently, we propose a weight tuning for each rule for the three stages that the instants FND, HND, and LND delimit. Thus, we have three KBs, which are as follows:  
* from the first _round_ to FND, we use an initial KB. * From FND to HND, we rely on an intermediate KB. * From HND to LND, we work with the final KB. Thus, to obtain the three different KBs, the weights of the rules are optimized following the process depicted in Figure 4.  
According to Figure 4, to carry out the optimization process, the initial stage starts with all the rules with a weight of one, to obtain the best weights that maximize the value of FND, so we obtain the initial KB or \(KB_{initial}\). It should be noted that, for the whole optimization process, we use a set of scenarios that define different WSN deployments with common parameters (the size of the deployment area, number of nodes, etc.) The details can be found in Section 2.4. In the second phase of the optimization process, \(KB_{initial}\) is used as the initial KB, until the simulation reaches FND. After that point, the weights of the rules are optimized again to obtain the best HND. The resulting KB is called \(KB_{intermediate}\).