
population_size = 400;
number_of_genes = 60;

initial_population = rand(population_size, number_of_genes);
tmp = initial_population*initial_population';
fitness = tmp(:,1);
initial_population(:, number_of_genes+1) = fitness;
population = sortrows(initial_population, number_of_genes+1);

xx = [];
yy = [];

for time=1:100
for j=1:population_size
   child = [];

   parent1 = population((floor((population_size/2)*rand)+1), :);
   parent2 = population((floor((population_size/2)*rand)+1), :);

   for n=1:number_of_genes
      which = floor(2*rand);
      if (which == 0)
         child(n) = parent1(n);
      else
         child(n) = parent2(n);
      end
   end


   
   fitness = child*child';
   child(number_of_genes+1) = fitness;

   population(j, :) = child;

   population = sortrows(population, number_of_genes+1);
   end

population(1,number_of_genes+1);

xx(end+1) = time;
yy(end+1) = population(1,number_of_genes+1);
end

plot(xx, yy)

