annotate toolboxes/FullBNT-1.0.7/graph/mk_nbrs_of_digraph_not_vectorized.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [Gs, op, nodes] = mk_nbrs_of_digraph2(G0)
wolffd@0 2 % MK_NBRS_OF_DIGRAPH Make all digraphs that differ from G0 by a single edge deletion, addition or reversal
wolffd@0 3 % [Gs, op, nodes] = mk_nbrs_of_digraph(G0)
wolffd@0 4 % op{i} = 'add', 'del', or 'rev' is the operation used to create the i'th neighbor.
wolffd@0 5 % nodes(i,1:2) are the head and tail of the operated-on arc.
wolffd@0 6
wolffd@0 7 [I,J] = find(G0);
wolffd@0 8 G0bar = setdiag(~G0, 0); % exclude self loops in graph complement
wolffd@0 9 [Ibar,Jbar] = find(G0bar);
wolffd@0 10 nnbrs = 2*length(I) + length(Ibar);
wolffd@0 11 Gs = cell(1, nnbrs);
wolffd@0 12 op = cell(1, nnbrs);
wolffd@0 13 nodes = zeros(nnbrs, 2);
wolffd@0 14
wolffd@0 15 nbr = 1;
wolffd@0 16 % all single edge deletions
wolffd@0 17 for e=1:length(I)
wolffd@0 18 i = I(e); j = J(e);
wolffd@0 19 G = G0;
wolffd@0 20 G(i,j) = 0;
wolffd@0 21 Gs{nbr} = G;
wolffd@0 22 op{nbr} = 'del';
wolffd@0 23 nodes(nbr, :) = [i j];
wolffd@0 24 nbr = nbr + 1;
wolffd@0 25 end
wolffd@0 26
wolffd@0 27 % all single edge reversals
wolffd@0 28 for e=1:length(I)
wolffd@0 29 i = I(e); j = J(e);
wolffd@0 30 G = G0;
wolffd@0 31 G(i,j) = 0;
wolffd@0 32 G(j,i) = 1;
wolffd@0 33 Gs{nbr} = G;
wolffd@0 34 op{nbr} = 'rev';
wolffd@0 35 nodes(nbr, :) = [i j];
wolffd@0 36 nbr = nbr + 1;
wolffd@0 37 end
wolffd@0 38
wolffd@0 39 [I,J] = find(~G0);
wolffd@0 40 % all single edge additions
wolffd@0 41 for e=1:length(I)
wolffd@0 42 i = I(e); j = J(e);
wolffd@0 43 G = G0;
wolffd@0 44 if i ~= j % don't add self loops
wolffd@0 45 G(i,j) = 1;
wolffd@0 46 Gs{nbr} = G;
wolffd@0 47 op{nbr} = 'add';
wolffd@0 48 nodes(nbr, :) = [i j];
wolffd@0 49 nbr = nbr + 1;
wolffd@0 50 end
wolffd@0 51 end
wolffd@0 52
wolffd@0 53 assert(nnbrs == nbr-1);