KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > grid > fitnessDistributed > MyWorkerReturnStrategy


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.*;
13 import org.jgap.distr.grid.*;
14
15 /**
16  * Just compute the fitness value in our example, where only fitness value
17  * computation is dirtibuted.
18  *
19  * @author Klaus Meffert
20  * @since 3.2
21  */

22 public class MyWorkerReturnStrategy
23     implements IWorkerReturnStrategy {
24   /** String containing the CVS revision. Read out via reflection!*/
25   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
26
27   /**
28    * Computes fitness of one chromosome and returns it.
29    *
30    * @param a_req JGAPRequest
31    * @param a_genotype Genotype
32    * @return JGAPResult
33    * @throws Exception in case of any error
34    *
35    * @author Klaus Meffert
36    * @since 3.2
37    */

38   public JGAPResult assembleResult(JGAPRequest a_req, Genotype a_genotype)
39       throws Exception JavaDoc {
40     IChromosome chrom = a_req.getPopulation().getChromosome(0);
41     // Do the actual fitness computation here.
42
// ---------------------------------------
43
chrom.getFitnessValue();
44     Population pop = new Population(a_req.getConfiguration(), chrom);
45     MyResult result = new MyResult(a_req.getSessionName(), a_req.getRID(),
46                                    pop, 1);
47     return result;
48   }
49 }
50
Popular Tags