资源简介
关于TAODV路由协议的完整matlab程序代码以及详细注释。
代码片段和文件信息
function [pathcost]=hopbyhop(startstopadmatrix)
%This function performs hop-by-hop routing by selecting the next hop with
%the highest trust value.
%the inputs of this function are:
%start =source node
%stop= destination node
%admatrix = adjacency matrix storing the trust values of the nodes
%the function returns the selected path and the average cost of the path
%the function is used as follows:
%[pathcost]=hopbyhop(startstopadmatrix)
%NB:the function does not work correctly in some casesfurther improvements
%will done in future.
%initialisation
noOfNodes = size(admatrix 1);
rpath=[];
rpath(1)=start;
pathS=start;
parent=pathS;
cosy = 0;
[route]=hopsdij(pathSstopadmatrix);%checking if path exists between source and destination node
if (pathS~=stop && route ==1)%main loop
k=1;%counter for neighbours
i=2;%path counter
while(pathS~=stop)
B=[];%vector of neighbours and trust values
jj=1;
for j= 1:noOfNodes
if admatrix(pathS j)~=inf
B(jj1)=j;
B(jj2)=admatrix(pathSj);
jj=jj+1;
end
end
B =sortrows(B-2);
nexthop = B(k1);%nexthop with the highest trust value
chk = searchp(rpathnexthop);
if chk==1
[route]=hopsdij(nexthopstopadmatrix);
if(route==0)
k=k+1;
else
rpath(i)=nexthop;
pathS=nexthop;
k =1;
i=i+1;
end
else
k = k+1;
end
end
else
disp(‘source =dest or cannot reach destination‘)
end
path =rpath;%selected path
cost=0;
for d=2:length(path)
cost= cost+admatrix(path(d-1)path(d));
end
cost=cost/length(path);%average cost of the path
%searching for visited nodes
function c =searchp(rpnp)
counter =0;
for z=1:length(rp)
if np==rp(z)
counter=counter+1;
end
end
if counter>0
c = 0;
else
c = 1;
end
function [route]=hopsdij(pathSstopadmatrix)
if admatrix(pathSstop)~=0 || admatrix(pathSstop)~=inf
route=1;
else
route=0;
end
return
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2212 2003-07-14 21:04 TAODV\hopbyhop.m
文件 1861 2003-07-14 21:11 TAODV\TAODV.m
目录 0 2014-08-11 19:34 TAODV
----------- --------- ---------- ----- ----
4073 3
- 上一篇:KL变换matlab
- 下一篇:matlab提取视网膜血管
评论
共有 条评论