comparison toolboxes/FullBNT-1.0.7/graph/min_subtree_con_nodes.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 [subtree, nroot_node] = min_subtree_con_nodes(jtree, root, nodes)
2 %min_subtree_con_nodes get the minimum subtree of tree which contains the nodes
3
4 if isempty(jtree) | isempty(nodes)
5 subtree = [];
6 nroot_node = [];
7 return;
8 end
9
10 rnodes = min_subtree_nodes(jtree, nodes);
11 nea_node = nearest_node(jtree, root, nodes);
12 node_num = length(jtree);
13 subtree = zeros(node_num);
14 subtree(rnodes, rnodes) = jtree(rnodes, rnodes);
15 nroot_node = nea_node;
16
17
18 function rnodes = min_subtree_nodes(tree, nodes)
19 rnodes = [];
20 if isempty(tree) | isempty(nodes)
21 return
22 end
23
24 rnodes = nodes(1);
25 newnodes = neighbors(tree, nodes(1));
26 while ~mysubset(nodes, rnodes)
27 swapnodes = newnodes;
28 newnodes = [];
29 added = 0;
30 for i=1:length(swapnodes)
31 inode = swapnodes(i);
32 tnodes = myunion(inode, rnodes);
33 if mysubset(nodes, tnodes)
34 added = 1;
35 break;
36 end
37 nns = neighbors(tree, inode);
38 add_nodes = mysetdiff(nns, tnodes);
39 newnodes = myunion(newnodes, add_nodes);
40 end
41 if added
42 rnodes = tnodes;
43 else
44 rnodes = myunion(rnodes, newnodes);
45 end
46 end
47
48 function nea_node = nearest_node(tree, inode, nodes)
49 if myismember(inode, nodes)
50 nea_node = inode;
51 return;
52 end
53 cs = children(tree, inode);
54 for i = 1:length(cs)
55 n = cs(i);
56 nea_node = nearest_node(tree, n, nodes);
57 end
58
59
60