Class: Wallace::Species
- Inherits:
-
Object
- Object
- Wallace::Species
- Defined in:
- lib/core/species.rb
Overview
Each individual in the population must belong to a single species.
Direct Known Subclasses
Defined Under Namespace
Classes: ArraySpecies, BitStringSpecies, PermutationSpecies, StringSpecies
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#finish!(individual) ⇒ Object
Used to post-process individuals belonging to this species after they have been created.
-
#initialize(opts) ⇒ Species
constructor
Creates a new Species.
-
#spawn(rng) ⇒ Object
Spawns a new member of this species at random.
-
#valid?(individual) ⇒ Boolean
Determines whether a given individual is a valid member of this species.
Constructor Details
#initialize(opts) ⇒ Species
Creates a new Species.
Parameters:
-
opts, hash of keyword options used by this method. -> id, the unique identifier for this species.
15 16 17 |
# File 'lib/core/species.rb', line 15 def initialize(opts) @id = opts[:id] end |
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/core/species.rb', line 7 def name @name end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/core/species.rb', line 4 def id @id end |
Instance Method Details
#finish!(individual) ⇒ Object
Used to post-process individuals belonging to this species after they have been created. By default this method is a stub.
Parameters:
-
individual, the individual to post-process.
Returns:
-
the post-processed individual.
48 49 50 |
# File 'lib/core/species.rb', line 48 def finish!(individual) individual end |
#spawn(rng) ⇒ Object
Spawns a new member of this species at random.
Parameters:
-
rng, the random number generator to use.
36 37 38 |
# File 'lib/core/species.rb', line 36 def spawn(rng) raise NotImplementedError, 'Spawn method not implemented by this species.' end |
#valid?(individual) ⇒ Boolean
Determines whether a given individual is a valid member of this species. Validity may be determined by more than just membership. For example, there may be certain size constraints on individuals.
Parameters:
-
individual, the individual to check for validity.
Returns: true if a valid member of this species, false if invalid or not a member.
28 29 30 |
# File 'lib/core/species.rb', line 28 def valid?(individual) individual.species === self end |