TDSR源码程序 - matlab算法设计 - 谷速源码
下载频道> 资源分类> matlab源码> 算法设计> TDSR源码程序

标题:TDSR源码程序
分享到:

所属分类: 算法设计 资源类型: 文件大小: 3.12 KB 上传时间: 2016-01-27 19:37:48 下载次数: 7 资源积分:1分 提 供 者: 马云 TDSR源码程序
内容:
TDSR源码程序,程序员在编程的过程中可以参考学习使用,希望对IT程序员有用,此源码程序简单易懂、方便阅读,有很好的学习价值!
function TDSR
%This function simulate the concepts of Dynamic Source Routing
%The function finds path from source node(node1) to destination node(node10)
%The output of this function is the figure displaying network topology and
%the selected path from source to destination,the average trust value of
%the selected path and the number of hops
clear;
noOfNodes  =10;
figure(1);
clf;
hold on;
R =5; % node transmission range
sor =1;%source node
des =10;%destination node
X = [1 2 3 4 8 6 7 9 10 10];%nodes' x coordinates
Y = [6 2 5 8 5 1 10 2 8 5];%nodes' y coordinates
Z =[1 1 0.7 0.4 0.1 0.1 0.1 1 1 1];%nodes' trust values
 
 
%plotting network topology
for i = 1:noOfNodes
    plot(X(i), Y(i), '.');
    text(X(i), Y(i), num2str(i));
    for j = 1:noOfNodes
        distance = sqrt((X(i) - X(j))^2 + (Y(i) - Y(j))^2);
        if distance <= R % there is a link;
            matrix(i, j) =1;
            trust(i,j)=1-((Z(i)+Z(j))/2);
            line([X(i) X(j)], [Y(i) Y(j)], 'LineStyle', ':');
            matriz(i,j)=distance;
        else
            matrix(i, j) =inf;
            trust(i,j)= inf;
            matriz(i,j)=inf;
        end;
    end;
end;
 
 
[path, cost] = dijkstra(sor,des,trust);%finding the path from source to destination
trusted_path=path
trusted_path_trust=1-cost
 
trusted_path_hops=length(path)-1
trusted_path_distance=0;
for d=2:length(path)
    
    trusted_path_distance= trusted_path_distance + matriz(path(d-1),path(d));
end
trusted_path_distance;
matrix
matriz
trust
 
%plotting the selected path
for p =1:(length(path)-1)
    line([X(sor) X(path(1))],[Y(sor) Y(path(1))],'Color','r','LineWidth', 1, 'LineStyle', '-')
    line([X(path(p)) X(path(p+1))], [Y(path(p)) Y(path(p+1))], 'Color','r','LineWidth', 1, 'LineStyle','-')
    
end
grid
hold on
return;

文件列表(点击上边下载按钮,如果是垃圾文件请在下面评价差评或者投诉):

关键词: 源码 程序

Top_arrow
回到顶部
联系方式| 版权声明| 招聘信息| 广告服务| 银行汇款| 法律顾问| 兼职技术| 付款方式| 关于我们|
网站客服网站客服 程序员兼职招聘 程序员兼职招聘
沪ICP备19040327号-3
公安备案号:沪公网安备 31011802003874号
库纳格流体控制系统(上海)有限公司 版权所有
Copyright © 1999-2014, GUSUCODE.COM, All Rights Reserved