1 10 package examples.simpleBooleanThreaded; 11 12 import org.jgap.*; 13 import org.jgap.impl.*; 14 15 21 public class MaxFunction 22 extends FitnessFunction { 23 24 private final static String CVS_REVISION = "$Revision: 1.1 $"; 25 26 36 public double evaluate(IChromosome a_subject) { 37 int total = 0; 38 39 for (int i = 0; i < a_subject.size(); i++) { 40 BooleanGene value = (BooleanGene) a_subject.getGene(a_subject.size() - 41 (i + 1)); 42 if (value.booleanValue()) { 43 if (i % 3 == 0) { 44 total += Math.pow(1.3, (double) i); 45 } 46 else if (i % 3 == 1) { 47 total -= Math.pow(1.7, (double) i); 48 } 49 else { 50 total += Math.pow(1.9, (double) i); 51 } 52 } 53 if (total < 0) { 54 total = 0; 55 } 56 } 57 58 return total; 59 } 60 } 61 | Popular Tags |