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.config;
11:
12: import org.jgap.*;
13:
14: /**
15: * Sample Fitness function for the MaximizingFunction problem.
16: */
17: public class MaximizingFunctionFitnessFunction extends FitnessFunction {
18: /** String containing the CVS revision. Read out via reflection!*/
19: private final static String CVS_REVISION = "$Revision: 1.4 $";
20:
21: /**
22: * Determine the fitness of the given Chromosome instance. The higher the
23: * return value, the more fit the instance. This method should always
24: * return the same fitness value for two equivalent Chromosome instances.
25: * @author Siddhartha Azad.
26: * @param a_chromosome the Chromosome instance to evaluate
27: * @return a positive integer reflecting the fitness rating of the given
28: * Chromosome
29: */
30: public double evaluate(IChromosome a_chromosome) {
31: int numGenes = a_chromosome.size();
32: if (numGenes != 3) {
33: throw new IllegalArgumentException("Chromosome for "
34: + "MaximizingFunction must have "
35: + "exactly 3 genes.");
36: }
37: Integer aVal = (Integer) a_chromosome.getGene(0).getAllele();
38: Integer bVal = (Integer) a_chromosome.getGene(1).getAllele();
39: Integer cVal = (Integer) a_chromosome.getGene(2).getAllele();
40: return (aVal.intValue() - bVal.intValue() + cVal.intValue());
41: }
42: }
|