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 licencing 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 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 implements IRequestSplitStrategy {
24: /** String containing the CVS revision. Read out via reflection!*/
25: private final static String CVS_REVISION = "$Revision: 1.1 $";
26:
27: private Configuration m_config;
28:
29: public SampleSplitStrategy(Configuration a_config) {
30: m_config = a_config;
31: }
32:
33: public Configuration getConfiguration() {
34: return m_config;
35: }
36:
37: /**
38: * Creates 20 single requests out of one. The single requests are each
39: * processed by one worker at a time.
40: *
41: * @param a_request the request to split
42: * @return single requests to be computed by workers
43: * @throws Exception
44: *
45: * @author Klaus Meffert
46: * @since 3.2
47: */
48: public JGAPRequest[] split(JGAPRequest a_request) throws Exception {
49: final int runs = 20;
50: JGAPRequest[] result = new JGAPRequest[runs];
51: for (int i = 0; i < runs; i++) {
52: // Setup JGAP configuration for worker.
53: // ------------------------------------
54: Configuration config = getConfiguration().newInstance(
55: i + "", "config " + i);
56: // Configuration config = new DefaultConfiguration(i+"","chromosome " + i);
57: // config.setEventManager(new EventManager());
58: // config.setPopulationSize(1);
59: // config.setFitnessFunction(getConfiguration().getFitnessFunction());
60: // IChromosome sample = (IChromosome) getConfiguration().getSampleChromosome().
61: // clone();
62: // config.setSampleChromosome(sample);
63: result[i] = (JGAPRequest) a_request.newInstance(
64: "JGAP-Grid Request " + i, i);
65: }
66: return result;
67: }
68: }
|