Ejemplo n.º 1
0
 /**
  * Verifies that terminals are passed as clones during evolution and not as references. Thanx a
  * lot Javier for pointing this out nicely!
  *
  * @throws Exception
  * @author Klaus Meffert
  * @since 3.2
  */
 public void testReferenceProblem_0() throws Exception {
   m_gpconf.setPopulationSize(30);
   m_gpconf.setGPFitnessEvaluator(new DeltaGPFitnessEvaluator());
   m_gpconf.setFitnessFunction(new TerminalsOnly());
   m_gpconf.setRandomGenerator(new StockRandomGenerator());
   //
   Class[] types = {CommandGene.IntegerClass};
   Class[][] argTypes = {{}};
   CommandGene[][] nodeSets = {
     {
       new Increment(m_gpconf, CommandGene.IntegerClass, 1),
       new Terminal(m_gpconf, CommandGene.IntegerClass, 1.0d, 10000.0d),
     }
   };
   GPGenotype gen =
       GPGenotype.randomInitialGenotype(m_gpconf, types, argTypes, nodeSets, 10, false);
   gen.getGPPopulation().sort(new TerminalsFirstComparator());
   IGPProgram prog1 = gen.getGPPopulation().getGPProgram(0);
   ProgramChromosome chrom1 = prog1.getChromosome(0);
   Terminal gene1 = (Terminal) chrom1.getGene(0);
   IGPProgram prog2 = gen.getGPPopulation().getGPProgram(1);
   ProgramChromosome chrom2 = prog2.getChromosome(0);
   Terminal gene2 = (Terminal) chrom2.getGene(0);
   assertNotSame(gene1, gene2);
 }
Ejemplo n.º 2
0
 protected double evaluate(IGPProgram a_subject) {
   ProgramChromosome chrom1 = a_subject.getChromosome(0);
   CommandGene gene1 = chrom1.getGene(0);
   if (gene1 instanceof Terminal) {
     return gene1.execute_double(null, 0, new Object[] {});
   } else {
     return 999999.0d;
   }
 }