This is an implementation of Dijkstra algorithm. if Distance = Inf*ones(N,1) , what is the value of Distance(CurrentNode)?? And could someone also give an example value of src and ConMat? Thank you!
while (nVisited <N)
Visited(CurrentNode) = 1;
for i=1:N
if (ConMat(CurrentNode,i)>0)
temp = ConMat(CurrentNode,i) + **Distance(CurrentNode)**;
if (temp< Distance(i))
Distance(i) = temp;
PrevNode(i) = CurrentNode;
end
end
end
Distance = Inf * ones(N,1)returnsan array with size Nx1.
CurrentNodecontains the index of the vertice your algorithm is computing the path. Suppose you have a simple graph, such as the following (stolen from Wikipedia):Your initial
srcis the node you start your search – in this case, index1. For your initial node,Distanceis0. So,Distance( 1 ) = 0, while the others hasDistanceequals toInf(Distance(src+1:end) = Inf).ConMatis your graph in a matrix representation.