📄 simu1.m
字号:
%On the minimum node degree and connectivity of a wireless multihop network%
%********Report research simulation***********%%%%%%%%%%%%%%%%%%%%%%%%
%************simulation of prob of each node has at least n0 neighbors********
%********1000*1000m^2,n=500 nodes ,radio range r0,minimum node degree dmin*
%*********Date 2006,6,13--By Liu FengWei
%function
Stimes=500;%simulation times
Nodenum=500;%number of nodes
N0=[1 2 3];%minimum degree
LN0=length(N0);%length of N0
Rlimit=150;
%Pdmin_N=zeros(1,L);%prob of minimum node degree greater than N0
Rstep=[10:10:Rlimit]; %radio range
L=length(Rstep);%number of radio range
Ndeg=zeros(Nodenum,L);%record degree of every node
G_than_N0=zeros(Nodenum,L,LN0);%record the number of degree of every node greater than N0
for s=1:Stimes
rand('state',sum(100*clock))
%NodeXY=1000*(rand(Nodenum,2));%coordinates of node
NodeXY=1000*(rand(Nodenum,2));%coordinates of node
%[Sort_N,Sort_index]=sort(NodeXY(:,1));%sort the node to distinguish the lateral node
%NodeXY=NodeXY(Sort_index,:);
Links=zeros(Nodenum*(Nodenum-1)/2,2,L);
k=ones(L,1);%index for links for every radio range
m=1;
%************Generate links**************************
for r0=10:10:150
for i=1:(Nodenum-1)
for j=(i+1):Nodenum
if(sqrt((NodeXY(i,1)-NodeXY(j,1))^2+(NodeXY(i,2)-NodeXY(j,2))^2)<r0)%Euclidian distance<r0
Links(k(m),:,m)=[i j];
k(m)=k(m)+1;
end
end
end
m=m+1;
end
%*******Calculate the degree of each node***************
%Links=Links(1:(k-1),:,:);
for i=1:Nodenum
for j=1:L
Ndeg(i,j)=sum(sum(Links(1:k(j),:,j)==i));
end
end
%%%%%%%%%%%%Calculate the prob of degree of every node greater than N0%%%%%
for i=1:LN0
G_than_N0(:,:,i)=(Ndeg>=N0(i))+G_than_N0(:,:,i);
end
%for i=1:L
% s=sum(Ndeg(:,i)>=N0);
% Pdmin_N=sum(Ndeg>=N0)/Nodenum+Pdmin_N;%Nodenum;%prob P(dmin>=N0)
%Pdmin=min(Ndeg)/sum(:,i);
%end
end
G_than_N0=G_than_N0/Stimes;%calculate the prob of degree of every node greater than N0
Pdmin_N=prod(G_than_N0);
%%%%%%%%%%%%%Calculate the analytical prob%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=10^6;
P_a=zeros(L,LN0);
for j=1:LN0
i=1;
for r0=10:10:Rlimit
for N=0:N0(j)-1
P_a(i,j)=((Nodenum/A)*pi*r0^2)^N/factorial(N)+P_a(i,j);
end
P_a(i,j)=(1-P_a(i,j)*exp(-(Nodenum/A)*pi*r0^2))^Nodenum;
i=i+1;
end
end
%%%%%%%%%%%%draw figure%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
plot(Rstep,Pdmin_N(:,:,1),'bo',Rstep,P_a(:,1),'r-',Rstep,Pdmin_N(:,:,2),'b*',Rstep,P_a(:,2),'r--',Rstep,Pdmin_N(:,:,3),'bsquare',Rstep,P_a(:,3),'r-.');
grid on;
legend('\it simP(d_min>=1)','\ita analytical P(d_min>=1)','\it simP(d_min>=2)','\ita analytical P(d_min>=2)','\it simP(d_min>=3)','\ita analytical P(d_min>=3)');
hold on
axis([0 Rlimit 0 1])
xlabel('range(in m)','color','b')
ylabel('prob for d_min','color','b')
title(' P(dmin>=N0 with Euclidian distance metric)')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -