Module: PermutationCrossover
- Defined in:
- lib/charlie/permutation/permutation.rb
Overview
-
One point partial preservation crossover for PermutationGenotype
-
Also known as partial recombination crossover (PRX).
-
Child 1 is identical to parent 1 up to the cross point, and contains the remaining elements in the same order as parent 2.
Instance Method Summary collapse
Instance Method Details
#cross(parent1, parent2) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/charlie/permutation/permutation.rb', line 82 def cross(parent1,parent2) p1, p2 = parent1.genes, parent2.genes cross_pt = rand(p1.size+1) st1, st2 = p1[0...cross_pt], p2[0...cross_pt] [ st1 + (p2 - st1), st2 + (p1 - st2) ].map{|x| from_genes(x) } end |