• 大小: 4KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-08
  • 语言: Matlab
  • 标签: DVHOP  

资源简介

原始DVHOP算法源程序,有详细的注释,算法简洁,运行速度快。

资源截图

代码片段和文件信息

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  DV-Hop算法  ~~~~~~~~~~~~~~~~~~~~~~~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% BorderLength-----正方形区域的边长,单位:m
% NodeAmount-------网络节点的个数
% BeaconAmount---信标节点数
% Sxy--------------用于存储节点的序号,横坐标,纵坐标的矩阵
%Beacon----------信标节点坐标矩阵;BeaconAmount*BeaconAmount
%UN-------------未知节点坐标矩阵;2*UNAmount
% Distance------未知节点到信标节点距离矩阵;2*BeaconAmount
%h---------------节点间初始跳数矩阵
%X---------------节点估计坐标初始矩阵X=[xy]‘
% R------------------节点的通信距离,一般为10-100m

clearclose all;
BorderLength=100;
NodeAmount=100;
BeaconAmount=20;
UNAmount=NodeAmount-BeaconAmount;
R=30;
% D=zeros(NodeAmountNodeAmount);%未知节电到信标节点距离初始矩阵;BeaconAmount行NodeAmount列
h=zeros(NodeAmountNodeAmount);%初始跳数为0;BeaconAmount行NodeAmount列
X=zeros(2UNAmount);%节点估计坐标初始矩阵

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~在正方形区域内产生均匀分布的随机拓扑~~~~~~~~~~~~~~~~~~~~
C=BorderLength.*rand(2NodeAmount);
%带逻辑号的节点坐标
Sxy=[[1:NodeAmount];C];
Beacon=[Sxy(21:BeaconAmount);Sxy(31:BeaconAmount)];%信标节点坐标
UN=[Sxy(2(BeaconAmount+1):NodeAmount);Sxy(3(BeaconAmount+1):NodeAmount)];%未知节点坐标
%画出节点分布图
plot(Sxy(21:BeaconAmount)Sxy(31:BeaconAmount)‘r*‘Sxy(2(BeaconAmount+1):NodeAmount)Sxy(3(BeaconAmount+1):NodeAmount)‘k.‘)
xlim([0BorderLength]);
ylim([0BorderLength]);
title(‘* 红色信标节点 . 黑色未知节点‘)
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~初始化节点间距离、跳数矩阵~~~~~~~~~~~~~~~~~~~~~~
for i=1:NodeAmount
    for j=1:NodeAmount
        Dall(ij)=((Sxy(2i)-Sxy(2j))^2+(Sxy(3i)-Sxy(3j))^2)^0.5;%所有节点间相互距离
        if (Dall(ij)<=R)&(Dall(ij)>0)
            h(ij)=1;%初始跳数矩阵
        elseif i==j
            h(ij)=0;
        else h(ij)=inf;
        end
    end
end
%~~~~~~~~~~~~~~~~~~

评论

共有 条评论