| Path: | lib/charlie/list/list_mutate.rb |
| Last Update: | Wed Dec 19 17:38:34 +0100 2007 |
List mutators: generated by the ListMutator function
| MutationStrategies | = | { # TODO: change to default parameters in 1.9 :probability => Proc.new{|genes,pointmut,p| p ||= 0.05 |
The mutation strategies for ListMutator
|
|
| PointMutators | = | { :replace => proc{|x,*pos| pos.at_rand }, :flip => proc{|x| 1-x }, :uniform => Proc.new{|x,max_size| max_size ||= 0.25; |
The point mutators for ListMutator
|
Generates a module which can be used as a mutator for array-based genotypes like FloatListGenotype, BitStringGenotype and StringGenotype
# File lib/charlie/list/list_mutate.rb, line 48
48: def ListMutator(strategy=:expected_n ,point_mutator=:uniform)
49: strat, *strat_args = *strategy
50: pm , *pm_args = *point_mutator
51:
52: pm ||= proc{}
53:
54: strat = MutationStrategies[strat.intern] unless strat.is_a? Proc
55: pm = PointMutators[pm.intern] unless pm.is_a? Proc
56:
57: raise ArgumentError,"Invalid mutation strategy" if strat.nil?
58: raise ArgumentError,"Invalid point mutator" if point_mutator.nil?
59:
60: if pm_args.empty?
61: point_mutator_with_args = pm
62: else
63: point_mutator_with_args = proc{|*args| pm.call(*(args+pm_args) ) }
64: end
65:
66: Module.new{
67: define_method(:mutate!) {
68: strat.call(@genes,point_mutator_with_args,*strat_args)
69: self
70: }
71: self.name= "ListMutator(#{strategy.inspect},#{point_mutator.inspect})"
72: }
73: end