test/genetic_algorithm.rb
#     1. Choose initial population
#     2. Evaluate the fitness of each individual in the population
#     3. Repeat
#           1. Select best-ranking individuals to reproduce
#           2. Breed new generation through crossover and mutation (genetic operations) and give birth to offspring
#           3. Evaluate the individual fitnesses of the offspring
#           4. Replace worst ranked part of population with offspring
#     4. Until termination    
#     5. Return the best chromosome
1. Choose initial population
2. Evaluate the fitness of each individual in the population
3. Repeat
1. Select best-ranking individuals to reproduce
2. Breed new generation through crossover and mutation (genetic operations) and give birth to offspring
3. Evaluate the individual fitnesses of the offspring
4. Replace worst ranked part of population with offspring
4. Until termination
5. Return the best chromosome
1 . Choose initial population 2 . Evaluate the fitness of each individual in the population 3 . Repeat 1 . Select best - ranking individuals to reproduce 2 . Breed new generation through crossover and mutation ( genetic operations ) and give birth to offspring 3 . Evaluate the individual fitnesses of the offspring 4 . Replace worst ranked part of population with offspring 4 . Until termination 5 . Return the best chromosome
def run
        generate_initial_population()                    
        (1..@max_generation).each do |generation_number|
          puts "\nGeneration #{generation_number}"
          fitness_range = get_fitness_range(@population)
          next if fitness_range.max == fitness_range.min
          @population.sort!()
          selected_to_breed = selection()              
          offsprings = reproduction(selected_to_breed) 
          replace_worst_ranked(offsprings)
          puts to_s()
          mutate()
          increment_age()
        end
        return @population.sort { |a, b| b.fitness <=> a.fitness}
      end
def run generate_initial_population ( ) ( 1 .. @max_generation ) . each do | generation_number | puts "\nGeneration #{generation_number}" fitness_range = get_fitness_range ( @population ) next if fitness_range . max == fitness_range . min @population . sort! ( ) selected_to_breed = selection ( ) offsprings = reproduction ( selected_to_breed ) replace_worst_ranked ( offsprings ) puts to_s ( ) mutate ( ) increment_age ( ) end return @population . sort { | a , b | b . fitness <=> a . fitness } end
1.
1 .
#Generate initial population  # Evaluates current population  # Generate the population for this new generation #return best_chromosome()