Module: Evolvable

Extended by:
Forwardable
Defined in:
lib/evolvable.rb,
lib/evolvable/gene.rb,
lib/evolvable/goal.rb,
lib/evolvable/genome.rb,
lib/evolvable/version.rb,
lib/evolvable/mutation.rb,
lib/evolvable/evolution.rb,
lib/evolvable/selection.rb,
lib/evolvable/count_gene.rb,
lib/evolvable/evaluation.rb,
lib/evolvable/population.rb,
lib/evolvable/serializer.rb,
lib/evolvable/search_space.rb,
lib/evolvable/equalize_goal.rb,
lib/evolvable/maximize_goal.rb,
lib/evolvable/minimize_goal.rb,
lib/evolvable/point_crossover.rb,
lib/evolvable/gene_combination.rb,
lib/evolvable/rigid_count_gene.rb,
lib/evolvable/uniform_crossover.rb,
lib/evolvable/error/undefined_method.rb

Overview

The Evolvable module makes it possible to implement evolutionary behaviors for any class by defining a .search_space class method and #value instance method. Then to evolve instances, initialize a population with .new_population and invoke the #evolve method on the resulting population object.

Implementation Steps

  1. Include the Evolvable module in the class you want to evolve.
  2. Define .search_space and any gene classes that you reference.
  3. Define #value.
  4. Initialize a population with .new_population and use #evolve.

Defined Under Namespace

Modules: ClassMethods, Errors, Gene Classes: CountGene, EqualizeGoal, Evaluation, Evolution, GeneCombination, GeneSpace, Genome, Goal, MaximizeGoal, MinimizeGoal, Mutation, PointCrossover, Population, RigidCountGene, SearchSpace, Selection, Serializer, UniformCrossover

Constant Summary collapse

VERSION =
'1.2.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#generation_indexObject

Returns the value of attribute generation_index.



203
204
205
# File 'lib/evolvable.rb', line 203

def generation_index
  @generation_index
end

#genomeObject

Returns the value of attribute genome.



203
204
205
# File 'lib/evolvable.rb', line 203

def genome
  @genome
end

#idObject

Returns the value of attribute id.



203
204
205
# File 'lib/evolvable.rb', line 203

def id
  @id
end

#populationObject

Returns the value of attribute population.



203
204
205
# File 'lib/evolvable.rb', line 203

def population
  @population
end

#valueObject

Implementing this method is required for evaluation and selection.



203
204
205
206
207
# File 'lib/evolvable.rb', line 203

attr_accessor :id,
:population,
:genome,
:generation_index,
:value

Class Method Details

.included(base) ⇒ Object



42
43
44
# File 'lib/evolvable.rb', line 42

def self.included(base)
  base.extend(ClassMethods)
end

.new_object(old_val, new_val, default_class) ⇒ Object



46
47
48
# File 'lib/evolvable.rb', line 46

def self.new_object(old_val, new_val, default_class)
  new_val.is_a?(Hash) ? (old_val&.class || default_class).new(**new_val) : new_val
end

Instance Method Details

#after_initializeObject

Runs an evolvable is initialized. Ueful for implementing custom initialization logic.



197
# File 'lib/evolvable.rb', line 197

def after_initialize; end

#dump_genome(serializer: Serializer) ⇒ Object



234
235
236
# File 'lib/evolvable.rb', line 234

def dump_genome(serializer: Serializer)
  @genome.dump(serializer: serializer)
end

#find_geneObject



228
229
230
231
232
# File 'lib/evolvable.rb', line 228

def_delegators :genome,
:find_gene,
:find_genes,
:find_genes_count,
:genes

#find_genesObject



228
229
230
231
232
# File 'lib/evolvable.rb', line 228

def_delegators :genome,
:find_gene,
:find_genes,
:find_genes_count,
:genes

#find_genes_countObject



228
229
230
231
232
# File 'lib/evolvable.rb', line 228

def_delegators :genome,
:find_gene,
:find_genes,
:find_genes_count,
:genes

#genesObject



228
229
230
231
232
# File 'lib/evolvable.rb', line 228

def_delegators :genome,
:find_gene,
:find_genes,
:find_genes_count,
:genes

#load_genome(data, serializer: Serializer) ⇒ Object



238
239
240
# File 'lib/evolvable.rb', line 238

def load_genome(data, serializer: Serializer)
  @genome = Genome.load(data, serializer: serializer)
end

#population_indexObject

Deprecated.

Will be removed in version 2.0. Use #generation_index instead.



214
215
216
# File 'lib/evolvable.rb', line 214

def population_index
  generation_index
end