*/
private void speciateAndCalculateSpawnLevels(final List<Genome> genomes) {
double maxScore = 0;
if (genomes.size() == 0) {
throw new EncogError("Can't speciate, the population is empty.");
}
final List<Species> speciesCollection = this.population.getSpecies();
if (speciesCollection.size() == 0) {
throw new EncogError("Can't speciate, there are no species.1");
}
// calculate compatibility between genomes and species
adjustCompatibilityThreshold();
// assign genomes to species (if any exist)
for (final Genome g : genomes) {
Species currentSpecies = null;
final Genome genome = g;
if (!Double.isNaN(genome.getAdjustedScore())
&& !Double.isInfinite(genome.getAdjustedScore())) {
maxScore = Math.max(genome.getAdjustedScore(), maxScore);
}
for (final Species s : speciesCollection) {
final double compatibility = getCompatibilityScore(genome,
s.getLeader());
if (compatibility <= this.compatibilityThreshold) {
currentSpecies = s;
addSpeciesMember(s, genome);
genome.setSpecies(s);
break;
}
}
// if this genome did not fall into any existing species, create a
// new species
if (currentSpecies == null) {
currentSpecies = new BasicSpecies(this.population, genome);
this.population.getSpecies().add(currentSpecies);
}
}
//
double totalSpeciesScore = 0;
for (final Species species : speciesCollection) {
totalSpeciesScore += species.calculateShare(this.owner
.getScoreFunction().shouldMinimize(), maxScore);
}
if (speciesCollection.size() == 0) {
throw new EncogError("Can't speciate, there are no species.2");
}
if (totalSpeciesScore < Encog.DEFAULT_DOUBLE_EQUAL) {
// This should not happen much, or if it does, only in the
// beginning.
// All species scored zero. So they are all equally bad. Just divide