01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licensing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
10: package examples.supergene;
11:
12: import org.jgap.*;
13: import org.jgap.super genes.*;
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
22: * @since 2.0
23: */
24: public class SupergeneChangeFitnessFunction extends
25: AbstractChangeFitnessFunction {
26: /** String containing the CVS revision. Read out via reflection!*/
27: private final static String CVS_REVISION = "$Revision: 1.2 $";
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("Invalid coind code " + a_code);
50: }
51: }
52: }
|