comparison toolboxes/FullBNT-1.0.7/graph/pred2path.m @ 0:e9a9cd732c1e tip

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