comparison toolboxes/FullBNT-1.0.7/graph/mk_nbrs_of_dag.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 [Gs, op, nodes] = mk_nbrs_of_dag(G0)
2 % MK_NBRS_OF_DAG Make all DAGs that differ from G0 by a single edge deletion, addition or reversal
3 % [Gs, op, nodes] = mk_nbrs_of_dag(G0)
4 %
5 % Gs{i} is the i'th neighbor.
6 % op{i} = 'add', 'del', or 'rev' is the operation used to create the i'th neighbor.
7 % nodes(i,1:2) are the head and tail of the operated-on arc.
8
9 Gs = {};
10 op = {};
11 nodes = [];
12
13 [I,J] = find(G0);
14 nnbrs = 1;
15 % all single edge deletions
16 for e=1:length(I)
17 i = I(e); j = J(e);
18 G = G0;
19 G(i,j) = 0;
20 Gs{nnbrs} = G;
21 op{nnbrs} = 'del';
22 nodes(nnbrs, :) = [i j];
23 nnbrs = nnbrs + 1;
24 end
25
26 % all single edge reversals
27 for e=1:length(I)
28 i = I(e); j = J(e);
29 G = G0;
30 G(i,j) = 0;
31 G(j,i) = 1;
32 if acyclic(G)
33 Gs{nnbrs} = G;
34 op{nnbrs} = 'rev';
35 nodes(nnbrs, :) = [i j];
36 nnbrs = nnbrs + 1;
37 end
38 end
39
40 [I,J] = find(~G0);
41 % all single edge additions
42 for e=1:length(I)
43 i = I(e); j = J(e);
44 if i ~= j % don't add self arcs
45 G = G0;
46 G(i,j) = 1;
47 if G(j,i)==0 % don't add i->j if j->i exists already
48 if acyclic(G)
49 Gs{nnbrs} = G;
50 op{nnbrs} = 'add';
51 nodes(nnbrs, :) = [i j];
52 nnbrs = nnbrs + 1;
53 end
54 end
55 end
56 end
57
58
59
60
61
62
63
64