Class: Util::Individual

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

Overview

The superclass that wraps genotype and phenotype mapping process into the single instance, typically subclassed by the real-world task individuals. The Individual class provides “duck-type interface” which separates a task from various algorithms.

Direct Known Subclasses

PipedIndividual

Constant Summary

@@shortener =
Operator::Shorten.new

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Individual) initialize(mapper, genotype)

Create the new phenotype, based on the genotype, using the mapper.



14
15
16
17
18
19
20
21
22
23
24
# File '../lib/individual.rb', line 14

def initialize( mapper, genotype )
  @genotype = genotype
  @used_length = nil

  @phenotype = mapper.phenotype( @genotype )
  return if @phenotype.nil?

  @used_length = mapper.used_length
  @track_support = mapper.track_support 
  @complexity = mapper.complexity   
end

Instance Attribute Details

- (Object) complexity (readonly)

The complexity of the expression. See Mapper::Base#complexity



37
38
39
# File '../lib/individual.rb', line 37

def complexity
  @complexity
end

- (Object) genotype (readonly)

Genotype vector (array of codons) as provided by the constructor.



27
28
29
# File '../lib/individual.rb', line 27

def genotype
  @genotype
end

- (Object) phenotype (readonly)

Phenotype text (string representing typically the source of the program), the result of GP mapping. Phenotype attribute can be nil (when the mapping process failed).



31
32
33
# File '../lib/individual.rb', line 31

def phenotype
  @phenotype
end

- (Object) track_support (readonly)

The LHS crossover support from the Mapper::Base (see Operator::CrossoverLHS)



40
41
42
# File '../lib/individual.rb', line 40

def track_support
  @track_support
end

- (Object) used_length (readonly)

The number of codons used in the mapping process (see Mapper::Base#used_length).



34
35
36
# File '../lib/individual.rb', line 34

def used_length
  @used_length
end

Instance Method Details

- (Object) shorten_chromozome=(shorten)

If set to true, the genome is shortened by the Shorten#shorten with the used_length argument.



43
44
45
46
47
# File '../lib/individual.rb', line 43

def shorten_chromozome=( shorten )
  return unless shorten
  return if @used_length.nil?
  @genotype = @@shortener.shorten( @genotype, @used_length )
end

- (Boolean) valid?

Return true if the phenotype is valid (the mapping process was succesful).

Returns:

  • (Boolean)


50
51
52
# File '../lib/individual.rb', line 50

def valid?
  not self.phenotype.nil?
end