Class: Operator::MutationAlteringCore
- Inherits:
-
Object
- Object
- Operator::MutationAlteringCore
- Defined in:
- ../lib/mutation_altering.rb
Overview
Common functionality for MutationBitNodal, MutationBitStructural, MutationNodal and MutationStructural classes.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) offset
Offset which is added to the index of the mutated codon’s position.
Instance Method Summary (collapse)
-
- (MutationAlteringCore) initialize(grammar)
constructor
See a subclass description.
-
- (Object) mutation(orig, track)
See a subclass description.
Constructor Details
- (MutationAlteringCore) initialize(grammar)
See a subclass description.
10 11 12 13 14 |
# File '../lib/mutation_altering.rb', line 10 def initialize( grammar ) @grammar = grammar @random = Kernel @offset = 0 end |
Instance Attribute Details
- (Object) offset
Offset which is added to the index of the mutated codon’s position. This is useful for Mapper::*Locus mappers where the odd codons encode a location choices and even codons encode rule choices.
30 31 32 |
# File '../lib/mutation_altering.rb', line 30 def offset @offset end |
Instance Method Details
- (Object) mutation(orig, track)
See a subclass description.
17 18 19 20 21 22 23 24 25 |
# File '../lib/mutation_altering.rb', line 17 def mutation( orig, track ) mutant = orig.clone filtered_track = track.find_all { |node| @grammar[ node.symbol ].sn_altering == filter } return mutant if filtered_track.empty? where = @random.rand( filtered_track.size ) index = ( filtered_track[where].from + @offset ).divmod( mutant.size ).last mutant[ index ] = get_codon_value( mutant, index ) mutant end |