课程首页 | 课程简介 | 课程大纲 | 课程讲义 | 授课教师 | 网络可视化 | 课程建设动态 | 课程资讯 | 线上课程 | 头条推荐 
   
 

代码参考 | SW小世界网络(Matlab)
2022-01-15 19:22 Jie  RCNS

function A=buildsw(N,K,p)

%Builds ring lattice with N nodes.  K is the number of neighbours TO EACH SIDE (i.e. half the average degree).

%K must be less than (N-1)/2.

%Then a proportion p of edges are randomly rewired keeping one end attached.

%Usage: A=buildsw(N,K,p)


L=N*K*p; %number rewired

A=sparse([],[],[],N,N,2*(N*K));

%B=repmat(1,N,2*K);

B=rand(N,2*K);

d=[[-(N-1):-(N-K)] [1:K]];

A=spdiags(B,d,N,N);

%A=A+A'; %could do it directed not symetric


sortnet = sort(reshape(A,N^2,1)); %list random values as vector

C = (A > sortnet(end-N*K+L)); %intact net

D = (A~=0)-C; %to be rewired

A=C+C';


[i,j]=find(D);


for c=1:length(i)

   poss=setdiff(find(~A(:,i(c))),i(c));

   k=ceil(rand*length(poss));

   A(i(c),poss(k))=1;

   A(poss(k),i(c))=1;

end


Close Window
  读取内容中,请等待...

版权所有:Research Centre of Nonlinear Science 邮政编码:430073
E-mail:liujie@wtu.edu.cn 备案序号:鄂ICP备15000386号 鄂公网安备 42011102000704号