Class: MHL::IntegerVectorGenotypeSpace
- Inherits:
-
Object
- Object
- MHL::IntegerVectorGenotypeSpace
- Defined in:
- lib/mhl/integer_genotype_space.rb
Overview
This class implements a genotype with integer space representation
Instance Method Summary collapse
- #get_random ⇒ Object
-
#initialize(opts) ⇒ IntegerVectorGenotypeSpace
constructor
A new instance of IntegerVectorGenotypeSpace.
-
#reproduce_from(p1, p2, mutation_rv, recombination_rv) ⇒ Object
reproduction with random geometric mutation and intermediate recombination.
Constructor Details
#initialize(opts) ⇒ IntegerVectorGenotypeSpace
Returns a new instance of IntegerVectorGenotypeSpace.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mhl/integer_genotype_space.rb', line 5 def initialize(opts) @random_func = opts[:random_func] @dimensions = opts[:dimensions].to_i unless @dimensions and @dimensions > 0 raise ArgumentError, 'Must have positive integer dimensions' end # TODO: enable to choose which recombination function to use case opts[:recombination_type].to_s when /intermediate/i @recombination_func = :intermediate_recombination when /line/i @recombination_func = :line_recombination else raise ArgumentError, 'Recombination function must be either line or intermediate!' end end |
Instance Method Details
#get_random ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/mhl/integer_genotype_space.rb', line 24 def get_random if @random_func @random_func.call else # TODO: implement this end end |
#reproduce_from(p1, p2, mutation_rv, recombination_rv) ⇒ Object
reproduction with random geometric mutation and intermediate recombination
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mhl/integer_genotype_space.rb', line 34 def reproduce_from(p1, p2, mutation_rv, recombination_rv) # make copies of p1 and p2 # (we're only interested in the :genotype key) c1 = { :genotype => p1[:genotype].dup } c2 = { :genotype => p2[:genotype].dup } # mutation comes first random_geometric_mutation(c1[:genotype], mutation_rv) random_geometric_mutation(c2[:genotype], mutation_rv) # and then recombination send(@recombination_func, c1[:genotype], c2[:genotype], recombination_rv) return c1, c2 end |