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
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
-
#generation_index ⇒ Object
Returns the value of attribute generation_index.
-
#genome ⇒ Object
Returns the value of attribute genome.
-
#id ⇒ Object
Returns the value of attribute id.
-
#population ⇒ Object
Returns the value of attribute population.
-
#value ⇒ Object
Implementing this method is required for evaluation and selection.
Class Method Summary collapse
Instance Method Summary collapse
-
#after_initialize ⇒ Object
Runs an evolvable is initialized.
- #dump_genome(serializer: Serializer) ⇒ Object
- #find_gene ⇒ Object
- #find_genes ⇒ Object
- #find_genes_count ⇒ Object
- #genes ⇒ Object
- #load_genome(data, serializer: Serializer) ⇒ Object
-
#population_index ⇒ Object
deprecated
Deprecated.
Will be removed in version 2.0. Use #generation_index instead.
Instance Attribute Details
#generation_index ⇒ Object
Returns the value of attribute generation_index.
203 204 205 |
# File 'lib/evolvable.rb', line 203 def generation_index @generation_index end |
#genome ⇒ Object
Returns the value of attribute genome.
203 204 205 |
# File 'lib/evolvable.rb', line 203 def genome @genome end |
#id ⇒ Object
Returns the value of attribute id.
203 204 205 |
# File 'lib/evolvable.rb', line 203 def id @id end |
#population ⇒ Object
Returns the value of attribute population.
203 204 205 |
# File 'lib/evolvable.rb', line 203 def population @population end |
#value ⇒ Object
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_initialize ⇒ Object
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_gene ⇒ Object
228 229 230 231 232 |
# File 'lib/evolvable.rb', line 228 def_delegators :genome, :find_gene, :find_genes, :find_genes_count, :genes |
#find_genes ⇒ Object
228 229 230 231 232 |
# File 'lib/evolvable.rb', line 228 def_delegators :genome, :find_gene, :find_genes, :find_genes_count, :genes |
#find_genes_count ⇒ Object
228 229 230 231 232 |
# File 'lib/evolvable.rb', line 228 def_delegators :genome, :find_gene, :find_genes, :find_genes_count, :genes |
#genes ⇒ Object
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_index ⇒ Object
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 |