view toolboxes/FullBNT-1.0.7/graph/mk_rooted_tree.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
line wrap: on
line source
function [T, pre, post, cycle] = mk_rooted_tree(G, root)
% MK_ROOTED_TREE Make a directed tree pointing away from root
% [T, pre, post, cycle] = mk_rooted_tree(G, root)

n = length(G);
T = sparse(n,n); % not the same as T = sparse(n) !
directed = 0;
[d, pre, post, cycle, f, pred] = dfs(G, root, directed);
[junk, pre2] = sort(d);
assert(isequal(pre, pre2))
[junk, post2] = sort(f);
assert(isequal(post, post2));
%[d, pre, post, cycle, f, pred] = dfs(G, [], directed);
for i=1:length(pred)
  if pred(i)>0
    T(pred(i),i)=1;
  end
end