annotate toolboxes/FullBNT-1.0.7/graph/triangulate.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [G, cliques, fill_ins] = triangulate(G, order)
Daniel@0 2 % TRIANGULATE Ensure G is triangulated (chordal), i.e., every cycle of length > 3 has a chord.
Daniel@0 3 % [G, cliques, fill_ins, cliques_containing_node] = triangulate(G, order)
Daniel@0 4 %
Daniel@0 5 % cliques{i} is the i'th maximal complete subgraph of the triangulated graph.
Daniel@0 6 % fill_ins(i,j) = 1 iff we add a fill-in arc between i and j.
Daniel@0 7 %
Daniel@0 8 % To find the maximal cliques, we save each induced cluster (created by adding connecting
Daniel@0 9 % neighbors) that is not a subset of any previously saved cluster. (A cluster is a complete,
Daniel@0 10 % but not necessarily maximal, set of nodes.)
Daniel@0 11
Daniel@0 12 MG = G;
Daniel@0 13 n = length(G);
Daniel@0 14 eliminated = zeros(1,n);
Daniel@0 15 cliques = {};
Daniel@0 16 for i=1:n
Daniel@0 17 u = order(i);
Daniel@0 18 U = find(~eliminated); % uneliminated
Daniel@0 19 nodes = myintersect(neighbors(G,u), U); % look up neighbors in the partially filled-in graph
Daniel@0 20 nodes = myunion(nodes, u); % the clique will always contain at least u
Daniel@0 21 G(nodes,nodes) = 1; % make them all connected to each other
Daniel@0 22 G = setdiag(G,0);
Daniel@0 23 eliminated(u) = 1;
Daniel@0 24
Daniel@0 25 exclude = 0;
Daniel@0 26 for c=1:length(cliques)
Daniel@0 27 if mysubset(nodes,cliques{c}) % not maximal
Daniel@0 28 exclude = 1;
Daniel@0 29 break;
Daniel@0 30 end
Daniel@0 31 end
Daniel@0 32 if ~exclude
Daniel@0 33 cnum = length(cliques)+1;
Daniel@0 34 cliques{cnum} = nodes;
Daniel@0 35 end
Daniel@0 36 end
Daniel@0 37
Daniel@0 38 fill_ins = sparse(triu(max(0, G - MG), 1));
Daniel@0 39
Daniel@0 40 %assert(check_triangulated(G)); % takes 72% of the time!
Daniel@0 41
Daniel@0 42