xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 5KB
    文件類(lèi)型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-18
  • 語(yǔ)言: Matlab
  • 標(biāo)簽: MATLABLEACH??

資源簡(jiǎn)介

本代碼是基于MATLAB平臺(tái)的無(wú)線(xiàn)傳感器網(wǎng)絡(luò)中LEACH協(xié)議的仿真源代碼,注釋清楚,適合初學(xué)者學(xué)習(xí)

資源截圖

代碼片段和文件信息

clear;
%PARAMETERS

%?dimensions?x(m)?y(m)
xm=100;
ym=100;

%x?and?y?Coordinates?of?the?Sink
sink.x=0.5*xm;
sink.y=0.5*ym;

%Number?of?Nodes?in?the?field
n=100

%Optimal?Election?Probability?of?a?node?to?become?cluster?head
p=0.05;?%Variable

%Energy?Model?(all?values?in?Joules)
%Initial?Energy?
Eo=0.02;

ETX=50*0.000000001;
ERX=50*0.000000001;

%Transmit?Amplifier?types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;

%Data?Aggregation?Energy
EDA=5*0.000000001;

%maximum?number?of?rounds
rmax=50

%PARAMETERS?Done

%Computation?of?do
do=sqrt(Efs/Emp);

%Creation?of?the?random?Sensor?Network
figure(1);
hold?off;
for?i=1:1:n
???%?S(i).xd=rand(11)*xm;
???%?XR(i)=S(i).xd;
????%S(i).yd=rand(11)*ym;
????%YR(i)=S(i).yd;
????load(‘XR.mat‘)
????load(‘YR.mat‘)
????S(i).xd=XR(i);
????S(i).yd=YR(i);
????S(i).G=0;?%這個(gè)函數(shù)小于等于0才能去選拔簇頭,也是為了讓當(dāng)選的簇頭不再重復(fù)當(dāng)選簇頭設(shè)置的變量
????S(i).E=Eo;?%初始能量
????%initially?there?are?no?cluster?heads?only?nodes
????S(i).type=‘N‘;
???plot(?XR(i)YR(i)‘o‘);
????
end

S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xdS(n+1).yd‘x‘);
????????
%First?Iteration
figure(1);

%counter?for?CHs
countCHs=0;

%counter?for?CHs?per?round
rcountCHs=0;
cluster=1;

countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;?%這幾句代碼是干什么用的?

for?r=1:1:rmax
????r

??%Operation?for?epoch
??if(mod(r?round(1/p)?)==0)?%滿(mǎn)足這個(gè)條件就清零
????for?i=1:1:n
????????S(i).G=0;
????????S(i).cl=0;
????end
??end
hold?off;

%Number?of?dead?nodes
dead=0;

%counter?for?bit?transmitted?to?bases?Station?and?to?Cluster?Heads
packets_TO_BS=0;
packets_TO_CH=0;

%counter?for?bit?transmitted?to?bases?Station?and?to?Cluster?Heads??per?round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;
figure(1);

for?i=1:1:n
????%checking?if?there?is?a?dead?node
????if?(S(i).E<=0)
????????plot(S(i).xdS(i).yd‘red?.‘);
????????dead=dead+1;
????????hold?on;????
????end
????if?S(i).E>0
????????S(i).type=‘N‘;
????????plot(S(i).xdS(i).yd‘o‘);
????????hold?on;
????end
end
plot(S(n+1).xdS(n+1).yd‘x‘);?%基站用x表示

STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;

%When?the?first?node?dies
if?(dead==1)
????if(flag_first_dead==0)
????????first_dead=r???%第一個(gè)節(jié)點(diǎn)死亡的輪數(shù)
????????flag_first_dead=1;
????end
end

countCHs=0;
cluster=1;%定義一個(gè)從1開(kāi)始的下標(biāo)參數(shù),真正簇頭個(gè)數(shù)應(yīng)該減去1(因?yàn)閺?開(kāi)始,所以第一個(gè)選出的簇頭應(yīng)該是2-1=1,如果從0開(kāi)始,就不用減去1)

for?i=1:1:n
???if(S(i).E>0)
???temp_rand=rand;?%rand是函數(shù)?,沒(méi)有括號(hào)表示生成0-1的隨機(jī)數(shù)???
???if?(?(S(i).G)<=0)??%表示該節(jié)點(diǎn)可以進(jìn)行簇頭選舉

?%Election?of?Cluster?Heads
?if(temp_rand<=?(p/(1-p*mod(rround(1/p)))))??%簇頭選舉公式
????????????countCHs=countCHs+1;
????????????packets_TO_BS=packets_TO_BS+1;
????????????PACKETS_TO_BS(r+1)=packets_TO_BS;
????????????
????????????S(i).type=‘C‘;?%C表示什么?
????????????S(i).G=round(1/p)-1;?%????賦予一個(gè)大于0的數(shù),該節(jié)點(diǎn)就不能進(jìn)行簇頭選取(當(dāng)選過(guò)的簇頭不能進(jìn)行簇頭選舉)
????????????C(cluster).xd=S(i).xd;
????????????C(cluster).yd=S(i).yd;?%簇頭位置坐標(biāo)
????????????plot(S(i).xdS(i).yd‘k*‘);
????????????
????????????distance(

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????1003??2018-03-29?20:30??XR.mat
?????文件????????1003??2018-03-29?20:30??YR.mat
?????文件?????????420??2018-03-29?20:28??xy.m
?????文件????????6951??2018-04-24?18:59??LEACH2_G.m

評(píng)論

共有 條評(píng)論

相關(guān)資源