-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMutate.m
24 lines (20 loc) · 791 Bytes
/
Mutate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Alp Sayin - alpsayin[at]alpsayin[dot]com - https://alpsayin.com
% Matlab Genetic Algorithm
% Spring 2012
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tempPopulation = Mutate(tempPopulation, mutationProbability)
indexes = rand(size(tempPopulation))<mutationProbability; % Index for Mutations
tempPopulation(indexes) = tempPopulation(indexes)*-1+1; % Bit Flip Occurs
% Deprecated - to be deleted in the next iteration
% nGenes= size(chromosome,2);
% mutatedChromosome = chromosome;
% for j = 1: nGenes
% r= rand;
% if (r < mutationProbability)
% mutatedChromosome(j) = 1-chromosome(j);
% end
%
% end