Class: Wallace::Species::StringSpecies

Inherits:
ArraySpecies show all
Defined in:
lib/species/string_species.rb

Overview

String-based species represent their members as strings. Species may impose constraints on the length and alphabet of these strings. If more constraints are desired then the species can be easily extended or sub-classed to implement those constraints.

Instance Attribute Summary

Attributes inherited from Wallace::Species

#id

Instance Method Summary collapse

Methods inherited from ArraySpecies

#valid?

Methods inherited from Wallace::Species

#finish!, #valid?

Constructor Details

#initialize(opts = {}) ⇒ StringSpecies

Constructs a new string-based species.

Parameters:

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



16
17
18
19
# File 'lib/species/string_species.rb', line 16

def initialize(opts = {})
  opts[:values] = opts.delete(:alphabet)
  super(opts)
end

Instance Method Details

#spawn(rng) ⇒ Object

Creates a new string-based individual using the alphabet and length constraints of this species.



23
24
25
26
27
# File 'lib/species/string_species.rb', line 23

def spawn(rng)
  ind = super(rng)
  ind.data = ind.data.join
  return ind
end