www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/arith_varpoint_crossover.m

    % Evolution Strategy: Arithmetic variable point cross over for real coded chromosomes

function [offspring_popln]= arith_varpoint_crossover(parent_popln,  crossover_rate)

[popln_size,  genes] = size(parent_popln);
for i = 1 : 2: (popln_size-1) 
    parent1 = parent_popln(i,:);
    parent2 = parent_popln(i+1,:);
    a = rand;
    for j = 1: genes
        if (rand < crossover_rate) % perform cross over
             temp1 = parent1(j);
             temp2 = parent2(j);
             parent1(j)= a * temp1 + (1-a)* temp2;
             parent2(j)= (1-a)* temp1 + a * temp2;
        end
    end
    offspring_popln(i,:) = parent1;
    offspring_popln(i+1,:)= parent2;
end