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

📄 2ddeployment.asv

📁 平面型节点散布仿真
💻 ASV
字号:
%%%%%%%%%%%%%%%%%    动态部署节点算法仿真V1.0    %%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%  2008.3.27  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 300*300m无障碍物区中进行移动节点部署
% 初始化区域为10*10m,然后,经计算展开到300*300m场
% 节点传感半径25m;通讯半径50m
% 节点能感知GPS信息
clf;
lon=132;         %GPS经度基点(需为整数)
lan=56;          %GPS纬度基点(需为整数)
n=300;              % the square of mobile  
x=rand(1,n);        % the X position of mobile nodes 
y=rand(1,n);        % the Y position of mobile nodes 
rs=25;              % the sensor radius
rc=50;              % the communication radius
rd=2;               % the detection obstacle radius
robs=1;               % the voiding obstacle R
rspan=50;              % the span between two nodes

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% 初始化场景 %%%%%%%%%%%%%%%%%%
% initialization position of node
for i=1:0.1*n       %0.1n=30个移动节点
    x0(i)=lon+0.1*n*x(i);  %初始化在最小方格30*30中
    y0(i)=lan+0.1*n*y(i);
end
% 显示初始化节点位置,随机分布
rand('state',5);
x = rand(1,10); y = rand(1,10);
voronoi(x,y)
voronoi(x0(i),y0(i));
for i=1:0.1*n
    if 0
    plot(gnode.x(i),gnode.y(i),'s','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);    
    text(gnode.x(i),gnode.y(i),'gnode.i');    %???????    
    end
    hold on;
end
grid on;
%  初始化时的通讯链路
for i=1:0.1*n
    for j=2:0.1*n
     if i~=j
      dij=sqrt((x0(i)-x0(j))^2+(y0(i)-y0(j))^2);       %i节点和j节点之间的距离
      if (dij<=rc)                                     %小于通讯距离则可以通讯,存在通讯链路
         x=[x0(i),x0(j)];
         y=[y0(i),y0(j)];       
         line(x,y);                                    %短线表示通讯链路
         hold off;
      end
     end
    end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%不考虑初始能量损耗,按均等计算运算,采用势场函数控制节点速度。
%h=figure(2);
%%for i=1:0.1*n
%%    d=sqrt((x0(i)-lon)^2+(y0(i)-lan)^2);
%%end
%%for i=1:0.1*n
%%    if d(i)<d(i-1)                       %找到基点最近的节点号?? 不能通过编绎
%%       inn=i;
%%    else 
%%       inn=i-1;
%%    end
%%end
for i=1:0.1*n
    d(0.1*n)=sqrt((x0(i)-lon)^2+(y0(i)-lan)^2);
end
subplot(2,2,2);
for i=1:0.1*n
    xm(i)=((50*i)-x0(io))+rspan;    %以x[0],y[0]为基准点开始??以到基点最近的点为基准点展开部署为好!
    ym(i)=((50*i)-y0(io))+rspan;
    step=50;                               % 总步长控制划线点
    h=1:0.01:step;
    x=[xm(i-1),xm(i)];
    y=[ym(i-1),ym(i)];
    line(xm,ym);
    hold on;
end

%执行并输出


⌨️ 快捷键说明

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