zzh121300 发表于 2009-3-26 14:41

基于matlab Dijkstra算法的实现

function =Dijkstra(W)
n = size (W,1);
for i = 1 :n
    l(i)=W(1,i);
    z(i)=1;
end
i=1;
while i<=n
    for j =1 :n
        if l(i)>l(j)+W(j,i)
            l(i)=l(j)+W(j,i);
            z(i)=j;
            if j                i=j-1;
            end
        end
    end
    i=i+1;
end
% W =[ 0     2     1     8   Inf   Inf   Inf   Inf
%     2     0   Inf     6     1   Inf   Inf   Inf
%      1   Inf     0     7   Inf   Inf     9   Inf
%      8     6     7     0     5     1     2   Inf
%    Inf     1   Inf     5     0     3   Inf     9
%    Inf   Inf   Inf     1     3     0     4     6
%    Inf   Inf     9     2   Inf     4     0     3
%    Inf   Inf   Inf   Inf     9     6     3     0  ];
页: [1]
查看完整版本: 基于matlab Dijkstra算法的实现