lib/population.rb
# TODO: to give tournamentSize as the member of RubyGAConfig.

to give tournamentSize as the member of RubyGAConfig.
to give tournamentSize as the member of RubyGAConfig .
def simple_ga_old(fun, selection=nil, mutation_method=nil)
    if rand(100) > @crossoverProbability*100
      @units.each{|unit| unit.get_older}
      case selection
      when "roulette"
        parent1 = roulette_selection!(fun)
        parent2 = roulette_selection!(fun)
      when "elite"
        parent1 = elite_selection!(fun)
        parent2 = elite_selection!(fun)
      when "tournament"
        parent1 = tournament_selection!(fun)
        parent2 = tournament_selection!(fun)
      when "rank" 
        parent1 = rank_selection!(fun)
        parent2 = rank_selection!(fun)
      else
        raise "selection method is invalid!"
      end
      child1, child2 = parent1.crossover(parent2, @crossover)
      @units << parent1 << parent2 << child1 << child2 
      2.times do
        worst = drop_worst_unit(fun)
      end
    end
    @units.each do |unit|
      if rand(100) < @mutationProbability*100
        unit.mutation(@mutationProbability, mutation_method)
      end
    end
  end
def simple_ga_old ( fun , selection = nil , mutation_method = nil ) if rand ( 100 ) > @crossoverProbability * 100 @units . each { | unit | unit . get_older } case selection when "roulette" parent1 = roulette_selection! ( fun ) parent2 = roulette_selection! ( fun ) when "elite" parent1 = elite_selection! ( fun ) parent2 = elite_selection! ( fun ) when "tournament" parent1 = tournament_selection! ( fun ) parent2 = tournament_selection! ( fun ) when "rank" parent1 = rank_selection! ( fun ) parent2 = rank_selection! ( fun ) else raise "selection method is invalid!" end child1 , child2 = parent1 . crossover ( parent2 , @crossover ) @units << parent1 << parent2 << child1 << child2 2 . times do worst = drop_worst_unit ( fun ) end end @units . each do | unit | if rand ( 100 ) < @mutationProbability * 100 unit . mutation ( @mutationProbability , mutation_method ) end end end
TODO: to give tournamentSize as the member of RubyGAConfig.
TODO : to give tournamentSize as the member of RubyGAConfig .
# Crossover
 # Mutation

fun
<not_specific>
selection
<not_specific>
mutation_method
<not_specific>