%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % sp_dijkstra % %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % T,H are tail and head nodes of all arcs, COST is the cost vector. % A{} are the out-arc cells initialized by netdata. % s is the source node s=input('give source node s:'); d=inf*ones(1,N); % initialization d(s)=0; pred=zeros(1,N); ULAB=1:N; % ULAB--unlabelled set while ~isempty(ULAB) [dmin,ind]=min(d(ULAB)); i=ULAB(ind); ULAB=setdiff(ULAB,[i]); kk=A{i}; jj=H(kk); [d(jj), index]=min([d(jj); d(i)+COST(kk)']); % we create a 2 by |jj| matrix pred(jj(find(index==2)))=i; % index =1 or 2, which records % the row-number that hits the minimum. end%if pred d