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 _tournament_selection(fun, bang=nil)
    indice = (0..@units.size-1).to_a  
    units_fitness = {}
    @tournamentSize.times do |i|
      idx = indice.slice!(rand(indice.size))
      units_fitness[idx] = @units[idx].fitness(fun)
    end
    max_fit = nil
    max_idx = nil
    units_fitness.each{|idx, fit|
      if max_fit == nil || max_fit < fit
        max_fit = fit
        max_idx = idx
      end
    }
    if bang
      return @units.slice!(max_idx)
    else
      return @units[max_idx]
    end
  end
def _tournament_selection ( fun , bang = nil ) indice = ( 0 .. @units . size - 1 ) . to_a units_fitness = { } @tournamentSize . times do | i | idx = indice . slice! ( rand ( indice . size ) ) units_fitness [ idx ] = @units [ idx ] . fitness ( fun ) end max_fit = nil max_idx = nil units_fitness . each { | idx , fit | if max_fit == nil || max_fit < fit max_fit = fit max_idx = idx end } if bang return @units . slice! ( max_idx ) else return @units [ max_idx ] end end
TODO: to give tournamentSize as the member of RubyGAConfig.
TODO : to give tournamentSize as the member of RubyGAConfig .
# くじ

fun
<not_specific>
bang
<not_specific>