find a bottom to up ordering given the tree structure {pred} returned by matlab's graphminspantree

release/4.3a0
Kai Ni 2009-12-12 22:40:27 +00:00
parent 7725a9caeb
commit f307ac4b7c
2 changed files with 24 additions and 24 deletions

View File

@ -1 +1,22 @@
% put function here
% find a bottom to up ordering given the tree structure {pred} returned by matlab's graphminspantree
function [ordering] = bottom_up_ordering(pred)
%% compute the levels of the nodes
parents = [0];
node_levels = zeros(length(pred), 1);
current_level = 1;
while ~isempty(parents)
parents = find(ismember(pred, parents));
node_levels(parents) = current_level;
current_level = current_level + 1;
end
max_level = current_level - 1;
ordering = Ordering();
for level = max_level:-1:1
ids = find(node_levels==level);
for i = 1:length(ids)
ordering.push_back(sprintf('x%d', ids(i)));
end
end
end

View File

@ -1,25 +1,4 @@
% find a bottom to up ordering given the tree structure {pred} returned by matlab's graphminspantree
function [ordering] = kai02_bottomUp(pred)
%% compute the levels of the nodes
parents = [0];
node_levels = zeros(length(pred), 1);
current_level = 1;
while ~isempty(parents)
parents = find(ismember(pred, parents));
node_levels(parents) = current_level;
current_level = current_level + 1;
end
max_level = current_level - 1;
ordering = Ordering();
for level = max_level:-1:1
ids = find(node_levels==level);
for i = 1:length(ids)
ordering.push_back(sprintf('x%d', ids(i)));
end
end
load beijing_graph.mat;
ordering = bottom_up_ordering(pred);
ordering.print('ordering')
end