lib/rubyga_config.rb
# Generate gene to give the population.
# Arguments: 
#   cond = condition of generating gene.
# Condition is supposed as following,
#   1. random (general purpose).
#   2. tsp (it's intended for TSP(Travel Salesman Problem), so each of element appears
#           only once in the returned array which size equals given gene. 
#           The first element equals the last one.)
Generate gene to give the population.
Arguments:
cond = condition of generating gene.
Condition is supposed as following,
1. random (general purpose).
2. tsp (it's intended for TSP(Travel Salesman Problem), so each of element appears
only once in the returned array which size equals given gene.
The first element equals the last one.)
Generate gene to give the population . Arguments : cond = condition of generating gene . Condition is supposed as following 1 . random ( general purpose ) . 2 . tsp ( it ' s intended for TSP ( Travel Salesman Problem ) so each of element appears only once in the returned array which size equals given gene . The first element equals the last one . )
def generate_gene(cond=nil)
    bits = []
    cond = "random" if cond == nil
    if cond == "random"
      @gene_size.times do |i|
        bits << @gene_var[rand(@gene_var.size)]
      end
    elsif cond == "tsp"
      tmp_gene = @gene_var.dup
      @gene_var.size.times do |i|
        bits << tmp_gene.slice!(rand(tmp_gene.size))
      end
      if bits.size != bits.uniq.size
        raise "Failed to generage_gene for TSP: #{bits}"
      end
    end
    return bits
  end
def generate_gene ( cond = nil ) bits = [ ] cond = "random" if cond == nil if cond == "random" @gene_size . times do | i | bits << @gene_var [ rand ( @gene_var . size ) ] end elsif cond == "tsp" tmp_gene = @gene_var . dup @gene_var . size . times do | i | bits << tmp_gene . slice! ( rand ( tmp_gene . size ) ) end if bits . size != bits . uniq . size raise "Failed to generage_gene for TSP: #{bits}" end end return bits end
Generate gene to give the population.
Generate gene to give the population .
cond
<not_specific>