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 examples.grid.mathProblemDistributed;
11:
12: import org.jgap.*;
13: import org.jgap.gp.*;
14: import org.jgap.gp.impl.*;
15: import org.jgap.distr.grid.*;
16: import org.jgap.distr.grid.gp.*;
17: import org.apache.log4j.*;
18:
19: /**
20: * Return the top 10 results to the client.
21: *
22: * @author Klaus Meffert
23: * @since 3.2
24: */
25: public class MyWorkerReturnStrategy implements IWorkerReturnStrategyGP {
26: /** String containing the CVS revision. Read out via reflection!*/
27: private final static String CVS_REVISION = "$Revision: 1.4 $";
28:
29: private static Logger log = Logger
30: .getLogger(MyWorkerReturnStrategy.class);
31:
32: /**
33: * Determines the top 10 chromosomes and returns them.
34: *
35: * @param a_req JGAPRequest
36: * @param a_genotype Genotype
37: * @return JGAPResult
38: * @throws Exception in case of any error
39: *
40: * @author Klaus Meffert
41: * @since 3.2
42: */
43: public JGAPResultGP assembleResult(JGAPRequestGP a_req,
44: GPGenotype a_genotype) throws Exception {
45: IGPProgram best;
46: GPPopulation pop = a_genotype.getGPPopulation();
47: if (pop == null) {
48: log.fatal("Population was null!");
49: best = null;
50: } else {
51: log.debug("Assembling result from population with size "
52: + pop.size());
53: best = pop.determineFittestProgram();
54: if (best == null) {
55: log.error("Could not determine the best program!");
56: }
57: }
58: JGAPResultGP result = new JGAPResultGP(a_req.getSessionName(),
59: a_req.getRID(), best, 1);
60: return result;
61: }
62: }
|