# Fuzzy-Logic Based Distributed Energy-Efficient Clustering Algorithm for Wireless Sensor Networks
## 4 EEDCF Algorithm  
Fuzzy logic can be applied to handle the evaluation problems with complicated factors and conditions via simulating human beings' making decision. It provides a feasible method to achieve the conclusion according to the descriptive language to deal with the input data like human operators, which is suitable to be used for CH election [27].  
The proposed EEDCF algorithm combines fuzzy logic with clustering algorithm for wireless sensor networks and considers node residual energy, node degree, and neighbor nodes' energy as input values for each node, which are defined as follows:  
Node residual energy: The current energy of each node. Due to the need to undertake data gathering mission within the cluster and communicate with the BS, the energy consumption of CH is far more than the other member nodes in the cluster. Therefore, selecting the nodes with higher residual energy to be the CHs can greatly improve the performance of the whole system and increase the lifetime of the networks.  
Node degree: The number of neighbor nodes within communication radius \"R\". The greater the node degree is, the higher the efficiency of data transmission will be, and the smaller the shared workload of data forwarding taken on by each neighbor node of CH will be also, which is good for the entire system energy optimization.  
Neighbor nodes' average residual energy: Due to the multi-hop communication model for data transmission within the cluster, the nodes closer to the CH need more energy to implement data forwarding than the farther ones. Thus, there is no doubt that introducing neighbor nodes' average residual energy as one of the decision factors is an effective solution to the load balancing problem for the whole network system.  
In this paper, we define four states for the nodes: (1) initial state; (2) competing CH state; (3) elected CH state; and (4) member node state. Table 1 shows the message format and description used in the EEDCF algorithm, and the pseudo code of the proposed algorithm describing every CH election process is shown in Algorithm 1.  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Message** & **Description** \\ \hline Node\_MSG & Data package including node ID and residual energy \\ \hline Info\_table & Information table in each node \\ \hline Head\_compete & The node is in CH competing state \\ \hline CH\_Message & The node is selected as CH finally \\ \hline Node\_JOIN & Nodes failing to be elected as CH send this message to search for the closest CH to ask for joining \\ \hline CH\_ACCEPT & When new CHs receive Node\_JOIN message from non-CH nodes, they return CH\_ACCEPT message to finish the information docking \\ \hline \hline \end{tabular}
\end{table}
Table 1: Messages definition.  
The cluster formation process can be divided into three phases: (1) information table updating; (2) CH election; and (3) cluster build. Those phases are described in the upcoming subsections.  
```
1 Begin
2N=Total number of nodes
3i=ID of living sensor node in current round
4 nod[i].statement=initial_state
5 forachnode[i]
6 receives Node_MSG from Neighbor_Node
7 nod[i].Info_table updates
8 Input parameters: Residual Energy (RE), Node Degree (ND), Neighbor nodes' Residual Energy (NRE)
9 nod[i].RE=residual energy of nod[i]
10 nod[i].ND=number of nodes within communication \"R\"
11 nod[i].NRE=residual energy of neighbor nodes of nod[i]
12 Analysis through fuzzy inference system (FIS)
13 probability=FIS(nod[i].RE, nod[i].ND, node[i].NRE)
14 Send Head_compete to all neighbor nodes
15 Neighbor_Node[j]=list of Head_compete from neighbor node
16 Comparing the result from FIS (Fuzzy Inference System) with neighbor nodes'
17 if(node[i].probability> Neighbor_Node[j].probability)
18 nod[i].statement=CH
19 advertise CH_Message
20 else
21 on receiving CH_Message
22 select the nearest CH
23 send Node_JOIN to the nearest CH
24 end
25 end
26 End
```  
**Algorithm 1** The Proposed Clustering Algorithm for EEDCF