Created
September 14, 2015 05:31
-
-
Save ivanchoff/f78798ca31939ac1cddf to your computer and use it in GitHub Desktop.
implementation of dijkstra algorithm in octave
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
function[dist previo] = dijkstraOctave(Adj,inicio) | |
n = size(Adj,1); | |
nodos_visitados = 0; | |
dist(1:n) = inf; | |
visited(1:n) = 0; | |
previo(1:n) = -1; | |
Q(1:n) = inf; | |
dist(inicio) = 0; | |
Q(inicio) = 0; | |
while sum(visited)~=n | |
[x posx] = min(Q); | |
%if visited(posx)==0 | |
% continue; | |
%end | |
visited(posx) = 1; | |
for i=1:n | |
if Adj(posx,i)>0 && visited(i)==0 | |
if dist(posx) + Adj(posx,i) < dist(i) | |
dist(i) = dist(posx) + Adj(posx,i); | |
previo(i) = posx; | |
Q(i) = dist(i); | |
end | |
end | |
end | |
Q(posx) = inf; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment