KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > grid > fitnessDistributed > 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.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
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 void initialize(GridNodeClientConfig gridconfig)
31       throws Exception JavaDoc {
32     // Create the problem to be solved.
33
// --------------------------------
34
gridconfig.setSessionName("JGAP_fitness_distributed");
35     Configuration jgapconfig = new DefaultConfiguration();
36     jgapconfig.setEventManager(new EventManager());
37     jgapconfig.setPopulationSize(10);
38     jgapconfig.setKeepPopulationSizeConstant(true);
39     jgapconfig.setFitnessFunction(new SampleFitnessFunction());
40     IChromosome sample = new Chromosome(jgapconfig,
41                                         new BooleanGene(jgapconfig), 16);
42     jgapconfig.setSampleChromosome(sample);
43     // Setup parameters.
44
// -----------------
45
setWorkerReturnStrategy(new MyWorkerReturnStrategy());
46     // No initialization of Genotype on behalf of workers.
47
// ---------------------------------------------------
48
setGenotypeInitializer(null);
49     // Evolution takes place on client only!
50
// -------------------------------------
51
setWorkerEvolveStrategy(null);
52     // Setup the client to produce a work request for each chromosome
53
// to get its fitness value computed by a single worker.
54
// --------------------------------------------------------------
55
setRequestSplitStrategy(new MyRequestSplitStrategy(jgapconfig));
56     setConfiguration(jgapconfig);
57     // Evolution takes place on client.
58
// --------------------------------
59
setClientEvolveStrategy(new ClientEvolveStrategy());
60     // Register client feedback listener.
61
// ----------------------------------
62
setClientFeedback(new MyClientFeedback());
63   }
64
65   public void validate()
66       throws Exception JavaDoc {
67     if (getRequestSplitStrategy() == null) {
68       throw new RuntimeException JavaDoc("Please set the request split strategy first!");
69     }
70     if (getConfiguration() == null) {
71       throw new RuntimeException JavaDoc("Please set the configuration first!");
72     }
73   }
74 }
75
Popular Tags