function [Paths,S] = gettraffic(G,nfrom,nto) %----------------------------------------------------------------------------- % for a given graph G, find the shortest paths from node (nfrom) to node (nto) % unoriented and unweighted graph and calculates the traffic (per segment): % node (nfrom) sends to node (nto) 1GB of data, the resulting traffic % matrix S(nnod,nnod) gives how much of the 1GB flows through each segment % S(i,j)=s means that segment between nodes (i) and (j) carries (s) GB of data %*** parameters: % G(nnod,nnod) -in- weighted adjacency matrix of the oriented graph: % G(i,j)=s if the cost of segment i-->j is 1/s % G(i,j)<>0 if i --> j exists (cost is infty) % nfrom, nto -in- nodal indices of "from" and "to" nodes % Paths{npath} -out- for each shortest path, list nodes along the path % S(nnod,nnod) -out- traffic matrix on segments %----------------------------------------------------------------------------- % mail: ales.janka@hefr.ch HEIA-FR 2015 nnod = size(G,1); if min(nto,nfrom)<1 error('(nto) and (nfrom) should be >= 1!'); end; if max(nto,nfrom)>nnod error('(nto) and (nfrom) should be <= nnod!'); end; %*** get all shortest paths from node (nfrom) to node (nto): [Paths, ndist] = dijkstraties(G,nfrom,nto); if (ndist>1e10) Paths = []; end; %*** calculate the traffic matrix S: S = 0.*G; npath = size(Paths,1); for ipath = 1:npath path = Paths{ipath}'; S = S + sparse(path(1:end-1),path(2:end),1/npath,nnod,nnod); end %if norm((G==0).*S,inf)>1e-16 % [nfrom nto] % G = full(G) % S = full(S) % error('nonexisting traffic segments!') %end; % S = S+S'; %*** check if everything is OK: ---> not anymore for non-oriented graphs % if (abs(sum(sum(S))/ndist-2)>1e-6) % error('thewe is something skwewy awound hewe!') % end;