资源简介

使用matlab编写,无线传感器网络的泛洪算法

资源截图

代码片段和文件信息

function [] = DFS(rTTL)
global connMatrix;
global visited;
global xLocation;
global yLocation;
global floodProb;
global savedTransmission;
global distMatrix;
global ETX;
global ERX;
global Efs;
global Emp;
global EDA;
global do;
global Energy;
global numOfNodes;
global radius;
global radius_s;
% Get the number of reachable neighbors
connMatrix = zeros(1numOfNodes); 
radius_temp=radius;
index=find(distMatrix(r:)<=radius);
if (length(index)==0)%在半径范围找不到节点
    radius_temp=radius+radius_s;
    while(length(find(distMatrix(r:)<=radius_temp))==0)
          radius_temp=radius_temp+radius_s;
    end                
end
connMatrix =(distMatrix(r:)<=radius_temp);
neighborNodes = find(connMatrix(:) == 1);%距离小于门限的坐标
% Get the unreached neighbors
neigbborNodes = intersect(neighborNodes find(visited(:) == 0));%找到可访问并且距离近的
% for k = 1:length(neighborNodes)
%     
% end;

for k = 1:length(neighborNodes)
    if (visited(neighborNodes(k)) == 0)
        if(distMatrix(rneighborNodes(k))>do)
           Energy(r)=Energy(r)-( ETX*(4000) + Emp*4000*(distMatrix(rneighborNodes(k)).^4)); 
        end;
        if(distMatrix(rneighborNodes(k))<=do)
           Energy(r)=Energy(r)-( ETX*(4000) + Emp*4000*(distMatrix(rneighborNodes(k)).^2)); 
        end;
        Energy(neighborNodes(k))=Energy(neighborNodes(k))-((ERX + EDA)*4000);
        
        TTL=TTL-1;
        if(neighborNodes(k)==numOfNodes|TTL==0)%当传给中心点或TTL为零时结束
            break;
        end;
        
        visited(neighborNodes(k)) = 1;
        DFS(neighborNodes(k)TTL);
        
    end;
end;



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        1664  2012-07-07 09:26  DFS.m
     文件        2097  2012-07-07 09:32  flooding.m

评论

共有 条评论