matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 23:39:59
matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
xV[kG+]:W6$N4}pCj'ٝYff%-U!m MJJBKm[$F+gvvײ@ EF==d1&:"ۍӯ{Ç{G;G?lZ8GZ yT)D:sq8U("(i֡дM%E<9yk =_~o<6cݸ$Ýohg/{x8X{6w۵^fo0 zI(}hV"uH"iT},G.LQl7))4$DX M"}ZJvjxPYЗu'k0 N]9״b)MGK9A BR R"zrD".|hH%YIrFsFuknZ@xlՉP`rCPwq.4#cFanĭ$h"e&JB2*+=R ъƩj̸c݊oBet=:ynD4*+Sp1̓#e%B")pԧYI7z;ѵOse!MiMQ|7#B"3:q"8.F.K2 ꚓm9d!2:+`4 L⒚H{̤6lT[_*!^XWÌ6TMSxS;INJ:Sѫu:6Z~IPHH Qf08؀ !Wqf),R? /wY" Iu*=菗h} 

matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.
高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p) 在这行出现问题
function [path,totalCost,farthestPreviousHop,farthestNextHop] = dijkstra_1(n,netCostMatrix,farthestPreviousHop,farthestNextHop)
visited(1:n) = 0;
distance(1:n) = inf; % it stores the shortest distance between each node and the source node;
parent(1:n) = 0;
fid=fopen('allpath.txt','w');
for s = 1:100
distance(s) = 0;
for i = 1:(n-1),
temp = [];
for h = 1:n,
if visited(h) == 0 % in the tree;
temp=[temp distance(h)];
else
temp=[temp inf];
end
end;
[t,u] = min(temp); % it starts from node with the shortest distance to the source;
visited(u) = 1; % mark it as visited;
for v = 1:n,% for each neighbors of node u;
if ( ( netCostMatrix(u,v) + distance(u)) < distance(v) )
distance(v) = distance(u) + netCostMatrix(u,v); % update the shortest distance when a shorter path is found;
parent(v) = u; % update its parent;
end;
end;
end;
for d = s:100,
path = [];
if parent(d) = 0 % if there is a path!
%path = [];
t = d;
path = [d];
while t = s
p = parent(t);
path = [p path];
if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
farthestPreviousHop(t) = p;
end;
if netCostMatrix(p,farthestNextHop(p)) < netCostMatrix(p,t)
farthestNextHop(p) = t;
end;
t = p;
end;
totalCost= distance(d);
fprintf(fid,'%d ',path); %记录源点到任意一点的最短路径
end;
%allpath(d)=path;
end
fprintf(fid,'\n');
end
fclose(fid);
return;
s是起始节点,d是目标节点
令s=1时,程序没有问题,但是加上循环for s = 1:100 时,

matlab运行出现问题,Attempted to access e(1,0); index must be a positive integer or logical.高手帮我看看以下程序吧,dijkstra算法,记录任意两点之间的最短路径,if netCostMatrix(t,farthestPreviousHop(t)) < netCostMatrix(t,p)
nit PublicTree;
interface
uses
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,Dialogs,
ComCtrls,ImgList,DB,Menus;
type
TFrameTree = class(TFrame)
tvTree:TTreeView;
ImageList1:TImageList;
procedure tvTreeExpanding(Sender:TObject; Node:TTreeNode;
var AllowExpansion:Boolean);