annotate toolboxes/FullBNT-1.0.7/graph/pred2path.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function rte = pred2path(P,s,t)
Daniel@0 2 %PRED2PATH Convert predecessor indices to shortest paths from node 's' to 't'.
Daniel@0 3 % rte = pred2path(P,s,t)
Daniel@0 4 % P = |s| x n matrix of predecessor indices (from DIJK)
Daniel@0 5 % s = FROM node indices
Daniel@0 6 % = [] (default), paths from all nodes
Daniel@0 7 % t = TO node indices
Daniel@0 8 % = [] (default), paths to all nodes
Daniel@0 9 % rte = |s| x |t| cell array of paths (or routes) from 's' to 't', where
Daniel@0 10 % rte{i,j} = path from s(i) to t(j)
Daniel@0 11 % = [], if no path exists from s(i) to t(j)
Daniel@0 12 %
Daniel@0 13 % (Used with output of DIJK)
Daniel@0 14
Daniel@0 15 % Copyright (c) 1998-2001 by Michael G. Kay
Daniel@0 16 % Matlog Version 5 22-Aug-2001
Daniel@0 17
Daniel@0 18 % Input Error Checking ******************************************************
Daniel@0 19 error(nargchk(1,3,nargin));
Daniel@0 20
Daniel@0 21 [rP,n] = size(P);
Daniel@0 22
Daniel@0 23 if nargin < 2 | isempty(s), s = (1:n)'; else s = s(:); end
Daniel@0 24 if nargin < 3 | isempty(t), t = (1:n)'; else t = t(:); end
Daniel@0 25
Daniel@0 26 if any(P < 0 | P > n)
Daniel@0 27 error(['Elements of P must be integers between 1 and ',num2str(n)]);
Daniel@0 28 elseif any(s < 1 | s > n)
Daniel@0 29 error(['''s'' must be an integer between 1 and ',num2str(n)]);
Daniel@0 30 elseif any(t < 1 | t > n)
Daniel@0 31 error(['''t'' must be an integer between 1 and ',num2str(n)]);
Daniel@0 32 end
Daniel@0 33 % End (Input Error Checking) ************************************************
Daniel@0 34
Daniel@0 35 rte = cell(length(s),length(t));
Daniel@0 36
Daniel@0 37 for i = 1:length(s)
Daniel@0 38 if rP == 1
Daniel@0 39 si = 1;
Daniel@0 40 else
Daniel@0 41 si = s(i);
Daniel@0 42 if si < 1 | si > rP
Daniel@0 43 error('Invalid P matrix.')
Daniel@0 44 end
Daniel@0 45 end
Daniel@0 46 for j = 1:length(t)
Daniel@0 47 tj = t(j);
Daniel@0 48 if tj == s(i)
Daniel@0 49 r = tj;
Daniel@0 50 elseif P(si,tj) == 0
Daniel@0 51 r = [];
Daniel@0 52 else
Daniel@0 53 r = tj;
Daniel@0 54 while tj ~= s(i)
Daniel@0 55 if tj < 1 | tj > n
Daniel@0 56 error('Invalid element of P matrix found.')
Daniel@0 57 end
Daniel@0 58 r = [P(si,tj) r];
Daniel@0 59 tj = P(si,tj);
Daniel@0 60 end
Daniel@0 61 end
Daniel@0 62 rte{i,j} = r;
Daniel@0 63 end
Daniel@0 64 end
Daniel@0 65
Daniel@0 66 if length(s) == 1 & length(t) == 1
Daniel@0 67 rte = rte{:};
Daniel@0 68 end
Daniel@0 69
Daniel@0 70 %rte = t;
Daniel@0 71 while 0%t ~= s
Daniel@0 72 if t < 1 | t > n | round(t) ~= t
Daniel@0 73 error('Invalid ''pred'' element found prior to reaching ''s''');
Daniel@0 74 end
Daniel@0 75 rte = [P(t) rte];
Daniel@0 76 t = P(t);
Daniel@0 77 end
Daniel@0 78