population_size = 100; chromosome_length = 500; generations = 500; mutation_rate = 0.001; best_fitness_hist = []; %create inital population population = initialization(population_size, chromosome_length); for g = 1:generations %eval fitness fitness = sum(population, 2); %select individuals for tournament selection selected = tournament_selection(population,fitness,population_size); %crossover the individuals offspring = crossover(selected); %mutation mutated_offspring = mutate(offspring, mutation_rate); %create new population population = mutated_offspring; %display best fitness of this generation best_fitness = max(fitness); if best_fitness == chromosome_length break end best_fitness_hist = [best_fitness_hist;best_fitness]; fprintf('Generation %d: Bestfitness = %d\n', g, best_fitness); end plot(best_fitness_hist)