wolffd@0: function [Gs, op, nodes] = mk_nbrs_of_dag(G0) wolffd@0: % MK_NBRS_OF_DAG Make all DAGs that differ from G0 by a single edge deletion, addition or reversal wolffd@0: % [Gs, op, nodes] = mk_nbrs_of_dag(G0) wolffd@0: % wolffd@0: % Gs{i} is the i'th neighbor. 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: Gs = {}; wolffd@0: op = {}; wolffd@0: nodes = []; wolffd@0: wolffd@0: [I,J] = find(G0); wolffd@0: nnbrs = 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{nnbrs} = G; wolffd@0: op{nnbrs} = 'del'; wolffd@0: nodes(nnbrs, :) = [i j]; wolffd@0: nnbrs = nnbrs + 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: if acyclic(G) wolffd@0: Gs{nnbrs} = G; wolffd@0: op{nnbrs} = 'rev'; wolffd@0: nodes(nnbrs, :) = [i j]; wolffd@0: nnbrs = nnbrs + 1; wolffd@0: end 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: if i ~= j % don't add self arcs wolffd@0: G = G0; wolffd@0: G(i,j) = 1; wolffd@0: if G(j,i)==0 % don't add i->j if j->i exists already wolffd@0: if acyclic(G) wolffd@0: Gs{nnbrs} = G; wolffd@0: op{nnbrs} = 'add'; wolffd@0: nodes(nnbrs, :) = [i j]; wolffd@0: nnbrs = nnbrs + 1; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: