예제 #1
0
 @Override
 public ExprTree mutateExprTree(ExprTree ptree, ExprTreeSchema schema, IRandGen randgen) {
   // Copy of expr
   ExprTree stree = ptree.copy();
   // Node selection
   int selectIndex = randgen.choose(0, ptree.size());
   // Mutated node
   IPrimitive oldBlock = stree.getBlock(selectIndex);
   Class<?> rtype = oldBlock.returnType();
   int arity = oldBlock.argumentTypes().length;
   IPrimitive newBlock = schema.getAnyBlock(rtype, randgen, arity);
   stree.setBlock(newBlock, selectIndex);
   // Return result
   return stree;
 }
예제 #2
0
  @Override
  protected void createParents() {
    parents = new ArrayList<IIndividual>();

    // Parent genotype
    ExprTree genotype = new ExprTree();
    genotype.addBlock(new Add());
    genotype.addBlock(new X());
    genotype.addBlock(new Sub());
    genotype.addBlock(new Mul());
    genotype.addBlock(new Add());
    genotype.addBlock(new X());
    genotype.addBlock(new Y());
    genotype.addBlock(new Y());
    genotype.addBlock(new Z());

    // Add individual to the parents set
    parents.add(new ExprTreeIndividual(genotype));
  }
  @Override
  protected void createExpected() {
    expected = new ArrayList<IIndividual>();

    // Mutated individual genotype
    ExprTree genotype = new ExprTree();
    genotype.addBlock(new Add());
    genotype.addBlock(new X());
    genotype.addBlock(new Add());
    genotype.addBlock(new Sub());
    genotype.addBlock(new X());
    genotype.addBlock(new Y());
    genotype.addBlock(new Z());

    // Add individual to expected set
    expected.add(new ExprTreeIndividual(genotype));
  }