To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / graph / mk_nbrs_of_digraph_not_vectorized.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.22 KB)

1
function [Gs, op, nodes] = mk_nbrs_of_digraph2(G0)
2
% MK_NBRS_OF_DIGRAPH Make all digraphs that differ from G0 by a single edge deletion, addition or reversal
3
% [Gs, op, nodes] = mk_nbrs_of_digraph(G0)
4
% op{i} = 'add', 'del', or 'rev' is the operation used to create the i'th neighbor.
5
% nodes(i,1:2) are the head and tail of the operated-on arc.
6

    
7
[I,J] = find(G0);
8
G0bar = setdiag(~G0, 0); % exclude self loops in graph complement
9
[Ibar,Jbar] = find(G0bar);
10
nnbrs = 2*length(I) + length(Ibar);
11
Gs = cell(1, nnbrs);
12
op = cell(1, nnbrs);
13
nodes = zeros(nnbrs, 2);
14

    
15
nbr = 1;
16
% all single edge deletions
17
for e=1:length(I)
18
  i = I(e); j = J(e);
19
  G = G0;
20
  G(i,j) = 0;
21
  Gs{nbr} = G;
22
  op{nbr} = 'del';
23
  nodes(nbr, :) = [i j];
24
  nbr = nbr + 1;
25
end
26

    
27
% all single edge reversals
28
for e=1:length(I)
29
  i = I(e); j = J(e);
30
  G = G0;
31
  G(i,j) = 0;
32
  G(j,i) = 1;
33
  Gs{nbr} = G;
34
  op{nbr} = 'rev';
35
  nodes(nbr, :) = [i j];
36
  nbr = nbr + 1;
37
end
38

    
39
[I,J] = find(~G0);
40
% all single edge additions
41
for e=1:length(I)
42
  i = I(e); j = J(e);
43
  G = G0;
44
  if i ~= j % don't add self loops
45
    G(i,j) = 1;
46
    Gs{nbr} = G;
47
    op{nbr} = 'add';
48
    nodes(nbr, :) = [i j];
49
    nbr = nbr + 1;
50
  end
51
end
52

    
53
assert(nnbrs == nbr-1);