Class: Evolvable::GeneCombination
- Inherits:
-
Object
- Object
- Evolvable::GeneCombination
- Defined in:
- lib/evolvable/gene_combination.rb
Instance Method Summary collapse
-
#call(population) ⇒ Evolvable::Population
Performs the combination operation on the population.
-
#combine_genomes(genome_1, genome_2) ⇒ Evolvable::Genome
Combines two parent genomes to create a new genome.
-
#new_evolvables(population, count) ⇒ Array<Evolvable>
Creates new evolvable instances by combining parent genomes.
Instance Method Details
#call(population) ⇒ Evolvable::Population
Performs the combination operation on the population. Creates new evolvables by combining parent genomes.
28 29 30 31 |
# File 'lib/evolvable/gene_combination.rb', line 28 def call(population) new_evolvables(population, population.size) population end |
#combine_genomes(genome_1, genome_2) ⇒ Evolvable::Genome
Combines two parent genomes to create a new genome. For each gene key, combines the count genes and individual genes.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/evolvable/gene_combination.rb', line 58 def combine_genomes(genome_1, genome_2) new_config = {} genome_1.each do |gene_key, gene_config_1| gene_config_2 = genome_2.config[gene_key] count_gene = combine_count_genes(gene_config_1, gene_config_2) genes = combine_genes(count_gene.count, gene_config_1, gene_config_2) new_config[gene_key] = { count_gene: count_gene, genes: genes } end Genome.new(config: new_config) end |
#new_evolvables(population, count) ⇒ Array<Evolvable>
Creates new evolvable instances by combining parent genomes. For each new evolvable, selects parent genomes and combines them.
41 42 43 44 45 46 47 48 |
# File 'lib/evolvable/gene_combination.rb', line 41 def new_evolvables(population, count) parent_genome_cycle = population.new_parent_genome_cycle Array.new(count) do genome_1, genome_2 = parent_genome_cycle.next genome = combine_genomes(genome_1, genome_2) population.new_evolvable(genome: genome) end end |