Class: Operator::MutationBitRipple
- Inherits:
-
Object
- Object
- Operator::MutationBitRipple
- Defined in:
- ../lib/mutation_ripple.rb
Overview
Simple bit-level mutation. It assumes the source genotype has the form of the Array of codons with an interpretation given by CodonMod (see).
Instance Attribute Summary (collapse)
-
- (Object) codon
Codon encoding scheme.
-
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
Instance Method Summary (collapse)
-
- (MutationBitRipple) initialize(dummy = nil)
constructor
Create the mutation operator with default settings.
-
- (Object) mutation(orig, dummy = nil)
Select the random position within the orig vector and mutate it.
Constructor Details
- (MutationBitRipple) initialize(dummy = nil)
Create the mutation operator with default settings.
12 13 14 15 |
# File '../lib/mutation_ripple.rb', line 12 def initialize dummy=nil @random = Kernel @codon = CodonMod.new # standard 8-bit codons end |
Instance Attribute Details
- (Object) codon
Codon encoding scheme. By default the instance of the CodonMod class is used (ie. standard GE 8-bit codons) See CodonMod for details.
19 20 21 |
# File '../lib/mutation_ripple.rb', line 19 def codon @codon end |
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
22 23 24 |
# File '../lib/mutation_ripple.rb', line 22 def random @random end |
Instance Method Details
- (Object) mutation(orig, dummy = nil)
Select the random position within the orig vector and mutate it. The resultant value (of a mutated codon) is bit-mutated by self.codon.mutate_bit method. Return the mutated copy of the orig. genotype.
33 34 35 36 37 38 |
# File '../lib/mutation_ripple.rb', line 33 def mutation( orig, dummy=nil ) mutant = orig.clone where = @random.rand( orig.size ) mutant[ where ] = @codon.mutate_bit( mutant.at(where) ) mutant end |