result.setInnovations(innovationList);
EncogReadHelper in = new EncogReadHelper(is);
Map<Integer, Species> speciesMap = new HashMap<Integer, Species>();
Map<Species, Integer> leaderMap = new HashMap<Species, Integer>();
Map<Integer, Genome> genomeMap = new HashMap<Integer, Genome>();
EncogFileSection section;
while ((section = in.readNextSection()) != null) {
if (section.getSectionName().equals("NEAT-POPULATION")
&& section.getSubSectionName().equals("INNOVATIONS")) {
for (String line : section.getLines()) {
List<String> cols = EncogFileSection.splitColumns(line);
NEATInnovation innovation = new NEATInnovation();
innovation.setInnovationID(Integer.parseInt(cols.get(0)));
innovation.setInnovationType(PersistNEATPopulation
.stringToInnovationType(cols.get(1)));
innovation.setNeuronType(PersistNEATPopulation.stringToNeuronType(cols.get(2)));
innovation.setSplitX(CSVFormat.EG_FORMAT.parse(cols.get(3)));
innovation.setSplitY(CSVFormat.EG_FORMAT.parse(cols.get(4)));
innovation.setNeuronID(Integer.parseInt(cols.get(5)));
innovation.setFromNeuronID(Integer.parseInt(cols.get(6)));
innovation.setToNeuronID(Integer.parseInt(cols.get(7)));
result.getInnovations().add(innovation);
}
} else if (section.getSectionName().equals("NEAT-POPULATION")
&& section.getSubSectionName().equals("SPECIES")) {
for (String line : section.getLines()) {
String[] cols = line.split(",");
BasicSpecies species = new BasicSpecies();
species.setSpeciesID(Integer.parseInt(cols[0]));
species.setAge(Integer.parseInt(cols[1]));
species.setBestScore(CSVFormat.EG_FORMAT.parse(cols[2]));
species.setGensNoImprovement(Integer.parseInt(cols[3]));
species.setSpawnsRequired(CSVFormat.EG_FORMAT
.parse(cols[4]));
species.setSpawnsRequired(CSVFormat.EG_FORMAT
.parse(cols[5]));
leaderMap.put(species, Integer.parseInt(cols[6]));
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,