Class: Operator::RandomInit

Inherits:
Object
  • Object
show all
Defined in:
../lib/random_init.rb

Overview

Generate the random genotype of the specified size.

See also Mapper::Generator for description of the Sensible Initialisation.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RandomInit) initialize

A new instance of RandomInit



10
11
12
13
# File '../lib/random_init.rb', line 10

def initialize
  @random = Kernel
  @codon = CodonMod.new # standard 8-bit codons
end

Instance Attribute Details

- (Object) codon

Codon encoding scheme. By default the instance of the CodonMod class is used (ie. standard GE 8-bit codons) See CodonMod for details.



17
18
19
# File '../lib/random_init.rb', line 17

def codon
  @codon
end

- (Object) random

The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.



20
21
22
# File '../lib/random_init.rb', line 20

def random
  @random
end

Instance Method Details

- (Object) init(length)

Generate the genotype (chromozome) of the given length.



29
30
31
32
33
# File '../lib/random_init.rb', line 29

def init length
  gen = []
  length.times { gen << @codon.rand_gen }
  gen
end