function [children] = crossover(pop_keep, ma,pa, N_total_children, method) % BINARY_GA - Implements a couple of crossover algorithms % % Inputs: % pop_keep the population of most fit individuals % ma = indices into pop_keep for the "mother" chromosome % pa = indices into pop_keep for the "father" chromosome % each pairing produced two children, we repeatidly cycle through % the parents performing crossover until we have enough children % N_total_children = number of total children that we must generate % method = method used to perform crossover % % Outputs: % % Written by: % -- % John L. Weatherwax 2006-08-28 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- [N_keep,N_bits] = size(pop_keep); nPairs = length(ma); children = zeros(N_total_children,N_bits); % initialize storage switch method case 1, % single point crossover crossover_points = ceil( (N_bits-1) * rand(1,N_total_children) ); child_number = 1; while( child_number