public void eval(
      int seed, String parent1Expression, String parent2Expression, String offspringExpression) {
    EncogProgramContext context = new EncogProgramContext();
    StandardExtensions.createNumericOperators(context.getFunctions());

    // parent 1
    EncogProgram parent1 = new EncogProgram(context);
    parent1.getVariables().setVariable("x", 1);
    parent1.compileExpression(parent1Expression);

    // parent 2
    EncogProgram parent2 = new EncogProgram(context);
    parent2.getVariables().setVariable("x", 1);
    parent2.compileExpression(parent2Expression);

    // offspring
    EncogProgram[] offspring = parent1.allocateOffspring(1);

    EvolutionaryOperator cross = new SubtreeCrossover();
    Genome[] parents = {parent1, parent2};
    cross.performOperation(new Random(seed), parents, 0, offspring, 0);
    offspring[0].getVariables().setVariable("x", 1);

    RenderCommonExpression render = new RenderCommonExpression();
    // Assert.assertEquals(offspringExpression,render.render(offspring[0]));
  }
Ejemplo n.º 2
0
 public PrgPopulation(EncogProgramContext theContext, GenomeFactory theGenomeFactory) {
   super(theContext.getParams().getPopulationSize(), theGenomeFactory);
   GeneticTrainingParams params = theContext.getParams();
   this.holder =
       theContext
           .getHolderFactory()
           .factor(params.getPopulationSize(), params.getMaxIndividualSize());
   this.context = theContext;
 }