# A Hybrid Unequal Clustering Based on Density with Energy Conservation in Wireless Nodes
## 3 The Proposed HCD Algorithm
### Protocol Performance
#### 3.2.1 Cluster Initialization
\(E_{TX}(i,l,d_{j,memb})\) is the required energy for transmitting data from CH \(j\) to the next hop. \(E_{RX}(j,l)\) is the required energy for receiving data in node \(j\). \(M(j)\) is the count of member nodes of \(j\) CH. \(R(j)\) is the number of CHs, for whom node \(j\) act as a relay node and receive their data. Each CH computes the cost if there is a CH between it and the BS, and if it receives a route request. After selecting CH with a minimum value, CH \(i\) sends a route reply message to the CH of the next hop. In algorithm 1, lines 3 to 15 correspond to the first phase: the delay time calculation phase. Lines 17 to 27 and lines 28 to 46 correspond to the second and third phase, the CH selection phase and cluster formation phase, respectively. The third phase, computation of intracluster layer, is represented in lines 41. In this phase, CH divided CMs into two layers. Nodes which are in the first layer and their distance from CH is small and their energy is higher than the average energy of nodes are selected as ACH and scheduling is formulated such that further nodes transmit data sooner. Then, scheduling is broadcasted. Lines 47 to 63 represent the route construction phase. ```
1. Begin
2. if Sensor[i]\(\_\)state == 'ClusterHeadP'
3. exit
4. else
5. Sensor[i]\(\_\)state = \"node\"
6. while (CT < TimePha1)
7. V\({}_{t}\) = rand(0.9,1)
8. Calculate Rc by formula (4)
9. Broadcast Neighbor\(\_\)Msg;
10. while (CT < TimeBrc)
11. Receive Neighbor\(\_\)Msg
12. update neighbor List NL [1]
13. Whileon
14. Calculate DelayTime by formula (6) & (7)
15. whileend
16. T = TimePh1 + DelayTime
17. while (CT < TimePh2)
18. if(CT > T)
19. Sensor[i]\(\_\)state = 'ClusterHead'
20. broadcast Head\(\_\)Msg
21. receive Head\(\_\)Msg from competition ClusterHead
22. store in Head\(\_\)List ClusterHead[\(\_\)] along with distance
23. elseif (received Head\(\_\)Msg from any neighbor)
24. Sensor[i]\(\_\)state = 'ClusterMember'* store 'Sensor[j]' in Head_List ClusterHeadL[] along with distance
* end
* while (CT < TimePh3)
* while (CT < TimeBrc Ph3 for join-msg)
* if Sensor[i].state == 'ClusterMember'
* select the nearest ClusterHead Sensor[j] from ClusterHeadL[] list
* Sensor[i]. head = Sensor[j]
* send JoinClusterMsg to Sensor[j]
* elseif Sensor[i].state == ClusterHead
* Receive JoinClusterMsg from ClusterMember
* store in ClusterMember[j] List
* End
* Whileend
* If Sensor[j].state == ClusterHead
* Sensor[i].state = 'ClusterHeadP'
* Calculate Layer in Cluster & Assists CHnode
* send TDMA-Msg
* elseif
* Receive TDMA-Msg
* end
* Whileend
* while (CT < TimePh4)
* Broadcast Route_Msg;
* If layer > 1
* while (CT < Time_Br_RM)
* Receive Route_Msg
* update hopList HL []
* Whileend
* End
* select the ClusterHead Sensor[j] from hopList HL[] by formula (8) send Rout_Replay
* If layer < 4 while (CT < Time_Rs_RR)
* Receive Route_Replay
* Update RPICH List []
* whileend
* end
* Whileend
* end

#### 3.2.2 Data Transmission

Round

In the first phase of each round, based on the schedule by the CH, nodes start to send their own data to the CH. When CH receives the packets from its own members, it starts to assemble an integration. In the second phase, after sending data by nodes to CH, CH sends their data to the BS through a path that has been created in path discovered phases. The route has been designed so that energy consumption is minimized for sending each packet. In this phase, the protocol usesthe carrier-sense multiple access (CSMA) method to transfer data. Each CH sends the data to the BS through the path created in the previous section. Except for the last major slot, one part of the CH rotation was situated at the end of each major slot. In this part, each cluster member nodes send their data to their own CH. CH select a cluster member node as a CH which has more energy for the next round.