1 10 package org.jgap; 11 12 import org.jgap.event.*; 13 import org.jgap.impl.*; 14 15 22 public class ConfigurationForTest 23 extends Configuration { 24 25 private final static String CVS_REVISION = "$Revision: 1.7 $"; 26 27 public final static double STATIC_FITNESS_VALUE = 2.3d; 28 29 36 public ConfigurationForTest() 37 throws InvalidConfigurationException { 38 super(); 39 setPopulationSize(5); 40 reset(); 41 setFitnessFunction(new StaticFitnessFunction(STATIC_FITNESS_VALUE)); 42 setEventManager(new EventManager()); 43 setFitnessEvaluator(new DefaultFitnessEvaluator()); 44 addNaturalSelector(new BestChromosomesSelector(this), true); 45 addGeneticOperator(new MutationOperator(this, new DefaultMutationRateCalculator(this))); 46 setRandomGenerator(new StockRandomGenerator()); 47 Gene[] genes = new Gene[3]; 48 Gene gene = new BooleanGene(this); 49 genes[0] = gene; 50 gene = new StringGene(this, 1,10,StringGene.ALPHABET_CHARACTERS_LOWER); 51 genes[1] = gene; 52 gene = new IntegerGene(this, 100,300); 53 genes[2] = gene; 54 Chromosome chrom = new Chromosome(this, genes); 55 setSampleChromosome(chrom); 56 } 57 58 67 public synchronized void setRandomGenerator(RandomGenerator a_generatorToSet) 68 throws InvalidConfigurationException { 69 try { 70 junitx.util.PrivateAccessor.setField(this, "m_randomGenerator", 71 a_generatorToSet); 72 } 73 catch (NoSuchFieldException nex) { 74 throw new InvalidConfigurationException(nex.getMessage()); 75 } 76 } 77 } 78 | Popular Tags |