KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > examples > supergene > SupergeneChangeFitnessFunction


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.supergenes.*;
14
15 /**
16  *
17  * Fitness function for a version where Supergene is used.
18  *
19  * @author Neil Rotstan
20  * @author Klaus Meffert
21  * @author Audrius Meskauskas (subsequent adaptation)
22  * @since 2.0
23  */

24 public class SupergeneChangeFitnessFunction
25     extends AbstractChangeFitnessFunction {
26   /** String containing the CVS revision. Read out via reflection!*/
27   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
28
29   public SupergeneChangeFitnessFunction(int a_targetAmount) {
30     super(a_targetAmount);
31   }
32
33   /**
34    * Dimes and nickels are taken from the chromosome, and
35    * quarters and pennies are taken from the supergene (gene number 2).
36    */

37   public Gene getResponsibleGene(IChromosome a_chromosome, int a_code) {
38     switch (a_code) {
39       case SupergeneSample.DIMES:
40       case SupergeneSample.QUARTERS:
41         return a_chromosome.getGene(a_code);
42       case SupergeneSample.NICKELS:
43         Supergene s = (Supergene) a_chromosome.getGene(2);
44         return s.geneAt(0);
45       case SupergeneSample.PENNIES:
46         s = (Supergene) a_chromosome.getGene(2);
47         return s.geneAt(1);
48       default:
49         throw new Error JavaDoc("Invalid coind code " + a_code);
50     }
51   }
52 }
53
Popular Tags