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 licencing 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.grid.fitnessDistributed;
11:
12: import org.jgap.*;
13: import org.jgap.impl.*;
14:
15: /**
16: * Fitness function for our example.
17: *
18: * @author Klaus Meffert
19: * @since 3.01
20: */
21: public class SampleFitnessFunction extends FitnessFunction {
22: /** String containing the CVS revision. Read out via reflection!*/
23: private final static String CVS_REVISION = "$Revision: 1.2 $";
24:
25: /**
26: * The fitness evaluation routine.
27: *
28: * @param a_subject the Chromosome to be evaluated
29: * @return defect rate of our problem
30: *
31: * @author Klaus Meffert
32: * @since 3.01
33: */
34: public double evaluate(IChromosome a_subject) {
35: int total = 0;
36: for (int i = 0; i < a_subject.size(); i++) {
37: BooleanGene value = (BooleanGene) a_subject
38: .getGene(a_subject.size() - (i + 1));
39: if (value.booleanValue()) {
40: if (i % 3 == 0) {
41: total += Math.pow(2.0, (double) i);
42: } else if (i % 3 == 1) {
43: total -= Math.pow(2.0, (double) i);
44: } else {
45: total += Math.pow(1.1, (double) i);
46: }
47: }
48: }
49: if (total < 0) {
50: total = 0;
51: }
52: return total;
53: }
54: }
|