/** * @param aChromosome * @return double adjusted fitness for aChromosome relative to this specie * @throws IllegalArgumentException if chromosome is not a member if this specie */ public double getChromosomeFitnessValue(Chromosome aChromosome) { if (aChromosome.getFitnessValue() < 0) throw new IllegalArgumentException( "chromosome's fitness has not been set: " + aChromosome.toString()); if (chromosomes.contains(aChromosome) == false) throw new IllegalArgumentException( "chromosome not a member of this specie: " + aChromosome.toString()); return ((double) aChromosome.getFitnessValue()) / chromosomes.size(); }
/** * @return average raw fitness (i.e., not adjusted for specie size) of all chromosomes in specie */ public double getFitnessValue() { long totalRawFitness = 0; Iterator iter = chromosomes.iterator(); while (iter.hasNext()) { Chromosome aChromosome = (Chromosome) iter.next(); if (aChromosome.getFitnessValue() < 0) throw new IllegalStateException( "chromosome's fitness has not been set: " + aChromosome.toString()); totalRawFitness += aChromosome.getFitnessValue(); } return (double) totalRawFitness / chromosomes.size(); }