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

📄 routing1.m

📁 无线传感器网络的可靠路由算法
💻 M
字号:
clear;
N=100;
M=100;
for i=1:N
    x(i)=rand(1)*M;
    y(i)=rand(1)*M;
end
x(1)=M*0.95;y(1)=M*0.95;
neighbour=zeros(N,N*0.2);
for i=1:N
    n(i)=1;
   for j=1:N
      if (x(i)-x(j))^2+(y(i)-y(j))^2<M^2*0.04 & i~=j
          neighbour(i,n(i))=j;
          n(i)=n(i)+1;
      end
   end
end
% d0=1;
% xi=0;
n0=2;
bn=1;
r=2;
rou=2/20/8;
f=20;
c=zeros(100,1);
c(1)=1;
for loop=1:20
    for i=2:100
        for m=1:n(i)-1
            j=neighbour(i,m);
            d(i,j)=sqrt((x(i)-x(j))^2+(y(i)-y(j))^2);
            g(i,j)=10+10*n0*log(10/d(i,j));
            p(i,j)=(1-1/2*exp(-10^(0.1*g(i,j))*bn/2/r))^(rou*8*f);
            ctemp=p(i,j)*c(j);
            if c(i)<ctemp
               c(i)=ctemp;
               parent(i)=j;
            end
        end
    end
end
parent(1)=1;
% for j=1:3
%     for i=1:100
%         u(i,j)=x(10*j)+20*cos(2*pi*i/100);
%         v(i,j)=y(10*j)+20*sin(2*pi*i/100);
%     end
% end
% for i=1:N
%      cordinate_x(1)=x(i);
%      cordinate_x(2)=x(parent(i));
%      cordinate_y(1)=y(i);
%      cordinate_y(2)=y(parent(i));
%      line(cordinate_x,cordinate_y);     
%      text(x(i)+2,y(i)+2,num2str(i));
% end
% i=[1:100];
%  plot(i,c,'-o');
for i=1:10
     count(i)=0;
    for j=1:100
        if c(j)>=(i-1)*0.1 && c(j)<i*0.1
            count(i)=count(i)+1;
        end
    end
 end
% i=[0:0.1:0.9];
%  plot(i,count,'-o');
 p=ones(100,1);
 e=ones(100,1);
 for i=1:100
     j=i;
     sum(i)=0;
     while j~=1
         sum(i)=sum(i)+p(j)/e(j);
         j=parent(j);
     end
 end
 i=[1:100];
 plot(i,sum,'-o');
     
         

⌨️ 快捷键说明

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