mutationNcK(parents,options,GenomeLength,FitnessFcn,state,thisScore,thisPopulation)

function mutationChildren = mutationNcK(parents,options,GenomeLength,FitnessFcn,state,thisScore,thisPopulation)
% Oren Rosen
% 4/1/2008
% Copyright 2008 The MathWorks, Inc.
%
% This function is used for the NchooseK bitstring 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,:));
for i=1:length(parents)
% 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) );
end

