資源簡介
能求出任意兩點間所有最短路徑。數模時編寫。考慮鄰接矩陣中主對角線數據(雖然一般情況都取零)。更具實用性
代碼片段和文件信息
function?[sp?spcost]?=?dijkstra_all(matriz_costo?s?d)
%?This?is?an?implementation?of?the?dijkstra磗?algorithm?wich?finds?the?
%?minimal?cost?path?between?two?nodes.?It磗?supoussed?to?solve?the?problem?on?
%?possitive?weighted?instances.
%?the?inputs?of?the?algorithm?are:
%farthestNode:?the?farthest?node?to?reach?for?each?node?after?performing
%?the?routing;
%?n:?the?number?of?nodes?in?the?network;
%?s:?source?node?index;
%?d:?destination?node?index;
%For?information?about?this?algorithm?visit:
%http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
%This?implementatios?is?inspired?by?the?Xiaodong?Wang‘s?implememtation?of
%the?dijkstra‘s?algorithm?available?at
%http://www.mathworks.com/matlabcentral/fileexchange
%file?ID?5550
%Author:?Jorge?Ignacio?Barrera?Alviar.?April/2007
n=size(matriz_costo1);
S(1:n)?=?0;?????%s?vector?set?of?visited?vectors
dist(1:n)?=?inf;???%?it?stores?the?shortest?distance?between?the?source?node?and?any?other?node;
prev?=?zeros(50n);?%?Previous?node?informs?about?the?best?previous?node?known?to?reach?each??network?node?
count(1:n)=0;
dist(s)?=?0;
while?sum(S)~=n
????candidate=[];
????for?i=1:n
????????if?S(i)==0
????????????candidate=[candidate?dist(i)];
????????els
評論
共有 條評論