1 10 package examples.distinctGenes; 11 12 import org.jgap.*; 13 import org.jgap.impl.*; 14 15 24 public class SampleFitnessFunction 25 extends FitnessFunction { 26 27 private final static String CVS_REVISION = "$Revision: 1.2 $"; 28 29 37 public double evaluate(IChromosome a_subject) { 38 int total = 0; 39 for (int i = 0; i < a_subject.size() - 1; i++) { 41 CompositeGene gene = (CompositeGene) a_subject.getGene(i); 42 for (int j = 0; j < 4; j++) { 43 BooleanGene field = (BooleanGene) gene.geneAt(j); 47 if (field.booleanValue() == true) { 48 total++; 50 } 51 } 52 } 53 CompositeGene gene = (CompositeGene) a_subject.getGene(a_subject.size() - 1); 56 for (int j = 0; j < 3; j++) { 57 BooleanGene field = (BooleanGene) gene.geneAt(j); 58 if (field.booleanValue() == false) { 59 total++; 61 } 62 } 63 return total; 64 } 65 } 66 | Popular Tags |