KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > supergene > NickelsPenniesSupergene


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.supergene;
11
12 import org.jgap.*;
13 import org.jgap.impl.*;
14 import org.jgap.supergenes.*;
15
16 /**
17  * Supergene to hold pennies and nickels. Valid if the number of
18  * nickels and pennies is either both odd or both even.
19  *
20  * @author Audrius Meskauskas
21  * @since 2.0
22  */

23 public class NickelsPenniesSupergene
24     extends AbstractSupergene {
25   /** String containing the CVS revision. Read out via reflection!*/
26   private final static String JavaDoc CVS_REVISION = "$Revision: 1.2 $";
27
28   /**
29    * Default constructor for dynamic instantiation
30    *
31    * @throws InvalidConfigurationException
32    *
33    * @author Klaus Meffert
34    * @since 3.0
35    */

36   public NickelsPenniesSupergene()
37       throws InvalidConfigurationException {
38     super();
39   }
40
41   public NickelsPenniesSupergene(final Configuration a_conf)
42       throws InvalidConfigurationException {
43     super(a_conf);
44   }
45
46   public NickelsPenniesSupergene(final Configuration a_conf, Gene[] a_genes)
47       throws InvalidConfigurationException {
48     super(a_conf, a_genes);
49   }
50
51   public boolean isValid(Gene[] a_genes, Supergene a_supergene) {
52     IntegerGene nickels = (IntegerGene) a_genes[0];
53     IntegerGene pennies = (IntegerGene) a_genes[1];
54     boolean valid = nickels.intValue() % 2 == pennies.intValue() % 2;
55     return valid;
56   }
57 }
58
Popular Tags