Created
October 26, 2013 02:32
-
-
Save wenhuizhang/7164650 to your computer and use it in GitHub Desktop.
Find the shortest path_Dijkstra Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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