?? aloha2.m
字號:
clear;
disp(' ★ ★ ★ ★ ★ ★ ★ALOAH算法模擬實現 ★ ★ ★ ★ ★ ★ ★ ');
disp(' ★ created: 2009/04/17 ★ ');
disp(' ★ filename: aloha2.h ★ ');
disp(' ★ purpose: 比較不同標準下的算法優劣 ★ ');
disp(' ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ');
tag_count=input('輸入標簽數量(大于1小于65535): ');
A(1,tag_count)=0;
disp('輸入您要選擇的類型:');
disp('§1、隨機生成連續標簽');
disp('§2、隨機生成標簽');
choose=input('輸入:')
if choose==1
i=1;
for j=tag_count:-1:1%初始化標簽數組,ID為連續,降序排列處理方便
A(i)=j;
i=i+1;
end
dec2bin(A)
else if choose==2
fid=fopen('testdata.txt','r');
A=fread(fid,tag_count,'int32')
fclose(fid); %隨機生成16位的標簽
end
dec2bin(A)
end
zhen=input('輸入每幀時隙數(大于1小于255): ');
B(1,tag_count)=0;
request_time=0;
answer_time=0;
k=1;
C(1,tag_count)=0;
D(1,tag_count)=0;
n=1;
identify_tag(1,tag_count)=0;
m=1;
p=0;
while tag_count>0
request_time=request_time+1;
for i=1:tag_count
B(i)=ceil((rand(1)*zhen));
end
n=1;
for j=1:zhen
k=1;
answer_time=answer_time+1;
for i=1:tag_count
if j==B(i)
C(k)=i;
k=k+1;
end
end
if k==1
;
elseif k==2
D(n)=C(1);
n=n+1;
identify_tag(m)=A(C(1));
m=m+1;
else
;
end
end
n-1;
for i=1:tag_count
flag=0;
for j=1:(n-1)
if i==D(j)
flag=1;
D(j)=0;
break;
end
end
if flag==1
if p==0
p=i;
end
else
if p~=0
A(p)=A(i);
p=p+1;
end
end
end
tag_count=tag_count-(n-1);
end
request_time
answer_time
time=request_time+answer_time
identify_tag
disp('其中空閑時隙數為:')
f0=zhen*((1-(1/zhen))^length(A))
disp('其中成功的時隙數為:')
f1=length(A)*((1-(1/zhen))^(length(A)-1))
disp('其中沖突的時隙數為:')
fz=zhen-f0-f1
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -