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.fitnessDistributed;
11:
12: import org.homedns.dade.jcgrid.*;
13: import org.jgap.*;
14: import org.jgap.distr.grid.*;
15:
16: /**
17: * Receives work, computes a solution and returns the solution to the requester.
18: *
19: * @author Klaus Meffert
20: * @since 3.01
21: */
22: public class MyGAWorker extends JGAPWorker {
23: /** String containing the CVS revision. Read out via reflection!*/
24: private final static String CVS_REVISION = "$Revision: 1.4 $";
25:
26: /**
27: * Executes the evolution and returns the result.
28: *
29: * @param work WorkRequest
30: * @param workDir String
31: * @return WorkResult
32: * @throws Exception
33: *
34: * @author Klaus Meffert
35: * @since 3.01
36: */
37: public WorkResult doWork(WorkRequest work, String workDir)
38: throws Exception {
39: // Here we could use our own class descended from JGAPRequest
40: // MyRequest req = ( (MyRequest) work);
41: // For the result we could also use an individual class such as MyResult
42: // It would be also possible to do different computations than in
43: // super.doWork(...)
44: // MyResult res = (MyResult)super.doWork(work, workDir);
45:
46: // Doing the evolution as always just means:
47: // return super.doWork(work, workDir);
48:
49: // But we want to only calculate the fitness value of the chromosomes
50: // passed. In our case this is only one chromosome.
51: // ------------------------------------------------------------------
52: JGAPRequest req = ((JGAPRequest) work);
53: IChromosome chrom = req.getPopulation().getChromosome(0);
54: // Do the actual fitness computation here.
55: // ---------------------------------------
56: chrom.getFitnessValue();
57: Population pop = new Population(req.getConfiguration(), chrom);
58: MyResult result = new MyResult(req.getSessionName(), req
59: .getRID(), pop, 1);
60: return result;
61: }
62:
63: }
|