## 4 An Energy-Balanced Protocol Based on the Improved CFSFDP
### Proposed CFSFDP-E Algorithm  
In WSNs, the routing protocols can be divided into flat protocols and hierarchy protocols. All the nodes will be divided into several clusters in a hierarchy protocol. For example, in LEACH, cluster heads are selected randomly and the remaining nodes will choose the clusters in which the distance between the node and cluster head is the smallest. The CFSFDP algorithm can divide data points into clusters according to the local density and distance. Based on this algorithm, we propose an energy-balanced protocol called CFSFDP-Energy (CFSFDP-E) to form clusters in a WSN. In this paper, the premise is that the nodes in the WSN are deployed randomly and each node is location-fixed, energy-constrained and has the same capabilities. The BS is not subject to energy restrictions and has strong communication and computation capabilities. Sensor nodes can be regarded as special data points which have energy attributes. Therefore, it is possible to apply the CFSFDP clustering scheme in the WSN. However, due to the fixed location, the cluster centers will not be changed until the energy of nodes is exhausted. The first dead node will emerge earlier than that in LEACH, so we should take energy into consideration to select the nodes with high local density, high distance and high residual energy as cluster heads. In order to consider the impact of residual energy, Equation (5) should be changed as follows:  
\[\gamma_{i}(r)=\rho_{i}(r)E_{i}(r)\delta_{i}(r)\quad i\in I \tag{11}\]  
where \(\rho_{i}(r)\), \(\delta_{i}(r)\) is the local density and distance of node \(i\) in the current round \(r\) of WSN respectively, and \(E_{i}(r)\) is the residual energy of node \(i\). The number of cluster heads depends on the threshold \(\eta\). In the CFSFDP clustering algorithm, the threshold is fixed. However, the threshold must be dynamic to follow the trend of energy changing in improved algorithm when considering energy. We will discuss the dynamic threshold in Section 5.4. The following is an example to explain our proposed CFSFDP-E algorithm. Suppose that there are six nodes \(a,b,c,d,e,f\) to be clustered, shown in Figure 1. The local densities are in descending order and the distance of each node shown in Table 1 are calculated by Equation (4). Then, according to the algorithm, since the local density of node \(a\) is the largest, the distance of this node should be the maximum value of all the distances. The farthest node from node \(a\) is node \(f\). Then according to the descending order of local density, \(\delta_{b}\) should be the distance between node \(b\) and a node with higher local density, that is, \(\delta_{b}\) is \(d_{ba}\). Notice that in Table 1, DESC means the local densities are in descending order and the distance of each node is determined by the value of local density. Figure 1: The deployment of six nodes. Suppose that we only choose two nodes as cluster centers. In the CFSFDP algorithm, assuming that two points with the largest \(\gamma\) value are node \(a\) and node \(c\), that is, the class of node \(a\) is 1 and the class of node \(c\) is 2, then other nodes can be clustered based on the descending order of local density. For example, node \(b\) choose the same class as the node which has a higher local density and closest to itself. So, the class of node \(b\) is 1 which is the same as node \(a\) and the class of node \(d,\ e,\ f\) is 1, 2, 2 respectively. When considering residual energy in CFSFDP-E, the \(\gamma\) value will be changed. If the two nodes with the largest \(\gamma\) are node \(c\) and node \(b\) in the CFSFDP-E algorithm, the class of node \(a\) obviously cannot be determined because node \(a\) has the largest local density and we can't find a node with higher local density than node \(a\). It doesn't belong to any class if we still allocate nodes according to local density. Due to the above problems, we consider how to allocate other normal nodes based on both local density and energy.