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.evolutionDistributed;
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 GridConfiguration() {
30: super ();
31: }
32:
33: public void initialize(GridNodeClientConfig a_gridconfig)
34: throws Exception {
35: // Create the problem to be solved.
36: // --------------------------------
37: if (a_gridconfig != null) {
38: a_gridconfig.setSessionName("JGAP_evolution_distributed");
39: }
40: Configuration jgapconfig = new DefaultConfiguration();
41: jgapconfig.setEventManager(new EventManager());
42: jgapconfig.setPopulationSize(500);
43: jgapconfig.setKeepPopulationSizeConstant(true);
44: jgapconfig.setFitnessFunction(new SampleFitnessFunction());
45: IChromosome sample = new Chromosome(jgapconfig,
46: new BooleanGene(jgapconfig), 16);
47: jgapconfig.setSampleChromosome(sample);
48: // Setup parameters.
49: // -----------------
50: setWorkerReturnStrategy(new MyWorkerReturnStrategy());
51: // How to initialize the Genotype on behalf of the workers.
52: // --------------------------------------------------------
53: setGenotypeInitializer(new MyGenotypeInitializer());
54: // How to evolve on the worker side.
55: // ---------------------------------
56: setWorkerEvolveStrategy(new MyEvolveStrategy());
57: // Setup the client to produce a work request for each chromosome
58: // to get its fitness value computed by a single worker.
59: // --------------------------------------------------------------
60: setRequestSplitStrategy(new MyRequestSplitStrategy(jgapconfig));
61: setConfiguration(jgapconfig);
62: // Set the evolution process (but evolve on workers).
63: // --------------------------------------------------
64: setClientEvolveStrategy(new ClientEvolveStrategy());
65: // Optional: Register client feedback listener.
66: // --------------------------------------------
67: // setClientFeedback(new MyClientFeedback());
68: }
69:
70: public void validate() throws Exception {
71: if (getRequestSplitStrategy() == null) {
72: throw new RuntimeException(
73: "Please set the request split strategy first!");
74: }
75: if (getConfiguration() == null) {
76: throw new RuntimeException(
77: "Please set the configuration first!");
78: }
79: }
80: }
|