Class: Wallace::GE::GrammarSpecies

Inherits:
Species::ArraySpecies show all
Defined in:
lib/modules/ge/grammar_species.rb

Overview

The grammar species represents each individual in the species as an array of integers which map to a derivation of the grammar attached to the species.

Instance Attribute Summary collapse

Attributes inherited from Species

#id

Instance Method Summary collapse

Methods inherited from Species::ArraySpecies

#spawn, #valid?

Methods inherited from Species

#finish!, #spawn, #valid?

Constructor Details

#initialize(opts = {}) ⇒ GrammarSpecies

Constructs a new grammar-based species.

Parameters:

  • opts, hash of keyword options used by this method. -> id, the unique identifier for this species. -> grammar, the grammar used by individuals of this species. -> length, the length constraints on individuals of the species.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/modules/ge/grammar_species.rb', line 16

def initialize(opts = {})

  # By default grammar derivations are between 10 and 200 symbols and contain
  # integers in the range 0 to 2147483647 inclusive.
  opts[:length] ||= 10..200
  opts[:values] ||= 0..2147483647
  
  super(opts)

  @grammar = opts[:grammar]

end

Instance Attribute Details

#grammarObject (readonly)

Returns the value of attribute grammar.



7
8
9
# File 'lib/modules/ge/grammar_species.rb', line 7

def grammar
  @grammar
end