KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > grid > evolutionDistributed > GridConfiguration


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

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
26     extends GridConfigurationBase {
27   /** String containing the CVS revision. Read out via reflection!*/
28   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
29
30   public GridConfiguration() {
31     super();
32   }
33
34   public void initialize(GridNodeClientConfig a_gridconfig)
35       throws Exception JavaDoc {
36     // Create the problem to be solved.
37
// --------------------------------
38
if (a_gridconfig != null) {
39       a_gridconfig.setSessionName("JGAP_evolution_distributed");
40     }
41     Configuration jgapconfig = new DefaultConfiguration();
42     jgapconfig.setEventManager(new EventManager());
43     jgapconfig.setPopulationSize(500);
44     jgapconfig.setKeepPopulationSizeConstant(true);
45     jgapconfig.setFitnessFunction(new SampleFitnessFunction());
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     // Optional: Register client feedback listener.
67
// --------------------------------------------
68
// setClientFeedback(new MyClientFeedback());
69
}
70
71   public void validate()
72       throws Exception JavaDoc {
73     if (getRequestSplitStrategy() == null) {
74       throw new RuntimeException JavaDoc("Please set the request split strategy first!");
75     }
76     if (getConfiguration() == null) {
77       throw new RuntimeException JavaDoc("Please set the configuration first!");
78     }
79   }
80 }
81
Popular Tags