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