Module: TreeCrossover
- Defined in:
- lib/charlie/tree/tree.rb
Overview
TreeCrossover does a standard subtree swapping crossover for trees.
Instance Method Summary collapse
Instance Method Details
#cross(parent1, parent2) ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/charlie/tree/tree.rb', line 166 def cross(parent1,parent2) child1 = parent1.dup child2 = parent2.dup c1_st = child1.random_subtree c2_st = child1.random_subtree c1_copy = dup_tree(c1_st) c1_st.replace dup_tree(c2_st) c2_st.replace c1_copy [child1,child2] end |