KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > grid > SampleSplitStrategy


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 org.jgap.distr.grid;
11
12 import org.jgap.event.*;
13 import org.jgap.*;
14 import org.jgap.impl.*;
15
16 /**
17  * Sample implementation of IRequestSplitStrategy. Here, a request is
18  * transformed into 20 single requests, each to be computed by a worker.
19  *
20  * @author Klaus Meffert
21  * @since 3.2
22  */

23 public class SampleSplitStrategy
24     implements IRequestSplitStrategy {
25   /** String containing the CVS revision. Read out via reflection!*/
26   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
27
28   private Configuration m_config;
29
30   public SampleSplitStrategy(Configuration a_config) {
31     m_config = a_config;
32   }
33
34   public Configuration getConfiguration() {
35     return m_config;
36   }
37
38   /**
39    * Creates 20 single requests out of one. The single requests are each
40    * processed by one worker at a time.
41    *
42    * @param a_request the request to split
43    * @return single requests to be computed by workers
44    * @throws Exception
45    *
46    * @author Klaus Meffert
47    * @since 3.2
48    */

49   public JGAPRequest[] split(JGAPRequest a_request)
50       throws Exception JavaDoc {
51     final int runs = 20;
52     JGAPRequest[] result = new JGAPRequest[runs];
53     for (int i = 0; i < runs; i++) {
54       // Setup JGAP configuration for worker.
55
// ------------------------------------
56
Configuration config = getConfiguration().newInstance(i + "",
57           "config " + i);
58 // Configuration config = new DefaultConfiguration(i+"","chromosome " + i);
59
// config.setEventManager(new EventManager());
60
// config.setPopulationSize(1);
61
// config.setFitnessFunction(getConfiguration().getFitnessFunction());
62
// IChromosome sample = (IChromosome) getConfiguration().getSampleChromosome().
63
// clone();
64
// config.setSampleChromosome(sample);
65
result[i] = (JGAPRequest) a_request.newInstance("JGAP-Grid Request " + i,
66           i);
67     }
68     return result;
69   }
70 }
71
Popular Tags