wolffd@0: function [Gs, op, nodes] = mk_nbrs_of_digraph2(G0) wolffd@0: % MK_NBRS_OF_DIGRAPH Make all digraphs that differ from G0 by a single edge deletion, addition or reversal wolffd@0: % [Gs, op, nodes] = mk_nbrs_of_digraph(G0) wolffd@0: % op{i} = 'add', 'del', or 'rev' is the operation used to create the i'th neighbor. wolffd@0: % nodes(i,1:2) are the head and tail of the operated-on arc. wolffd@0: wolffd@0: [I,J] = find(G0); wolffd@0: G0bar = setdiag(~G0, 0); % exclude self loops in graph complement wolffd@0: [Ibar,Jbar] = find(G0bar); wolffd@0: nnbrs = 2*length(I) + length(Ibar); wolffd@0: Gs = cell(1, nnbrs); wolffd@0: op = cell(1, nnbrs); wolffd@0: nodes = zeros(nnbrs, 2); wolffd@0: wolffd@0: nbr = 1; wolffd@0: % all single edge deletions wolffd@0: for e=1:length(I) wolffd@0: i = I(e); j = J(e); wolffd@0: G = G0; wolffd@0: G(i,j) = 0; wolffd@0: Gs{nbr} = G; wolffd@0: op{nbr} = 'del'; wolffd@0: nodes(nbr, :) = [i j]; wolffd@0: nbr = nbr + 1; wolffd@0: end wolffd@0: wolffd@0: % all single edge reversals wolffd@0: for e=1:length(I) wolffd@0: i = I(e); j = J(e); wolffd@0: G = G0; wolffd@0: G(i,j) = 0; wolffd@0: G(j,i) = 1; wolffd@0: Gs{nbr} = G; wolffd@0: op{nbr} = 'rev'; wolffd@0: nodes(nbr, :) = [i j]; wolffd@0: nbr = nbr + 1; wolffd@0: end wolffd@0: wolffd@0: [I,J] = find(~G0); wolffd@0: % all single edge additions wolffd@0: for e=1:length(I) wolffd@0: i = I(e); j = J(e); wolffd@0: G = G0; wolffd@0: if i ~= j % don't add self loops wolffd@0: G(i,j) = 1; wolffd@0: Gs{nbr} = G; wolffd@0: op{nbr} = 'add'; wolffd@0: nodes(nbr, :) = [i j]; wolffd@0: nbr = nbr + 1; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: assert(nnbrs == nbr-1);