Class: Darwinning::Organism

Inherits:
Object
  • Object
show all
Includes:
ClassLevelInheritableAttributes
Defined in:
lib/darwinning/organism.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassLevelInheritableAttributes

included

Constructor Details

#initialize(genotypes = []) ⇒ Organism

Returns a new instance of Organism.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/darwinning/organism.rb', line 38

def initialize(genotypes = [])
  #TODO: catch errors if genotype.length != @genotypes.length
  # catch if genotype[x] is not a valid value for @gene[x]

  if genotypes == []
    # fill genotypes with expressed Genes
    @genotypes = self.class.genes.map { |g| g.express } # Gene expressions
  else
    @genotypes = genotypes
  end

  @fitness = -1
end

Instance Attribute Details

#fitnessObject

Returns the value of attribute fitness.



33
34
35
# File 'lib/darwinning/organism.rb', line 33

def fitness
  @fitness
end

#genesObject

Returns the value of attribute genes.



33
34
35
# File 'lib/darwinning/organism.rb', line 33

def genes
  @genes
end

#genotypesObject

Returns the value of attribute genotypes.



33
34
35
# File 'lib/darwinning/organism.rb', line 33

def genotypes
  @genotypes
end

#nameObject

Returns the value of attribute name.



33
34
35
# File 'lib/darwinning/organism.rb', line 33

def name
  @name
end

Instance Method Details

#nice_printObject



52
53
54
55
56
# File 'lib/darwinning/organism.rb', line 52

def nice_print
  puts self.class.name == "" ? "[no name]" : self.class.name
  self.class.genes.to_enum.each_with_index { |g, i| puts "  #{g.name}: #{@genotypes[i]} #{g.units}" }
  puts "    fitness: #{fitness}"
end