KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > DefaultConfiguration


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.impl;
11
12 import org.jgap.*;
13 import org.jgap.event.*;
14 import org.jgap.util.*;
15
16 /**
17  * The DefaultConfiguration class simplifies the JGAP configuration
18  * process by providing default configuration values for many of the
19  * configuration settings. The following values must still be provided:
20  * the sample Chromosome, population size, and desired fitness function.
21  * All other settings may also be changed in the normal fashion for
22  * those who wish to specify other custom values.
23  *
24  * @author Neil Rotstan
25  * @author Klaus Meffert
26  * @since 1.0
27  */

28 public class DefaultConfiguration
29     extends Configuration implements ICloneable {
30   /** String containing the CVS revision. Read out via reflection!*/
31   private final static String JavaDoc CVS_REVISION = "$Revision: 1.19 $";
32
33   public DefaultConfiguration() {
34     this("","");
35   }
36   /**
37    * Constructs a new DefaultConfiguration instance with a number of
38    * configuration settings set to default values. It is still necessary
39    * to set the sample Chromosome, population size, and desired fitness
40    * function. Other settings may optionally be altered as desired.
41    *
42    * @author Neil Rotstan
43    * @author Klaus Meffert
44    * @since 1.0
45    */

46   public DefaultConfiguration(String JavaDoc a_id, String JavaDoc a_name) {
47     super(a_id, a_name);
48     try {
49       setRandomGenerator(new StockRandomGenerator());
50       setEventManager(new EventManager());
51       BestChromosomesSelector bestChromsSelector = new BestChromosomesSelector(
52           this, 0.95d);
53       bestChromsSelector.setDoubletteChromosomesAllowed(false);
54       addNaturalSelector(bestChromsSelector, true);
55       setMinimumPopSizePercent(0);
56       setKeepPopulationSizeConstant(true);
57       setFitnessEvaluator(new DefaultFitnessEvaluator());
58       setChromosomePool(new ChromosomePool());
59       addGeneticOperator(new CrossoverOperator(this));
60       addGeneticOperator(new MutationOperator(this, 15));
61     }
62     catch (InvalidConfigurationException e) {
63       throw new RuntimeException JavaDoc(
64           "Fatal error: DefaultConfiguration class could not use its "
65           + "own stock configuration values. This should never happen. "
66           + "Please report this as a bug to the JGAP team.");
67     }
68   }
69
70   /**
71    * @return deep clone of this instance
72    *
73    * @author Klaus Meffert
74    * @since 3.2
75    */

76   public Object JavaDoc clone() {
77     return super.clone();
78   }
79 }
80
Popular Tags