?? 2ddeployment.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 + -