KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > grid > DefaultGenotypeInitializer


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 org.jgap.distr.grid;
11
12 import org.jgap.*;
13
14 /**
15  * Default implementation of IGenotypeInitializer.
16  *
17  * @author Klaus Meffert
18  * @since 3.2
19  */

20 public class DefaultGenotypeInitializer
21     implements IGenotypeInitializer, Comparable JavaDoc {
22   /** String containing the CVS revision. Read out via reflection!*/
23   private final static String JavaDoc CVS_REVISION = "$Revision: 1.3 $";
24
25   /**
26    * Sets up a Genotype by adding the content of the given Population to it
27    * and initializing the missing Chromosomes of the Genotype randomly.
28    *
29    * @param a_req a JGAPRequest object containing useful information
30    * @param a_initialPop the Population to consider
31    * @return the initialized Genotype
32    * @throws Exception
33    *
34    * @author Klaus Meffert
35    * @since 3.2
36    */

37   public Genotype setupGenotype(JGAPRequest a_req, Population a_initialPop)
38       throws Exception JavaDoc {
39     Genotype gen;
40     Configuration conf = a_req.getConfiguration();
41     if (a_initialPop == null || a_initialPop.size() < 1) {
42       gen = Genotype.randomInitialGenotype(conf);
43     }
44     else {
45       // Initialize genotype with given population.
46
// ------------------------------------------
47
gen = new Genotype(conf, a_initialPop);
48       // Fill up population to get the desired size.
49
// -------------------------------------------
50
int size = conf.getPopulationSize() - a_initialPop.size();
51       gen.fillPopulation(size);
52     }
53     return gen;
54   }
55
56   /**
57    * @param a_other sic
58    * @return as always
59    *
60    * @author Klaus Meffert
61    * @since 3.2
62    */

63   public int compareTo(Object JavaDoc a_other) {
64     if (a_other.getClass().equals(getClass())) {
65       return 0;
66     }
67     else {
68       return getClass().getName().compareTo(a_other.getClass().getName());
69     }
70   }
71 }
72
Popular Tags