⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c_ba.m

📁 可变聚类无标度网络源代码。提高了BA网络的聚类系数。
💻 M
字号:
%   This is the BA_Scale Model by Fan Jin.
%   At first there are only m nodes and no edge, then the m+1st node is
%   connected with the above m nodes
%   usage: Nodes = BA(N,m)
%   the parameter:N----network size
%                 m----a new node with m new edges
%   can randomly initialize the N and the m by yourself
%   the  diagonal elements of the matrix also equal to -degree
%   Nodes----the final coupling matrix
%   The following message(s) may not be displayed correctly for they contain Chinese charactors.
%   list----生成的一个辅助向量,该向量中的元素为每条边端点的节点。for example, 假设网络中节点4的度为7,则在list向量中会存在7个4,而这7个4的位置不一定是连续在一起的。
%   preferential attachment体现在随机的从list向量中选取元素,选中哪个元素,该元素表示的节点即被选中。由于list向量中每个节点的个数与它的度有关,因此,度越大的点被选中的概率越大。
% >[Nodes,Spath]=C_BA(100,3,0) 在command window中输入!!!!
function [Nodes,Spath]=C_BA(N,m,q)
%  N=100;
% m=3;
% q=0;
Nodes=zeros(N);
Cii=zeros(1,N);
%Nodes=sparse(N);
for i=1:m
    Nodes(i,m+1)=1;
    Nodes(m+1,i)=1;
    list1(i)=i;
end
for i=m+1:2*m
    list1(i)=m+1;
end
for n=m+2:N                  % start from m+2 to grow the network
    t=2*m*(n-m-1) ;           % for list1, every time t increases 2m
    % t=m*(n-m-1);
    for i=1:m
        list1(t+i)=n;          % in the list1, every time the above m is n, it represents that the nth nodes is connected to other m nodes
    end
    k=1;
    while k<m+1               % grow other m nodes
        p(k)=round((t+1)*rand(1));         %    random choose an integer from 1~N
        if p(k)>0&p(k)<(t+1)
            if Nodes(n,list1(p(k)))==0
                list1(t+m+k)=list1(p(k));
                Nodes(n,list1(p(k)))=1;
                Nodes(list1(p(k)),n)=1;
                u=list1(p(k));
                k=k+1;
                while k<m+1
                    pt=rand;
                    if  pt>q % where 1-q is the probability of PA
                        break;
                    end
                    a= Nodes(u,1:n-1);
                    b=Nodes(n,1:n-1);
                    c=find(a&b==1);
                    a(c)=0;
                    d=find(a==1);
                    e=size(d);
                    f=e(2);
                    if f==0
                        break;
                    end
                    g=1+floor(f*rand);
                    h=d(g);
                    list1(t+m+k)=h;
                    Nodes(n,h)=1;
                    Nodes(h,n)=1;
                    k=k+1;
                end
        end   %end for j
    end    %end for k
end %end for n
end
%Write_Sparse_Matrix(Nodes,['BA',num2str(N),'.txt']);
%Write_into_Pajek(Nodes,['BA',num2str(N),'.net']);
% for i=1:N
%     Nodes(i,i)=-sum(Nodes(:,i));
%     Cii(i)=Nodes(i,i);
% end
% % list
for i=1:N
     Cii(i)=sum(Nodes(:,i));
   
end
%%%%%%%%%%%%%%%求最短路径%%%%%%%%%%%%%%%%%%%%%%%%%
% function [Nodes,Cii]=C_BA(3,0)
A=Nodes;
for i=1:N
    for j=1:N
        Spath(i,j)=0;
    end
end
for l=1:N
  for i=1:N
    for j=1:N
      if A(i,j)>=1&Spath(i,j)==0
          Spath(i,j)=l;
      end
    end
  end
  A=A*Nodes;
end   
  for j=1:N
        Spath(j,j)=0;
  end

%%%%%%%%%%%%结束求最短路径%%%%%%%%%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -