目录
💥1 概述
📚2 运行结果
🎉3 参考文献
👨💻4 Matlab代码
💥1 概述
本文准备了一种路由方法,该方法使传感器通过有效地使用能量将数据从发送方加载到接收器,因为它在 LEACH 协议中使用簇头形成。作为接收器的“水槽”在整个范围内从一个地方随机移动到另一个地方。
传感器节点最初是在给定范围内和相同能量中随机创建的,经过几轮后,传感器的能量发生变化,然后根据该能量选择集群头 ,死节点以红色表示。我们可以在使用寿命和平均能耗等两个因素中比较现有系统和我们提出的系统进行结果分析。
📚2 运行结果
主函数部分代码:
clc; clear; close all; warning off all; tic; %% Create sensor nodes, Set Parameters and Create Energy Model % %%% %%% %%% %%% %%% %%% %%% %%% Initial Parameters %%% %%% %%% %%% %%% %%% %%% %% n=100; % Number of Nodes in the field[Area,Model]=setParameters(n); %Set Parameters Sensors and Network %%%%%%%%%%%%%%%%%%%%%%%%% configuration Sensors %%%%%%%%%%%%%%%%%%%% CreateRandomSen(Model,Area); % Create a random scenarioload Locations %Load sensor Location Sensors=ConfigureSensors(Model,n,X,Y); Sender=n+1; %Sink TotalCH=[]; ploter(Sensors,Model,Sender,TotalCH); %Plot sensors for i=1:n text(Sensors(i).xd,Sensors(i).yd,int2str(i),'FontSize',10); end plot(Sensors(Sender).xd,Sensors(Sender).yd,'w*','MarkerSize',15); %%%%%%%%%%%%%%%%%%%%%%%%%% Parameters initialization %%%%%%%%%%%%%%%% countCHs=0; %counter for CHs flag_first_dead=0; %flag_first_dead deadNum=0; %Number of dead nodes initEnergy=0; %Initial Energy for i=1:n initEnergy=Sensors(i).E+initEnergy; end SRP=zeros(1,Model.rmax); %number of sent routing packets RRP=zeros(1,Model.rmax); %number of receive routing packets SDP=zeros(1,Model.rmax); %number of sent data packets RDP=zeros(1,Model.rmax); %number of receive data packets Sum_DEAD=zeros(1,Model.rmax); CLUSTERHS=zeros(1,Model.rmax); AllSensorEnergy=zeros(1,Model.rmax); %%%%%%%%%%%%%%%%%%%%%%%%% Start Simulation %%%%%%%%%%%%%%%%%%%%%%%%% global srp rrp sdp rdp srp=0; %counter number of sent routing packets rrp=0; %counter number of receive routing packets sdp=0; %counter number of sent data packets rdp=0; %counter number of receive data packets %Sink broadcast start message to all nodes Receiver=1:n; %All nodes Sensors=SendReceivePackets(Sensors,Model,Sender,'Hello',Receiver); % All sensor send location information to Sink . Sensors=disToSink(Sensors,Model); % Sender=1:n; %All nodes % Receiver=n+1; %Sink % Sensors=SendReceivePackets(Sensors,Model,Sender,'Hello',Receiver); %Save metrics SRP(1)=srp; RRP(1)=rrp; SDP(1)=sdp; RDP(1)=rdp; %% Main loop program for r=1:1:Model.rmax % %%% %%% %%% %%% %%% %%% %%% %%% %%% Initialization %%% %%% %%% %%% %%% %%% %%% %This section Operate for each epoch member=[]; %Member of each cluster in per period countCHs=0; %Number of CH in per period %counter for bit transmitted to Bases Station and Cluster Heads srp=0; %counter number of sent routing packets rrp=0; %counter number of receive routing packets sdp=0; %counter number of sent data packets to sink rdp=0; %counter number of receive data packets by sink %initialization per round SRP(r+1)=srp; RRP(r+1)=rrp; SDP(r+1)=sdp; RDP(r+1)=rdp; pause(1) %pause simulation hold off; %clear figure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Sensors=resetSensors(Sensors,Model); %allow to sensor to become cluster-head. LEACH Algorithm AroundClear=10; if(mod(r,AroundClear)==0) for i=1:1:n Sensors(i).G=0; end end
🎉3 参考文献
[1]马震. 关于无线传感器网络节能的若干关键问题研究[D].北京交通大学,2009.
部分理论引用网络文献,若有侵权联系博主删除。