function ps = create_possible_parents(bnet, i, K,  must_connect, must_not_connect, disallow_empty_set)
% CREATE_POSSIBLE_PARENTS Find all sets of possible parents in the prev. slice for node i
% ps = create_possible_parents(bnet, i, K,  must_connect, must_not_connect, disallow_empty_set)
%
% must_connect is a vector containing nodes we must add as parents
% must_not_connect is a vector containing nodes we must not add as parents
% disallow_empty_set = 1 if we disallow the empty set of parents.
%
% We consider all subsets of nodes in the previous slice up to size K
% as possible parents, and then impose any constraints.

% It is quicker to use a bit vector representation of sets than to use cell arrays

ss = bnet.slice_size;
masks = subsets(ss, K);
masks(:,must_connect) = 1;
masks(:,must_not_connect) = 0;
masks = unique(masks, 'rows');
ps = {};
for i=1:size(masks,1)
  S = find(masks(i,:));
  if disallow_empty_set & isempty(S)
    %
  else
    ps{end+1} = S;
  end
end
