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.chromInit;
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 Neil Rotstan
19: * @author Klaus Meffert
20: * @since 2.4
21: */
22: public class MaxFunction extends FitnessFunction {
23: /** String containing the CVS revision. Read out via reflection!*/
24: private final static String CVS_REVISION = "$Revision: 1.3 $";
25:
26: /**
27: * See examples.simpleBoolean.MaxFunction for description.
28: * Please notice that in this example here, we have chromosomes with one and
29: * Chromosomes with two Genes, so that the description from the original
30: * MaxFunction does not apply directly here.
31: * @param a_subject the Chromosome to be evaluated
32: * @return defect rate of our problem
33: *
34: * @author Klaus Meffert
35: * @since 2.4
36: */
37: public double evaluate(IChromosome a_subject) {
38: int total = 0;
39:
40: for (int i = 0; i < a_subject.size(); i++) {
41: BooleanGene value = (BooleanGene) a_subject
42: .getGene(a_subject.size() - (i + 1));
43: if (value.booleanValue()) {
44: total += Math.pow(2.0, (double) i);
45: }
46: }
47:
48: return total;
49: }
50: }
|