1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| function [sp, spcost] = dijkstra_all(AdjMatrix, s, d)
n=size(AdjMatrix,1); S(1:n) = 0; dist(1:n) = inf; prev = zeros(50,n); count(1:n)=0;
dist(s) = 0;
while sum(S)~=n candidate=[]; for i=1:n if S(i)==0 candidate=[candidate dist(i)]; else candidate=[candidate inf]; end end [u_index u]=min(candidate); S(u)=1; for i=1:n if(dist(u)+AdjMatrix(u,u)+AdjMatrix(u,i))<dist(i) dist(i)=dist(u)+AdjMatrix(u,u)+AdjMatrix(u,i); prev(:,i)=prev(:,i).*0; prev(1,i)=u; count(i)=1; else if ((dist(u)+AdjMatrix(u,u)+AdjMatrix(u,i))==dist(i))&&(dist(i)~=inf)&&(u~=i) if count(i)<49 count(i)=count(i)+1; end prev(count(i),i)=u; end end end end
sp=[]; stack=[]; num=[];
stack = [d,zeros(1,9)]; num=[1,zeros(1,9)]; spcost = dist(d);
while stack(1) ~= 0 if stack(1)==s sp=[sp;stack]; stack=[stack(2:10),0]; num=[num(2:10),0]; continue; end tmp=prev(num(1),stack(1)); if tmp==0 stack=[stack(2:10),0]; num=[num(2:10),0]; continue; else num(1)=num(1)+1; stack=[tmp,stack(1:9)]; num=[1,num(1,1:9)]; end end
|