To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / graph / check_triangulated.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.2 KB)
| 1 |
function [triangulated, order] = check_triangulated(G) |
|---|---|
| 2 |
% CHECK_TRIANGULATED Return 1 if G is a triangulated (chordal) graph, 0 otherwise. |
| 3 |
% [triangulated, order] = check_triangulated(G) |
| 4 |
% |
| 5 |
% A numbering alpha is perfect if Nbrs(alpha(i)) intersect {alpha(1)...alpha(i-1)} is complete.
|
| 6 |
% A graph is triangulated iff it has a perfect numbering. |
| 7 |
% The Maximum Cardinality Search algorithm will create such a perfect numbering if possible. |
| 8 |
% See Golumbic, "Algorithmic Graph Theory and Perfect Graphs", Cambridge Univ. Press, 1985, p85. |
| 9 |
% or Castillo, Gutierrez and Hadi, "Expert systems and probabilistic network models", Springer 1997, p134. |
| 10 |
|
| 11 |
|
| 12 |
G = setdiag(G, 1); |
| 13 |
n = length(G); |
| 14 |
order = zeros(1,n); |
| 15 |
triangulated = 1; |
| 16 |
numbered = [1]; |
| 17 |
order(1) = 1; |
| 18 |
for i=2:n |
| 19 |
U = mysetdiff(1:n, numbered); % unnumbered nodes |
| 20 |
score = zeros(1, length(U)); |
| 21 |
for ui=1:length(U) |
| 22 |
u = U(ui); |
| 23 |
score(ui) = length(myintersect(neighbors(G, u), numbered)); |
| 24 |
end |
| 25 |
u = U(argmax(score)); |
| 26 |
numbered = [numbered u]; |
| 27 |
order(i) = u; |
| 28 |
nns = myintersect(neighbors(G,u), order(1:i-1)); % numbered neighbors |
| 29 |
if ~isequal(G(nns,nns), ones(length(nns))) % ~complete(G(nns,nns)) |
| 30 |
triangulated = 0; |
| 31 |
break; |
| 32 |
end |
| 33 |
end |
| 34 |
|