KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > grid > evolutionDistributed > 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.evolutionDistributed;
11
12 import java.util.*;
13 import org.jgap.*;
14 import org.jgap.distr.grid.*;
15
16 /**
17  * Return the top 10 results to the client.
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.2 $";
26
27   /**
28    * Determines the top 10 chromosomes and returns them.
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     List top = a_genotype.getPopulation().determineFittestChromosomes(10);
41     Population pop = new Population(a_req.getConfiguration());
42     for (int i = 0; i < top.size(); i++) {
43       pop.addChromosome( (IChromosome) top.get(i));
44     }
45     JGAPResult result = new JGAPResult(a_req.getSessionName(), a_req.getRID(),
46                                        pop, 1);
47     return result;
48   }
49 }
50
Popular Tags