Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/graph/triangulate.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 [G, cliques, fill_ins] = triangulate(G, order) | |
2 % TRIANGULATE Ensure G is triangulated (chordal), i.e., every cycle of length > 3 has a chord. | |
3 % [G, cliques, fill_ins, cliques_containing_node] = triangulate(G, order) | |
4 % | |
5 % cliques{i} is the i'th maximal complete subgraph of the triangulated graph. | |
6 % fill_ins(i,j) = 1 iff we add a fill-in arc between i and j. | |
7 % | |
8 % To find the maximal cliques, we save each induced cluster (created by adding connecting | |
9 % neighbors) that is not a subset of any previously saved cluster. (A cluster is a complete, | |
10 % but not necessarily maximal, set of nodes.) | |
11 | |
12 MG = G; | |
13 n = length(G); | |
14 eliminated = zeros(1,n); | |
15 cliques = {}; | |
16 for i=1:n | |
17 u = order(i); | |
18 U = find(~eliminated); % uneliminated | |
19 nodes = myintersect(neighbors(G,u), U); % look up neighbors in the partially filled-in graph | |
20 nodes = myunion(nodes, u); % the clique will always contain at least u | |
21 G(nodes,nodes) = 1; % make them all connected to each other | |
22 G = setdiag(G,0); | |
23 eliminated(u) = 1; | |
24 | |
25 exclude = 0; | |
26 for c=1:length(cliques) | |
27 if mysubset(nodes,cliques{c}) % not maximal | |
28 exclude = 1; | |
29 break; | |
30 end | |
31 end | |
32 if ~exclude | |
33 cnum = length(cliques)+1; | |
34 cliques{cnum} = nodes; | |
35 end | |
36 end | |
37 | |
38 fill_ins = sparse(triu(max(0, G - MG), 1)); | |
39 | |
40 %assert(check_triangulated(G)); % takes 72% of the time! | |
41 | |
42 |