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.impl.IntegerGene;
14: import examples.super gene.*;
15:
16: /**
17: * Fitness function for test implementations without using supergenes.
18: *
19: * @author Neil Rotstan
20: * @author Klaus Meffert
21: * @author Audrius Meskauskas
22: */
23: class WithoutSupergeneChangeFitFForTesting extends
24: SupergeneChangeFitnessFunction {
25: /** String containing the CVS revision. Read out via reflection!*/
26: private final static String CVS_REVISION = "$Revision: 1.1 $";
27:
28: public WithoutSupergeneChangeFitFForTesting(int a_targetAmount) {
29: super (a_targetAmount);
30: }
31:
32: public Gene getResponsibleGene(IChromosome a_chromosome, int a_code) {
33: return a_chromosome.getGene(a_code);
34: }
35:
36: /**
37: * Additionall check that the number of nickels and pennies should
38: * be both even or odd.
39: */
40: public double evaluate(IChromosome a_subject) {
41: IntegerGene nickels = (IntegerGene) a_subject
42: .getGene(SupergeneSample.NICKELS);
43: IntegerGene pennies = (IntegerGene) a_subject
44: .getGene(SupergeneSample.PENNIES);
45: boolean valid = nickels.intValue() % 2 == pennies.intValue() % 2;
46: // valid = true; // uncomment for testing without the condition above
47: double r;
48: if (!valid) {
49: r = 0;
50: } else {
51: r = super.evaluate(a_subject);
52: }
53: return r;
54: }
55: }
|