% get_unique_perms: find unique permutations of a combination vector
% which may have non-distinct entries.  For example, if c = [1 0 0]
% and perms = [1 2 3; 1 3 2; 2 3 1; 2 1 3; 3 1 2; 3 2 1]' then the
% result should be r = [1 3 4 0 0 0]' and the three unique permutations
% are c(perms(:,r(i))) i=1,2,3, i.e. [1 0 0]', [0 1 0]', and [0 0 1]'
%
function r = get_unique_perms( c)

global perms;
global MP;

r = zeros(MP,1);

r(1) = 1;	% start with first permutation
nr = 1;

for i = 2:MP	% check all of the other permutations

  unique = 1;

  ci = c(perms(:,i));

  for j = 1:nr
    if( all( c(perms(:,r(j))) == ci)) % matched previous permutation
      unique = 0;
      break;
    end
  end

  if( unique) % found another unique permutation
    nr = nr + 1;
    r(nr) = i;
  end

end
