matlab输出 inf,为什么输出的是-inf,不应该是个值吗

clear all

clc

load('r.mat')

transmat=r;

pathS=376;

pathE=2584;

%   pathS: 所求最短路径的起点

%   pathE :所求最短路径的终点

%   transmat: 图的转移矩阵或者邻接矩阵,应为方阵

if ( size(transmat,1) ~= size(transmat,2) )

error( 'detect_cycles:Dijkstra_SC', ...

'transmat has different width and heights' );

end

% 初始化:

%  noOfNode-图中的顶点数

%  parent(i)-节点i的父节点

%  distance(i)-从起点pathS的最短路径的长度

%  queue-图的广度遍历

noOfNode = size(transmat, 1);

for i = 1:noOfNode

parent(i) = 0;

distance(i) =Inf;

end

queue = [];

% Start from pathS

%

for i=1:noOfNode

if transmat(pathS, i)~=Inf

distance(i) = transmat(pathS, i);

parent(i)   = pathS;

queue       = [queue i];

end

end

% 对图进行广度遍历

while length(queue) ~= 0

hopS  = queue(1);

queue = queue(2:end);

for hopE = 1:noOfNode

if distance(hopE) > distance(hopS) + transmat(hopS,hopE)

distance(hopE) = distance(hopS) + transmat(hopS,hopE);

parent(hopE)   = hopS;

queue= [queue hopE];

end

end

end

% 返回最短路径的权和

r_cost = distance(pathE);

为什么输出的是-inf,不应该是个值吗?

16ae97300fb26d5150aca66cd3888cb6.gif

2014-8-15 00:15 上传

点击文件名下载附件

1.22 MB, 下载次数: 26

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值