📄 connect_k.asv
字号:
%**************************************************************************
%** File name : connect_k.m
%** Author : Liufengwei (English name:andy)
%** Creation date : 2006,6,13
%** Modified date: 4,22,2007,Sunday
%** Parameter explanation : See the note in the program
%**************************************************************************
% ** This simulation is done to investigate the probability of minimun network degree greater than n0
% analyzed in paper<On the minimum node degree and connectivity of a wireless multihop network>
% ** Model: Distribute n=500 nodes in 1000*1000m^2 accoring to uniform distribution;
% there is an edge between nodes if their distance is less than r0;We calculate the degree of every nodes
% ** Goal: simulate the formula in paper<On the minimum node degree and connectivity of a wireless multihop network>
% ** Explanation : based on Euclidian distance
%** Program process: initialize simulation parameter, then
%************************************************************************
%On the minimum node degree and connectivity of a wireless multihop network%
%*Report research simulation***********%%%%%%%%%%%%%%%%%%%%%%%%
%************simulation of K-connectivity*************************
%********1000*1000m^2,n=500 nodes ,radio range r0,minimum node degree dmin*
%%%%%%%%%%%%%%%%%%Date 2006,6,13--By Liu FengWei%%%%%%%%%%%%%%%%%%%%%%%%%%%
%function
Nodenum=1000; %number of nodes
K=1; %K connectivity
Rlimit=150;
Rstep=[10:10:Rlimit]; %radio range
L=length(Rstep); %number of radio range
NodeXY=1000*rand(Nodenum,2);%coordinates of node
sumlinks=Nodenum*(Nodenum-1)/2;
Links=zeros(sumlinks,2,L);
%Ndeg=zeros(Nodenum,L); %record degree of every node
Lnum=ones(L,1); %index for links number for every radio range
m=1;
P_k=zeros(L,1); %prob of k connectivity
%%%%%%%%%%%%%%%%%%%%%%%%%Generate links%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%if the distance between two nodes smaller than r0, link is created%%%%%%
for r0=10:10:Rlimit
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(Lnum(m),:,m)=[i j];
Lnum(m)=Lnum(m)+1;
end
end
end
m=m+1;
end
%%%%%%%%%%%%%%Calculate k connectivity of every radio range%%%%%%%%%%%%%%%
Nconnect=zeros((Nodenum-1),(Nodenum-1),L); % record the sum of connectivity
temp=zeros(1,(Nodenum-1)); %just for temp---no extra usness
for m=1:L
for i=(Nodenum-1):-1:1 %From last node--for its simplicity
L_Link=sum(Links(1:Lnum(m),1,m)==i); %number of nodes that connect node i
if(L_Link)
index=find(Links(1:Lnum(m),1,m)==i); %find the index of the node that connect node i
%%%%record the node connecting node i%%%%%%%%%
Nconnect(i,1:L_Link,m)=Links(index,2,m); %record the links of the node connecting node i now
k=1;
for k=1:L_Link %find the node in Nconnect(i,:,m)
CN_index=Links(index(k),2,m); %Connecting node of index(k)
if(CN_index<Nodenum) %node 500 doesn't connect any node except for node 499
temp=Nconnect(CN_index,:,m); %temporarily record the links of node CN_index
if(any(temp))
Dnode=0; %delete node number
for d=1:L_Link
D_index=find(temp==Nconnect(i,d,m)); %find delete index of the dth node
temp(D_index)=[]; %delete overlap node
Dnode=Dnode+length(D_index); %the number of node that is deleted
end
L_temp=sum(temp~=0); %the number of nodes in temp
C_start=L_Link;
%disp(L_Link)
L_Link=L_Link+L_temp; %end length
Nconnect(i,(C_start+1):L_Link,m)=temp(1:L_temp);
% C_start=L_Link;
end
%temp=zeros(1,(Nodenum-1)); %just for temp---no extra usness
end
end
end
end
end
%%%%%%%%%%%%Calculate the prob of k connectivity%%%%%%
%for i=1:L
% s=sum(sum(Nconnect(:,:,i)>0));
P_k=squeeze(sum(sum(Nconnect>0)))/sumlinks; %prob P(dmin>=N0)
%Pdmin=min(Ndeg)/sum(:,i);
%end
%%%%%%%%%%%%%%%%%%%%%draw figure%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
plot(Rstep,P_k,'ro-')
grid on;
axis([0 Rlimit 0 1])
xlabel('range(in m)','color','b')
ylabel('prob for Connect_k','color','b')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -