result.getSpecies().add(species);
speciesMap.put((int) species.getSpeciesID(), species);
}
} else if (section.getSectionName().equals("NEAT-POPULATION")
&& section.getSubSectionName().equals("GENOMES")) {
NEATGenome lastGenome = null;
for (String line : section.getLines()) {
List<String> cols = EncogFileSection.splitColumns(line);
if (cols.get(0).equalsIgnoreCase("g") ) {
lastGenome = new NEATGenome();
lastGenome.setNeuronsChromosome(new Chromosome());
lastGenome.setLinksChromosome(new Chromosome());
lastGenome.getChromosomes().add(
lastGenome.getNeuronsChromosome());
lastGenome.getChromosomes().add(
lastGenome.getLinksChromosome());
lastGenome.setGenomeID(Integer.parseInt(cols.get(1)));
lastGenome.setSpeciesID(Integer.parseInt(cols.get(2)));
lastGenome.setAdjustedScore(CSVFormat.EG_FORMAT
.parse(cols.get(3)));
lastGenome.setAmountToSpawn(CSVFormat.EG_FORMAT
.parse(cols.get(4)));
lastGenome.setNetworkDepth(Integer.parseInt(cols.get(5)));
lastGenome.setScore(CSVFormat.EG_FORMAT.parse(cols.get(6)));
result.add(lastGenome);
genomeMap.put((int) lastGenome.getGenomeID(),
lastGenome);
} else if (cols.get(0).equalsIgnoreCase("n") ) {
NEATNeuronGene neuronGene = new NEATNeuronGene();
neuronGene.setId(Integer.parseInt(cols.get(1)));
neuronGene.setNeuronType(PersistNEATPopulation
.stringToNeuronType(cols.get(2)));
neuronGene.setEnabled(Integer.parseInt(cols.get(3))>0);
neuronGene.setInnovationId(Integer.parseInt(cols.get(4)));
neuronGene.setActivationResponse(CSVFormat.EG_FORMAT
.parse(cols.get(5)));
neuronGene
.setSplitX(CSVFormat.EG_FORMAT.parse(cols.get(6)));
neuronGene
.setSplitY(CSVFormat.EG_FORMAT.parse(cols.get(7)));
lastGenome.getNeurons().add(neuronGene);
} else if (cols.get(0).equalsIgnoreCase("l")) {
NEATLinkGene linkGene = new NEATLinkGene();
linkGene.setId(Integer.parseInt(cols.get(1)));
linkGene.setEnabled(Integer.parseInt(cols.get(2))>0);
linkGene.setRecurrent(Integer.parseInt(cols.get(3))>0);
linkGene.setFromNeuronID(Integer.parseInt(cols.get(4)));
linkGene.setToNeuronID(Integer.parseInt(cols.get(5)));
linkGene.setWeight(CSVFormat.EG_FORMAT.parse(cols.get(6)));
linkGene.setInnovationId(Integer.parseInt(cols.get(7)));
lastGenome.getLinks().add(linkGene);
}
}
} else if (section.getSectionName().equals("NEAT-POPULATION")
&& section.getSubSectionName().equals("CONFIG")) {
Map<String, String> params = section.parseParams();
result.setNeatActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_NEAT_ACTIVATION));
result.setOutputActivationFunction(EncogFileSection.parseActivationFunction(params,NEATPopulation.PROPERTY_OUTPUT_ACTIVATION));
result.setSnapshot(EncogFileSection.parseBoolean(params, PersistConst.SNAPSHOT));
result.setInputCount(EncogFileSection.parseInt(params,
PersistConst.INPUT_COUNT));
result.setOutputCount(EncogFileSection.parseInt(params,
PersistConst.OUTPUT_COUNT));
result.setOldAgePenalty(EncogFileSection.parseDouble(params,
NEATPopulation.PROPERTY_OLD_AGE_PENALTY));
result.setOldAgeThreshold(EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_OLD_AGE_THRESHOLD));
result.setPopulationSize(EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_POPULATION_SIZE));
result.setSurvivalRate(EncogFileSection.parseDouble(params,
NEATPopulation.PROPERTY_SURVIVAL_RATE));
result.setYoungBonusAgeThreshhold(EncogFileSection.parseInt(
params, NEATPopulation.PROPERTY_YOUNG_AGE_THRESHOLD));
result.setYoungScoreBonus(EncogFileSection.parseDouble(params,
NEATPopulation.PROPERTY_YOUNG_AGE_BONUS));
result.getGenomeIDGenerate().setCurrentID(
EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_NEXT_GENOME_ID));
result.getInnovationIDGenerate().setCurrentID(
EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_NEXT_INNOVATION_ID));
result.getGeneIDGenerate().setCurrentID(
EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_NEXT_GENE_ID));
result.getSpeciesIDGenerate().setCurrentID(
EncogFileSection.parseInt(params,
NEATPopulation.PROPERTY_NEXT_SPECIES_ID));
}
}
// now link everything up
// first put all the genomes into correct species
for (Genome genome : result.getGenomes()) {
NEATGenome neatGenome = (NEATGenome) genome;
int speciesId = (int) neatGenome.getSpeciesID();
Species species = speciesMap.get(speciesId);
if (species != null) {
species.getMembers().add(neatGenome);
}
neatGenome.setInputCount(result.getInputCount());
neatGenome.setOutputCount(result.getOutputCount());
}
// set the species leader links
for (Species species : leaderMap.keySet()) {
int leaderID = leaderMap.get(species);