Two point Crossover in Genetic Algorithm

9 次查看(过去 30 天)
I have a simple piece of code that carries out the crossover with just one point. How would I go about making the following a two-point crossover operation?
if (rand < CrossoverProbability)
C1 = TempChromosome_1;
C2 = TempChromosome_2;
% now copy over the data from the other parent that is "crossed over" with the first
% parent
crossoverPoint = randi([1,30]);
TempChromosome_1(:,crossoverPoint:end) = C2(:,crossoverPoint:end);
TempChromosome_2(:,crossoverPoint:end) = C1(:,crossoverPoint:end);
end
The data itself (i.e. TempChromosome_1) is a 30-digit sequence with numbers 1-9

回答(1 个)

Pavithra Ashok Kumar
Hi, If you are looking for a built-in function to implement a 2-point crossover, set the "CrossOverFcn" parameter to be @crossovertwopoint. Refer the page for more details: http://www.mathworks.com/help/gads/genetic-algorithm-options.html

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by