function mutationChildren = mutationNcK(parents,options,GenomeLength,FitnessFcn,state,thisScore,thisPopulation)
% Oren Rosen
% Copyright 2008 The MathWorks, Inc.
% This function is used for the N-choose-K bit-string genetic algorithm.
% The mutation algorithm is written to work on a population of length N
% bitstrings, each with exactly K bits equal to one. The children that are
% produced are simply random permutations of the parents. Because of this,
% the "K bits equal to one" constraint is automatically satisfied.
% This implementation was a quick and intuitive way to structure this
% function. It is by no means optimized and the end user is encouraged to
% experiment with other methods.
mutationChildren = zeros(length(parents),GenomeLength);
numVars = length(thisPopulation(1,:));
% Each parent produces a child.
child = thisPopulation(parents(i),:);
% The child is a random permutation of the parent's bits.
mutationChildren(i,:) = child( randperm(numVars) );