## Description

- We selected LEACH (Low-energy adaptive clustering hierarchy) scheme for the minimization of energy consumption.
- We proposed a GWO optimization algorithm to minimize the LEACH protocol objective function as written in equation 3.
- Initialized the random position of the grey wolves in GWO algorithm with limits equal to cluster head formation.
- The cluster head selection is not efficient or optimal in LEACH, so we used a Metaheuristic algorithm called Grey Wolf Optimization (GWO) to select cluster head.
- The energy consumption of the sensor node is minimized by GWO optimized LEACH environment.

## Thesis Statement

LEACH[1] improves energy efficiency and increases the lifetime of the network. The clusters are formed in the LEACH scheme in which distributed sensor nodes are placed in a group. The sensor node has maximum residual energy selected as the cluster head (CH). All the cluster nodes transmit data to CH, and then CH is forwarded through the other CHs or directly to the base station. The cluster head selection procedure is not optimal in the LEACH scheme. So we proposed GWO optimization algorithm for the optimal selection of CH in the LEACH protocol.

## Improved LEACH

LEACH is a MAC protocol implemented with clustering and a simple routing protocol in WSN. The key function of LEACH is to minimize the energy consumption necessary to form clusters to increase the lifetime of WSN. Most of the sensor nodes transmit to the cluster head in the LEACH protocol. The cluster head compresses the received sensor nodes’ data and forwarded it to the sink node (Base Station). The remaining nodes of the clusters communicate with the cluster head in the TDMA (Time Division Multiplexing Access) manner as per CH generated scheduled [1].

The working of LEACH is divided into two phases. The first phase is the setup phase in which clusters are formed in WSN. The second phase is known as a steady phase in which information or data is transferred to the sink. The cluster head selection phase and clustering phase are the key parts of the LEACH protocol. Each sensor node is having threshold energy as per the formulation

In equation 1, p is cluster head percentage in all nodes, r is the round and G is the set of non-selected cluster head nodes.

The energy model is followed by LEACH protocol with the two-channel model; free space (d^{2}) for single hope path and multipath fading (d^{4}) for the multihop path. So the energy consumption of l bit packets over distance d is estimated as

Where *e _{fs}* = free space energy loss,

*e*= multipath fading loss,

_{mp}*d*= distance between source and destination node,

*d*= crossover distance =square root of (

_{0}*e*. The energy variable depends on the node distance, so via optimizing node distance, we can minimize the energy consumption at every sensor node in WSN.

_{fs}/e_{mp})### GWO optimized LEACH

An objective function is necessary for the optimization algorithm. It must satisfy the condition and constraints of the design network. As per equation 2 the energy depends on the distance of sensor nodes, so the objective function shows the relationship between energy and distance variable. Equation 3 shows the fitness function of the LEACH protocol

Here a_{1} and a_{2} are the tradeoff factors, and their fixed value is considered as 0.4. The objective function shows the energy consumption with respect to the node distance.

The MATLAB code for the objective function on LEACH optimization is written below. This is a generalized function and can be used with any optimization technique. For full details, you can download the product **here**.

%%This function is called in each iteration and defines the objective to %% minimize for cluster head selection %% function objval=objectiveFcn(nodeTable,x,nodes,clusterno,nodepos,sinknode) clusterheadpos=nodepos(x,:); sink=sinknode; % sink node %% calculate the distance of each clusterhead from each node for ii=1:clusterno % every CH to each node dist(ii,:) = sqrt((clusterheadpos(ii,1).*ones(100,1)-nodepos(:,1)).^2+... (clusterheadpos(ii,2).*ones(100,1)-nodepos(:,2)).^2); % base Station to every CH CHdistance(ii)=pdist([sink;clusterheadpos(ii,:)],'euclidean'); end for ii=1:nodes [D(ii),idx(ii)]=min(dist(:,ii)); end %% energy residual after each cluster head to sink node communication CHenergy=CHtoSinkEnergy(nodeTable,CHdistance,nodes,clusterno,x); %% energy residual after each cluster head to sensor node communication for ii=1:clusterno clusternodeID=nodeTable.nodeID(idx==ii); nodedistance=D(idx==ii); Clusternodes=numel(nodedistance); if Clusternodes~=0 [NodeEnergy,~,~,~]=nodetoCHEnergy(nodeTable,nodedistance,Clusternodes,clusternodeID); nodeTable.energy(clusternodeID)= NodeEnergy; end end %% objval calculation alpha1=0.4; alpha2=0.4; for ii=1:clusterno nodedistance=D(idx==ii); FirstTerm(ii)=alpha1*(sum(nodedistance)/numel(find(idx==ii))); secondTerm(ii)=alpha2*(sum(nodeTable.energy(idx==ii))/CHenergy(ii)); thirdTerm(ii)=(1-alpha1-alpha2)*(1/numel(find(idx==ii))); addTerms(ii)=FirstTerm(ii)+secondTerm(ii)+thirdTerm(ii); end objval=mean(addTerms); end

We proposed a GWO optimization algorithm to minimize the LEACH protocol objective function as written in equation 3. The GWO is a Meta-heuristic optimization algorithm developed in 2010.

A GWO optimized STATCOM TWO KUNDUR AREA SYSTEM MATLAB code is available at free-thesis.com

We developed a MATLAB script of the GWO algorithm to optimize the above mention objective function. GWO is inspired by the food searching behavior of grey wolves. The wolves are attacks in a group and the best position of any wolf can provide the best solution. We call the objective function in GWO script and get the optimal or best solution in terms of the consumption energy of sensor nodes. The position of the grey wolves updated the position of the cluster head of LEACH protocol.

The objective function written in equation 3 is minimized by the GWO algorithm. The position of wolves allocates the position of the cluster head in each cluster. The position of wolves has been updated the position of cluster heads are also changed.

Figure 1 Architecture of GWO optimized LEACH module @free-thesis.com

## Implementation

- We create a geographical area of 100*100 in the MATLAB 2018a. The sensor nodes are randomly placed in that area.
- Initialize the parameters of LEACH protocol like Initial Energy, Number of Nodes, rounds in LEACH, energy for transferring/receiving of each bit, transmit amplifier free space/multipath energy, aggregation energy, and the packet length. Consider 5% of the total nodes as clusters. So, among 100 nodes 5 clusters are formed using LEACH protocol.
- Initialized the random position of the grey wolves in GWO algorithm with limits equal to cluster head formation. Among the 100 nodes, 5 cluster heads are selected.
- Optimized the objective function value which is given in equation 2 and computed the best fit solution in terms of residual energy. Calculate the objective function value for each wolf in each iteration and save the output.
- Update the best position of wolves as per the GWO algorithm and estimate the best fitness value of the objective function in the next iteration.
- All the process is repeated until the final iteration is finished. We obtained the minimum value of the objective function in terms of energy and distance.
- So the efficient LEACH protocol is achieved by GWO algorithm. The residual energy is reduced in LEACH protocol via an optimal selection of cluster head.

Figure 2 WSN network generated for 100 nodes placed randomly

## Code Overview

This code generates and compares the performance of two different wireless sensor network (WSN) clustering techniques, namely Grey Wolf Optimization (GWO) and LEACH. The code generates a random WSN with a predetermined number of nodes, geographical region limits, and sink node position. The performance of the clustering techniques is evaluated through the amount of energy remaining in the nodes and the number of packets delivered to the sink node.

The code is implemented in MATLAB and consists of several functions that are called from the main script. The script performs the following actions:

- Create a directory to store the results.
- Generate a random WSN based on the number of nodes, geographical region limits, and sink node position.
- Implement the GWO optimization algorithm to select the cluster heads.
- Evaluate the performance of the GWO algorithm by calculating the remaining energy of the nodes and the number of packets delivered to the sink node.
- Implement the LEACH clustering algorithm.
- Evaluate the performance of the LEACH algorithm by calculating the remaining energy of the nodes and the number of packets delivered to the sink node.
- Save the workspace.

The code uses the following input parameters:

rounds: the number of rounds for the clustering algorithms to execute.

Nodes: an array that specifies the number of nodes in the WSN.

X: an array that specifies the geographical region limits for the X coordinates.

Y: an array that specifies the geographical region limits for the Y coordinates.

clusterno: the number of clusters in the WSN.

The code outputs the following results:

GWO_REenergy: an array that stores the remaining energy of the nodes after executing the GWO algorithm.

GWO_Alivenodes: an array that stores the number of alive nodes after executing the GWO algorithm.

GWO_packets: an array that stores the number of packets delivered to the sink node after executing the GWO algorithm.

GWO_Packetdrop: an array that stores the number of packets dropped after executing the GWO algorithm.

LEACH_REenergy: an array that stores the remaining energy of the nodes after executing the LEACH algorithm.

LEACH_Alivenodes: an array that stores the number of alive nodes after executing the LEACH algorithm.

LEACH_packets: an array that stores the number of packets delivered to the sink node after executing the LEACH algorithm.

LEACH_packetdrop: an array that stores the number of packets dropped after executing the LEACH algorithm.

The main script is divided into several sections that are described below:

#### Creating a directory to store the results

This section creates a directory to store the results of the clustering algorithms. The name of the directory is generated based on the current time.

d=num2str(clock); d(isspace(d))=[]; if ~exist('Results','dir') mkdir('Results') end mkdir(['Results/',d])

#### Generating a random WSN

This section generates a random WSN based on the input parameters. The nodes’ positions are assigned randomly, and the sink node’s position is fixed.

rounds=500; % number of rounds %Nodes=20:20:100; % WSN Nodes number Nodes=100; X=[1, 100]; % geographical region limits for X coordiantes Y=[1, 100]; % geographical region limits for Y coordiantes clusterno=5; for nodeloop=1:length(Nodes) % loop of various number of nodes nodes=Nodes(nodeloop); up=nodes; low=X(1); nodepos=X(1)+(X(2)-X(1)).*rand(nodes,2); % nodes position, assigned randomly sinknode=[X(2)/2,Y(2)]; end

#### GWO optimization algorithm

This section implements the GWO optimization algorithm to select the cluster heads. The algorithm iterates for a predetermined number of rounds, and the cluster heads’ positions are updated in each round.

initEnergy=0.5; %Initial Energy nodeTable.energy=initEnergy.*ones(1,nodes)'; nodeTable.nodeID=[1:nodes]'; nodeTable.dead=zeros(1,nodes)'; nodeTable.Alive=ones(1,nodes)'; nodeTable.status=repmat('S',nodes,1); % assign status to each node nodeTable_GWO=nodeTable; packets_delivered=[]; for ii=1:rounds display(['round: ',num2str(ii)]) display(['GWO is iterating for nodes = ', num2str(nodes)]) % GWO optimization [~,clusterheadPos{nodeloop}(ii,:),iterval(ii,:)]=GWO(nodeTable_GWO,clusterno,nodes,nodepos,up,low,sinknode); % [iterval(ii,:),clusterheadPos{nodeloop}(ii,:)]=abc(nodeTable_ABC,clusterno,nodes,nodepos,up,low,sinknode); % results evaluation [REenergy_GWO(ii),deadnodeNo_GWO(ii),nodeTable_GWO,Packetdrop_GWO(ii)]=resultsEval(... nodeTable_GWO,clusterheadPos{nodeloop}(ii,:),nodes,clusterno,nodepos,sinknode); if REenergy_GWO(ii)<0

#### GWO algorithm evaluation

This section evaluates the performance of the GWO algorithm by calculating the remaining energy of the nodes and the number of packets delivered to the sink node.

#### LEACH clustering algorithm

This section implements the LEACH clustering algorithm. The algorithm iterates for a predetermined number of rounds.

#### LEACH algorithm evaluation

This section evaluates the performance of the LEACH algorithm by calculating the remaining energy of the nodes and the number of packets delivered to the sink node.

#### Saving the workspace

This section saves the workspace to a .mat file.

## Conclusion

In this work, we minimize the energy consumption of sensors in the Wireless Sensor Network (WSN). The configuration of the WSN environment is done as per the LEACH (Low-energy adaptive clustering hierarchy) protocol due to efficient energy and network lifetime. In LEACH protocol the distributed sensor nodes are placed in a group or cluster. A sensor node of the cluster is selected as the cluster head which has maximum residual energy. The cluster head selection is not efficient or optimal in LEACH, so we used a Metaheuristic algorithm called Grey Wolf Optimization (GWO) to select cluster head. The energy consumption of the sensor node is minimized by GWO optimized LEACH environment.

## Published Paper similar to this work

- Agrawal, Deepika, Muhammad Huzaif Wasim Qureshi, Pooja Pincha, Prateet Srivastava, Sourabh Agarwal, Vikram Tiwari, and Sudhakar Pandey. “GWO‐C: Grey wolf optimizer‐based clustering scheme for WSNs.”
*International Journal of Communication Systems*33, no. 8 (2020): e4344. - Sharawi, Marwa, and Eid Emary. “Impact of grey wolf optimization on WSN cluster formation and lifetime expansion.” In
*2017 Ninth International Conference on Advanced Computational Intelligence (ICACI)*, pp. 157-162. IEEE, 2017. - Indrapandi, A., and S. Rizwana. “Energy Efficient Cluster based Data Aggregation using GWO Optimization with SPFA Technique for Wireless Sensor Networks.”
*Solid State Technology*63, no. 6 (2020): 24069-24083. - Pratha, S. Jaya, V. Asanambigai, and S. R. Mugunthan. “Grey wolf optimization based energy efficiency management system for wireless sensor networks.” (2021).

## References

- Jiang, Shuyu. “LEACH Protocol Analysis and Optimization of Wireless Sensor Networks Based on PSO and AC.” InÂ 2018 10th International Conference on Intelligent Human-Machine Systems and Cybernetics (IHMSC), vol. 2, pp. 246-250. IEEE, 2018.
- Beiranvand, Zahra, Ahmad Patooghy, and Mahdi Fazeli. “I-LEACH: An efficient routing algorithm to improve performance & to reduce energy consumption in Wireless Sensor Networks.” InÂ The 5th Conference on Information and Knowledge Technology, pp. 13-18. IEEE, 2013.
- Mann, Palvinder Singh, and Satvir Singh. “Improved artificial bee colony metaheuristic for energy-efficient clustering in wireless sensor networks.”Â Artificial Intelligence Review51, no. 3 (2019): 329-354.
- Hatta, N.M & Zain, Azlan & Sallehuddin, Roselina & Abd. Rahim, Shayfull Zamree & Yusoff, Yusliza. (2018). Recent studies on optimisation method of Grey Wolf Optimiser (GWO): a review (2014–2017). Artificial Intelligence Review. 10.1007/s10462-018-9634-.

hamdi.karim(verified owner)–thanx

hamdi.karim(verified owner)–thanx

thiyagarajan.n-1218(verified owner)–nice

thiyagarajan.n-1218(verified owner)–goood

saeideh(verified owner)–I need this code to do my thesis in order to compare its result with my own method. I hope you accept my request.

saeideh(verified owner)–good

nikhil.saini(verified owner)–h

nikhil.saini(verified owner)–h

nikhil.saini(verified owner)–h

nikhil.saini(verified owner)–h

nikhil.saini(verified owner)–h

nikhil.saini(verified owner)–h

sujin.kumar(verified owner)–good platform

sujin.kumar(verified owner)–good

harsimran.singh(verified owner)–Brilliant

bryan.raj(verified owner)–.

saranya.gunasekar(verified owner)–good

saranya.gunasekar(verified owner)–good

scelalcelik(verified owner)–ZUPER

anass.ess(verified owner)–tnx

anass.ess(verified owner)–tnx

saranya.gunasekar(verified owner)–GOOD

upanshu.srivastava(verified owner)–Good

upanshu.srivastava(verified owner)–Good

soustab10(verified owner)–nice

Drwang151002(verified owner)–good

Drwang151002(verified owner)–good

sagar.verma-6850(verified owner)–Thanks

sagar.verma-6850(verified owner)–Thanks

repshika.pradhan(verified owner)–loved it

repshika.pradhan(verified owner)–loved it

repshika.pradhan(verified owner)–loved it

seyed mohammad.alamolhodaie(verified owner)–It is very good

prashant.kulkarni-0716(verified owner)–EXCELLENT CODE

prashant.kulkarni-0716(verified owner)–EXCELLENT

dholariya.romit(verified owner)–good

upanshu.srivastava-4940(verified owner)–ok

thiyagarajan.n-1218(verified owner)–good

lyxfree(verified owner)–thankx

lyxfree(verified owner)–thankx

lyxfree(verified owner)–thankx

tunde.iyaomolere(verified owner)–great

y.s(verified owner)–sdadaasda

y.s(verified owner)–sdadaasda

dhivya.k(verified owner)–good

dhivya.k(verified owner)–good

dhivya.k(verified owner)–very good

adcadf.af(verified owner)–top

dimple.k(verified owner)–Good

papu.k(verified owner)–good

raghvi.khandelwal(verified owner)–please provide at the earliest

arthi.m(verified owner)–good

dhivya.k(verified owner)–good

dhivya.k(verified owner)–excelent

dhivya.k(verified owner)–good

dhivya.k(verified owner)–good

keerthana.r(verified owner)–good

keerthana.r(verified owner)–good

keerthana.r(verified owner)–good

indhu.k(verified owner)–nice

BLESSINA(verified owner)–Very useful code sharing, highly trustable sight.

nirmala(verified owner)–na

chakkor(verified owner)–thank you

baghouri(verified owner)–Thanks

repshika.pradhan(verified owner)–thankyou

a.g(verified owner)–nice

sowmya.r(verified owner)–Very good resources

manishshukla8840(verified owner)–Good but more item and different items

manishshukla8840(verified owner)–na

manishshukla8840(verified owner)–na n

manishshukla8840(verified owner)–na n

manishshukla8840(verified owner)–ZGoog theme but all topics was not covered in this portal

bladepiit(verified owner)–good

bladepiit(verified owner)–good

seham(verified owner)–good

seham(verified owner)–good

seham(verified owner)–good

seham(verified owner)–good

abdul.fofanah(verified owner)–good

jayati.vaish(verified owner)–good

jayati.vaish(verified owner)–good

jayati.vaish(verified owner)–good

sowmya.r(verified owner)–Very nice work.

sachin.divekar(verified owner)–Nice work

1512767365@qq.com(verified owner)–GOOD

1512767365@qq.com(verified owner)–GOOD

tunde.iyaomolere(verified owner)–Great

tunde.iyaomolere(verified owner)–Great

1512767365@qq.com(verified owner)–6666

bladepiit(verified owner)–please share the code to bladepiit@gmail.com

bagoes(verified owner)–ok

yang.le(verified owner)–wrong code.The objective function is false

yang.le(verified owner)–why you share the wrong code

krishna.b(verified owner)–gud

karthikeyan.sakthivel(verified owner)–Thank yu

caixin123(verified owner)–good