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