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 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.impl.*;
16: import org.jgap.event.*;
17: import org.homedns.dade.jcgrid.client.*;
18: import org.jgap.gp.impl.*;
19:
20: /**
21: * Main configuration for defining the problem and the way it is solved in the
22: * grid. Thus, the most important class in a JGAP Grid!
23: *
24: * @author Klaus Meffert
25: * @since 3.2
26: */
27: public class GridConfiguration extends GridConfigurationGPBase {
28: /** String containing the CVS revision. Read out via reflection!*/
29: private final static String CVS_REVISION = "$Revision: 1.5 $";
30:
31: public GridConfiguration() {
32: super ();
33: }
34:
35: public void initialize(GridNodeClientConfig a_gridconfig)
36: throws Exception {
37: // Create the problem to be solved.
38: // --------------------------------
39: if (a_gridconfig != null) {
40: a_gridconfig.setSessionName("JGAP_mathprob_distributed");
41: }
42: GPConfiguration jgapconfig = new GPConfiguration();
43: jgapconfig.setEventManager(new EventManager());
44: jgapconfig.setPopulationSize(500);
45: jgapconfig.setKeepPopulationSizeConstant(true);
46: IChromosome sample = new Chromosome(jgapconfig,
47: new BooleanGene(jgapconfig), 16);
48: jgapconfig.setSampleChromosome(sample);
49: // Setup parameters.
50: // -----------------
51: setWorkerReturnStrategy(new MyWorkerReturnStrategy());
52: // How to initialize the Genotype on behalf of the workers.
53: // --------------------------------------------------------
54: setGenotypeInitializer(new MyGenotypeInitializer());
55: // How to evolve on the worker side.
56: // ---------------------------------
57: setWorkerEvolveStrategy(new MyEvolveStrategy());
58: // Setup the client to produce a work request for each chromosome
59: // to get its fitness value computed by a single worker.
60: // --------------------------------------------------------------
61: setRequestSplitStrategy(new MyRequestSplitStrategy(jgapconfig));
62: setConfiguration(jgapconfig);
63: // Set the evolution process (but evolve on workers).
64: // --------------------------------------------------
65: setClientEvolveStrategy(new ClientEvolveStrategy());
66: jgapconfig.setFitnessFunction(new SampleFitnessFunction());
67: // Optional: Register client feedback listener.
68: // --------------------------------------------
69: setClientFeedback(new MyClientFeedback());
70: }
71:
72: public void validate() throws Exception {
73: if (getRequestSplitStrategy() == null) {
74: throw new RuntimeException(
75: "Please set the request split strategy first!");
76: }
77: if (getConfiguration() == null) {
78: throw new RuntimeException(
79: "Please set the configuration first!");
80: }
81: }
82: }
|