Class: Evolvable::GeneSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/evolvable/gene_space.rb

Overview

The gene space defines the structure of an evolvable's genome. It acts as a blueprint that describes what kinds of genes each evolvable instance should have—and how many.

At runtime, Evolvable::GeneSpace is responsible for interpreting this blueprint, constructing genomes, and managing gene configurations. You typically won’t need to interact with GeneSpace directly.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: {}, evolvable_class: nil) ⇒ GeneSpace

Returns a new instance of GeneSpace.



29
30
31
32
# File 'lib/evolvable/gene_space.rb', line 29

def initialize(config: {}, evolvable_class: nil)
  @evolvable_class = evolvable_class
  @config = normalize_config(config)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



34
35
36
# File 'lib/evolvable/gene_space.rb', line 34

def config
  @config
end

#evolvable_classObject

Returns the value of attribute evolvable_class.



34
35
36
# File 'lib/evolvable/gene_space.rb', line 34

def evolvable_class
  @evolvable_class
end

Class Method Details

.build(config, evolvable_class = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/evolvable/gene_space.rb', line 19

def build(config, evolvable_class = nil)
  if config.is_a?(GeneSpace)
    config.evolvable_class = evolvable_class if evolvable_class
    config
  else
    new(config: config, evolvable_class: evolvable_class)
  end
end

Instance Method Details

#merge_gene_space(val) ⇒ Object



40
41
42
43
# File 'lib/evolvable/gene_space.rb', line 40

def merge_gene_space(val)
  val = val.config if val.is_a?(self.class)
  @config.merge normalize_config(val)
end

#merge_gene_space!(val) ⇒ Object



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

def merge_gene_space!(val)
  val = val.config if val.is_a?(self.class)
  @config.merge! normalize_config(val)
end

#new_genomeObject



36
37
38
# File 'lib/evolvable/gene_space.rb', line 36

def new_genome
  Genome.new(config: new_genome_config)
end