PDF Publication Title:
Text from PDF Page: 171
weights) are non-negative. The algorithm explores the graph in a breadth-first manner based on the current shortest distance from the source. To pick the next vertex to explore, we need to find the closest vertex to the source, add or update the distance to all their neighbors to the current set of known vertices, and repeat. Finding the next vertex to explore based on the current distances can be done with the heap data structure in the previous section. Using the heap, Dijkstra’s algorithm is only a few lines of code. 1 function [d pred]=dijkstra_slow(A,u) 2 At = A’; n = size(At,1); % transpose for row access 3 d=Inf*ones(n,1); T=zeros(n,1); L=zeros(n,1); pred=zeros(1,n); % allocate heap 4 n=1; T(n)=u; L(u)=n; % n is now the size of the heap 5 % enter the main dijkstra loop 6 d(u) = 0; 7 while n>0 8 [v,n,T,L,d] = heappop(n,T,L,d); % find the closest vertex 9 % for each vertex adjacent to v, relax it 10 [si 11 for 12 13 14 15 16 17 18 19 20 21 end 22 end sj sv]=find(At(:,v)); ei=1:length(si) w=si(ei); ew=sv(ei); % relax edge (v,w,ew) if d(w)>d(v)+ew d(w)=d(v)+ew; pred(w)=v; % ei is the edge index % w is the target, ew is the edge weight % check if w is in the heap, insert if not, else update if L(w)==0, [n,T,L,d] = heapinsert(w,d(w),n,T,L,d); else [n,T,L,d] = heapupdate(w,n,T,L,d); end end Just like the previous description, we find the closest vertex and compute the distance to each neighbor. We then update the heap and continue. This function has respectable performance: load_gaimc_graph(’cs-stanford’) % 9914 by 9914 with 36854 edges (directed) A = sprand(A); rand(’state’,0); vs = ceil(size(A,1)*rand(100,1)); tic, for i=1:100, [d pred] = dijkstra_slow(A,i); end, toc Elapsed time is 10.748844 seconds. If we remove the function calls for the heap and place the function code in-line,17 then the performance improves considerably. Elapsed time is 3.459063 seconds. 17 We have omitted the source code for this case because it gets rather verbose with all the heap manipulations. 6.4 ⋅ gaimc 149PDF Image | Instagram Cheat Sheet
PDF Search Title:
Instagram Cheat SheetOriginal File Name Searched:
pagerank-sensitivity-thesis-online.pdfDIY PDF Search: Google It | Yahoo | Bing
Cruise Ship Reviews | Luxury Resort | Jet | Yacht | and Travel Tech More Info
Cruising Review Topics and Articles More Info
Software based on Filemaker for the travel industry More Info
The Burgenstock Resort: Reviews on CruisingReview website... More Info
Resort Reviews: World Class resorts... More Info
The Riffelalp Resort: Reviews on CruisingReview website... More Info
CONTACT TEL: 608-238-6001 Email: greg@cruisingreview.com (Standard Web Page)