StructuralMutation extends MutationOperation { @Override public void doOperation(Individual operand) { ContextualDerivationTree tree = (ContextualDerivationTree) GenotypeHelper.buildDerivationTree(operand); GEChromosome chromosome = (GEChromosome)operand.getGenotype().get(0); if(tree!=null) { ArrayList<Integer> structCodonList = new ArrayList(tree.getStructCodonList()); for(int i =0;i< structCodonList.size();i++) { int codonIndex =structCodonList.get(i); if(this.rng.nextBoolean(this.probability)) { chromosome.set(codonIndex, Math.abs(rng.nextInt())); tree = (ContextualDerivationTree) GenotypeHelper.buildDerivationTree(operand); } } ((GEIndividual)operand).invalidate(); tree = null; } } StructuralMutation(RandomNumberGenerator rng, Properties p);  StructuralMutation(double prob, RandomNumberGenerator rng); void setCreationOperation(CreationOperation creationOperation); @Override void doOperation(Individual operand); @Override void doOperation(List<Individual> operands);  }
@Test public void testDoOperation_Individual() { System.out.println("Structural muation doOperation"); GEIndividual operand = IndividualMaker.makeIndividual(p); int[] chromosome = {0,1,2,1,2,Integer.MIN_VALUE,Integer.MAX_VALUE,0,2,1,1,1}; int[] expected = {111352301,1,2,1,2,-2147483648,2147483647,0,2,1,1,1}; GEChromosome geChromosome = (GEChromosome)operand.getGenotype().get(0); geChromosome.setAll(chromosome); StructuralMutation instance = new StructuralMutation(0.5, new MersenneTwisterFast(2)); instance.doOperation(operand); JUnitHelper.checkArrays(expected, geChromosome.data); GEIndividualTest.testInvalidated(operand); operand = IndividualMaker.makeIndividual(p); geChromosome = null; try { instance.doOperation(operand); } catch(NullPointerException e) { assertTrue(true); } GEIndividualTest.testInvalidated(operand); }