| Path: | lib/charlie/permutation/permutation.rb |
| Last Update: | Sat Apr 05 14:47:39 +0200 2008 |
Contains genotypes, crossovers and mutators for permutations
# File lib/charlie/permutation/permutation.rb, line 12
12: def initialize
13: @genes = elements.dup.shuffle
14: end
Generates a genotype class which represents a permutation of elements Includes the PermutationMutator and PermutationCrossover by default
# File lib/charlie/permutation/permutation.rb, line 5
5: def PermutationGenotype(n,elements=0...n)
6: elements = elements.chars if elements.is_a? String # string to array of chars
7: elements = elements.to_a
8: Class.new(Genotype) {
9: define_method(:size) { n }
10: define_method(:elements){ elements }
11:
12: def initialize
13: @genes = elements.dup.shuffle
14: end
15:
16: def to_s
17: @genes.inspect
18: end
19: use TranspositionMutator.dup , PCross(0.75,PermutationCrossover)
20: }
21: end