KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > ConfigurationForTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap;
11
12 import org.jgap.event.*;
13 import org.jgap.impl.*;
14
15 /**
16  * Ready-to-go Implementation of org.jgap.Configuration with all important
17  * parameters already set.
18  *
19  * @author Klaus Meffert
20  * @since 2.2
21  */

22 public class ConfigurationForTest
23     extends Configuration {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.7 $";
26
27   public final static double STATIC_FITNESS_VALUE = 2.3d;
28
29   /**
30    * Default constructor
31    * @throws InvalidConfigurationException
32    *
33    * @author Klaus Meffert
34    * @since 2.2
35    */

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   /**
59    * Allows to set the random generator freely, also to null (normally
60    * forbidden).
61    * @param a_generatorToSet the random generator to set
62    * @throws InvalidConfigurationException
63    *
64    * @author Klaus Meffert
65    * @since 3.0
66    */

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 JavaDoc nex) {
74       throw new InvalidConfigurationException(nex.getMessage());
75     }
76   }
77 }
78
Popular Tags