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 licencing 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 examples.grid.mathProblemDistributed;
11:
12: import org.jgap.distr.grid.*;
13: import org.jgap.distr.grid.gp.*;
14: import org.jgap.*;
15: import org.jgap.gp.impl.*;
16:
17: /**
18: * Initializes the genotype on behalf of the workers in a grid.
19: *
20: * @author Klaus Meffert
21: * @since 3.2
22: */
23: public class MyGenotypeInitializer implements IGenotypeInitializerGP {
24: /** String containing the CVS revision. Read out via reflection!*/
25: private final static String CVS_REVISION = "$Revision: 1.4 $";
26:
27: public GPGenotype setupGenotype(JGAPRequestGP a_req,
28: GPPopulation a_initialPop) throws Exception {
29: GPConfiguration conf = a_req.getConfiguration();
30: GPPopulation pop;
31: if (a_initialPop == null) {
32: pop = new GPPopulation(conf, conf.getPopulationSize());
33: /**@todo add a mechanism to allow workers to initialize the population
34: * they work with.
35: */
36: } else {
37: if (a_initialPop.isFirstEmpty()) {
38: throw new RuntimeException(
39: "Initial population must either be null"
40: + " or be completely filled with gp programs!");
41: }
42: pop = a_initialPop;
43: }
44: int size = conf.getPopulationSize() - pop.size();
45: IGridConfigurationGP gridConfig = a_req.getGridConfiguration();
46: GPGenotype result = new GPGenotype(conf, pop, gridConfig
47: .getTypes(), gridConfig.getArgTypes(), gridConfig
48: .getNodeSets(), gridConfig.getMinDepths(), gridConfig
49: .getMaxDepths(), gridConfig.getMaxNodes());
50: return result;
51: }
52: }
|