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

📄 routing.m

📁 在复杂网络中
💻 M
字号:

% %%%%%%%%%%%%%%%求最短路径%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% 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
% 
% %%%%%%%%%%%%结束求最短路径%%%%%%%%%%%%%%%%%%%%%%%%%
% lamda=0.01;
% d=N*lamda;
tic;
alapha=0.7;

N=600; 
R=350;%200;
%R=11001000,300,400,600;
F=1000;
D=0;
for i=1:N
    Cii(i)=sum(Nodes(:,i));
end
list=zeros(F*R,2);

Packet=zeros(N);
aa=zeros(F);
% for i=1:N
%     Packet(i)=0;
% %   list2(i,1)=i;
% end
for T=1:F
    list2=zeros(N);
%      for i=1:N
%          list2(i,2)=0;
%      end
     for i=1:R
         b=rand(1,2)*N;
         B(i,:)=ceil(b);  
         while B(i,1)==B(i,2)   %选择R对源端和目的端,且源端和目的端不是同一点
                  b=rand(1,2)*N;
                  B(i,:)=ceil(b);   
         end
     end  
         list((T-1)*R+1:T*R,1:2)=B; %依次把选择的R对源端和目的端付给list
     for i=1:R;
         Packet(B(i,1))=Packet(B(i,1))+1; %选择的R个源端的数据包个数分别加1
     end
     D=D+R;  
     for i=1:R*T
         t2=1;
         e=100;
         ts=list(i,1);
         td=list(i,2);
         if ts==0
            continue;
         end
         list2(ts)=list2(ts)+1;    %list2第二列加一
         if list2(ts)>10   %第ts个节点对应的数据包超过了此节点的最大处理能力时,此时不进行传输
%             if list2(ts,2)>5
            continue;
         end        
          x=1;
          for k=1:N
              if Nodes(ts,k)==1
                 if k==td      %如果ts的邻居节点有目的节点,传递成功,源端赋0
%                   w=w-1;
                    D=D-1;
                    list(i,1)=0;
                    t2=0; 
                    continue;
                  end
              end       % if  Spath(k,td)<N
          end
          if t2~=0
              for k=1:N
                   if Nodes(ts,k)==1
                      Short=Spath(k,td);
                      e=alapha*Short+(1-alapha)*Packet(k)/Cii(k);
%                       e=alapha*Short+(1-alapha)*Packet(k)/5;
                      if x==1
                         min=e;
                         x=x+1; 
                         t2=k;
                      end
                      if e<min
                          min=e;
                          t2=k;
                      end
                  end
              end
   %执行路由策略,确定下一节点t2(i) 
                Packet(t2)=Packet(t2)+1;   
                list(i,1)=t2;            
           end
         Packet(ts)=Packet(ts)-1 ;
%        list2(ts,2)=list2(ts,2)-1;      
      end
      aa(T)=D;
end
    semilogy(1:F,aa,'b-');
   hold
%  end
toc;

⌨️ 快捷键说明

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