91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .m
    金幣: 1
    下載: 2 次
    發(fā)布日期: 2021-06-18
  • 語言: Matlab
  • 標(biāo)簽: WSN??LEACH??multihop??

資源簡介

在傳統(tǒng)的LEACH協(xié)議上進(jìn)行改進(jìn),增加了多跳傳輸環(huán)節(jié),距離基站較遠(yuǎn)的簇頭可以選擇距離基站較近的簇頭進(jìn)行數(shù)據(jù)轉(zhuǎn)發(fā),該代碼采用matlab實現(xiàn)。

資源截圖

代碼片段和文件信息

clear;?
con=0;?
xm?=?200;ym?=?200;?
sink.x?=0.5?*?xm;?
sink.y?=?ym?+?50;?
n?=100;?????
p=0.05;%(成為簇頭的最佳比例)?
%Energy?Model??
Eo?=?1;%(最初能量)?
%Eelec=Etx=Erx?
ETX1=0.000000001;?
ERX1=0.000000001;?
ETX2=0.0000000001;?
ERX2=0.0000000001;?
%Transmit?Amplifier?types??EfsEmp?
%Data?Aggregation?Energy?
EDA=5*0.000000001;?
INFINITY?=?999999999999999;????
%maximum?number?of?rounds?
rmax=3000;????????????????????
??%循環(huán)次數(shù)?
dead=0;?
?
%%%%%%%%%%%%%%%%%%%%%%%%%?END?OF?PARAMETERS?%%%%%%%%%%%%%%%%%%%%%%%%?
?
%隨機(jī)分布節(jié)點?
figure(1);?
for?i=1:1:n?
????S(i).xd=rand(11)*xm;%坐標(biāo)?
????XR(i)=S(i).xd;?
????S(i).yd=rand(11)*ym;?
????YR(i)=S(i).yd;?
????%initially?there?are?no?cluster?heads?only?nodes?
????S(i).type=0;%普通節(jié)點?
????S(i).E=Eo;?
????plot(S(i).xdS(i).yd‘o‘);???
????hold?on;???
end?
?
%計算節(jié)點間的距離?
for?i=1:1:n?
??for?j=1:1:n?
???distance(ij)=((S(i).xd-(S(j).xd))^2?+?(S(i).yd-(S(j).yd)?)^2?)^(1\2);?
??end?
end?
?
%覆蓋半徑?
R=((xm*ym)/(5*pi))^(1\2);?
%增加通信距離?
L=75;?
?
%基站坐標(biāo)?
S(n+1).xd=sink.x;?
S(n+1).yd=sink.y;?
plot(S(n+1).xdS(n+1).yd‘x‘);???
?
%大循環(huán)?
for?r=1:1:45?????
?????ss=rem((r+3)4)+1;??
?????if?rem(r-14)==0?
?????figure;?????????
?????end?
?????????E=0;?????????
?for?i=1:1:n???????????????
?????E=E+S(i).E;????????
????subplot(22ss)plot?(S(i).xdS(i).yd‘o‘);?
?????hold?on;?
????subplot(22ss)?plot?(S(n+1).xdS(n+1).yd‘x‘);?
?????if?S(i).type==1????????????
????????S(i).type=0;?
?????end??????
?end?
%計數(shù)死亡節(jié)點?
??
?for?i=1:1:n?
????%checking?if?there?is?a?dead?node?
?????if?(S(i).E<=0)?
????????subplot(22ss)plot(S(i).xdS(i).yd‘b*‘);???
????????hold?on;?
????????if?S(i).type==0?
???????????dead=dead+1;?
???????????S(i).type=2;?
????????end?
????end?
?end??
?if?(n-dead<=10)%節(jié)點全部死亡退出循環(huán)?
????break;?
?end?
???
?countCHs=1;?
?cluster=1;??
???????
?for?k=1:1:10???????
???for?i=1:1:n?
???c(i)=rand;?
?????if(S(i).E*n>=E?&&?S(i).type?==0)?
??????%如果該節(jié)點在候選集合中?
????????%Election?of?Cluster?Heads?
?????????if(?c(i)?<=?(p/(1-p*mod(rround(1/p)))))?
????????????countCHs?=?countCHs+1;?
????????????S(i).type?=?1;?
????????????C(cluster).type=S(i).type;?
????????????C(cluster).xd?=?S(i).xd;?
????????????C(cluster).yd?=?S(i).yd;?
????????????C(cluster).id?=?i;?
????????????C(cluster).E=S(i).E;??

評論

共有 條評論