@ Override protected List < Node > mate ( Node parent1 , Node parent2 , int numberOfCrossoverPoints , Random rng ) { List < Node > offspring = new ArrayList < Node > ( 2 ) ; Node offspring1 = parent1 ; Node offspring2 = parent2 ; for ( int i = 0 ; i < numberOfCrossoverPoints ; i ++ ) { int crossoverPoint1 = rng . nextInt ( parent1 . countNodes ( ) ) ; Node subTree1 = parent1 . getNode ( crossoverPoint1 ) ; int crossoverPoint2 = rng . nextInt ( parent2 . countNodes ( ) ) ; Node subTree2 = parent2 . getNode ( crossoverPoint2 ) ; offspring1 = parent1 . replaceNode ( crossoverPoint1 , subTree2 ) ; offspring2 = parent2 . replaceNode ( crossoverPoint2 , subTree1 ) ; } offspring . add ( offspring1 ) ; offspring . add ( offspring2 ) ; return offspring ; }
Swaps randomly selected sub - trees between the two parents .