1 10 package examples.config; 11 12 import org.jgap.*; 13 14 17 public class MaximizingFunctionFitnessFunction 18 extends FitnessFunction { 19 20 private final static String CVS_REVISION = "$Revision: 1.4 $"; 21 22 31 public double evaluate(IChromosome a_chromosome) { 32 int numGenes = a_chromosome.size(); 33 if (numGenes != 3) { 34 throw new IllegalArgumentException ("Chromosome for " + 35 "MaximizingFunction must have " 36 + "exactly 3 genes."); 37 } 38 Integer aVal = (Integer ) a_chromosome.getGene(0).getAllele(); 39 Integer bVal = (Integer ) a_chromosome.getGene(1).getAllele(); 40 Integer cVal = (Integer ) a_chromosome.getGene(2).getAllele(); 41 return (aVal.intValue() - bVal.intValue() + cVal.intValue()); 42 } 43 } 44 | Popular Tags |