Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wenhuizhang/7164650 to your computer and use it in GitHub Desktop.
Save wenhuizhang/7164650 to your computer and use it in GitHub Desktop.
Find the shortest path_Dijkstra Algorithm
%http://en.wikipedia.org/wiki/Dijkstra's_algorithm
%W stands for the pic/path weight distibution
%n total number of spots
function [l,z]=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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment