01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licensing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
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 extends Configuration implements
29: ICloneable {
30: /** String containing the CVS revision. Read out via reflection!*/
31: private final static String CVS_REVISION = "$Revision: 1.25 $";
32:
33: public DefaultConfiguration() {
34: this ("", "");
35: }
36:
37: /**
38: * Constructs a new DefaultConfiguration instance with a number of
39: * configuration settings set to default values. It is still necessary
40: * to set the sample Chromosome, population size, and desired fitness
41: * function. Other settings may optionally be altered as desired.
42: *
43: * @param a_id unique id for the configuration within the current thread
44: * @param a_name informative name of the configuration, may be null
45: *
46: * @author Neil Rotstan
47: * @author Klaus Meffert
48: * @since 1.0
49: */
50: public DefaultConfiguration(String a_id, String a_name) {
51: super (a_id, a_name);
52: try {
53: setBreeder(new GABreeder());
54: setRandomGenerator(new StockRandomGenerator());
55: setEventManager(new EventManager());
56: BestChromosomesSelector bestChromsSelector = new BestChromosomesSelector(
57: this , 0.95d);
58: bestChromsSelector.setDoubletteChromosomesAllowed(true);
59: addNaturalSelector(bestChromsSelector, true);
60: setMinimumPopSizePercent(0);
61: //
62: setSelectFromPrevGen(1.0d);
63: setKeepPopulationSizeConstant(true);
64: setFitnessEvaluator(new DefaultFitnessEvaluator());
65: setChromosomePool(new ChromosomePool());
66: addGeneticOperator(new CrossoverOperator(this ));
67: addGeneticOperator(new MutationOperator(this , 15));
68: } catch (InvalidConfigurationException e) {
69: throw new RuntimeException(
70: "Fatal error: DefaultConfiguration class could not use its "
71: + "own stock configuration values. This should never happen. "
72: + "Please report this as a bug to the JGAP team.");
73: }
74: }
75:
76: /**
77: * @return deep clone of this instance
78: *
79: * @author Klaus Meffert
80: * @since 3.2
81: */
82: public Object clone() {
83: return super.clone();
84: }
85: }
|