return result;
}
@Override
public void save(OutputStream os, Object obj) {
EncogWriteHelper out = new EncogWriteHelper(os);
NEATPopulation pop = (NEATPopulation) obj;
out.addSection("NEAT-POPULATION");
out.addSubSection("CONFIG");
out.writeProperty(PersistConst.SNAPSHOT, pop.isSnapshot());
out.writeProperty(NEATPopulation.PROPERTY_OUTPUT_ACTIVATION, pop.getOutputActivationFunction());
out.writeProperty(NEATPopulation.PROPERTY_NEAT_ACTIVATION, pop.getNeatActivationFunction());
out.writeProperty(PersistConst.INPUT_COUNT, pop.getInputCount());
out.writeProperty(PersistConst.OUTPUT_COUNT, pop.getOutputCount());
out.writeProperty(NEATPopulation.PROPERTY_OLD_AGE_PENALTY,
pop.getOldAgePenalty());
out.writeProperty(NEATPopulation.PROPERTY_OLD_AGE_THRESHOLD,
pop.getOldAgeThreshold());
out.writeProperty(NEATPopulation.PROPERTY_POPULATION_SIZE,
pop.getPopulationSize());
out.writeProperty(NEATPopulation.PROPERTY_SURVIVAL_RATE,
pop.getSurvivalRate());
out.writeProperty(NEATPopulation.PROPERTY_YOUNG_AGE_THRESHOLD,
pop.getYoungBonusAgeThreshold());
out.writeProperty(NEATPopulation.PROPERTY_YOUNG_AGE_BONUS,
pop.getYoungScoreBonus());
out.writeProperty(NEATPopulation.PROPERTY_NEXT_GENOME_ID, pop
.getGenomeIDGenerate().getCurrentID());
out.writeProperty(NEATPopulation.PROPERTY_NEXT_INNOVATION_ID, pop
.getInnovationIDGenerate().getCurrentID());
out.writeProperty(NEATPopulation.PROPERTY_NEXT_GENE_ID, pop
.getGeneIDGenerate().getCurrentID());
out.writeProperty(NEATPopulation.PROPERTY_NEXT_SPECIES_ID, pop
.getSpeciesIDGenerate().getCurrentID());
out.addSubSection("INNOVATIONS");
if (pop.getInnovations() != null) {
for (Innovation innovation : pop.getInnovations().getInnovations()) {
NEATInnovation neatInnovation = (NEATInnovation) innovation;
out.addColumn(neatInnovation.getInnovationID());
out.addColumn(PersistNEATPopulation
.innovationTypeToString(neatInnovation
.getInnovationType()));
out.addColumn(PersistNEATPopulation
.neuronTypeToString(neatInnovation.getNeuronType()));
out.addColumn(neatInnovation.getSplitX());
out.addColumn(neatInnovation.getSplitY());
out.addColumn(neatInnovation.getNeuronID());
out.addColumn(neatInnovation.getFromNeuronID());
out.addColumn(neatInnovation.getToNeuronID());
out.writeLine();
}
}
out.addSubSection("GENOMES");
for (Genome genome : pop.getGenomes()) {
NEATGenome neatGenome = (NEATGenome) genome;
out.addColumn("g");
out.addColumn(neatGenome.getGenomeID());
out.addColumn(neatGenome.getSpeciesID());
out.addColumn(neatGenome.getAdjustedScore());
out.addColumn(neatGenome.getAmountToSpawn());
out.addColumn(neatGenome.getNetworkDepth());
out.addColumn(neatGenome.getScore());
out.writeLine();
for (Gene neuronGene : neatGenome.getNeurons().getGenes()) {
NEATNeuronGene neatNeuronGene = (NEATNeuronGene) neuronGene;
out.addColumn("n");
out.addColumn(neatNeuronGene.getId());
out.addColumn(PersistNEATPopulation
.neuronTypeToString(neatNeuronGene.getNeuronType()));
out.addColumn(neatNeuronGene.isEnabled());
out.addColumn(neatNeuronGene.getInnovationId());
out.addColumn(neatNeuronGene.getActivationResponse());
out.addColumn(neatNeuronGene.getSplitX());
out.addColumn(neatNeuronGene.getSplitY());
out.writeLine();
}
for (Gene linkGene : neatGenome.getLinks().getGenes()) {
NEATLinkGene neatLinkGene = (NEATLinkGene) linkGene;
out.addColumn("l");
out.addColumn(neatLinkGene.getId());
out.addColumn(neatLinkGene.isEnabled());
out.addColumn(neatLinkGene.isRecurrent());
out.addColumn(neatLinkGene.getFromNeuronID());
out.addColumn(neatLinkGene.getToNeuronID());
out.addColumn(neatLinkGene.getWeight());
out.addColumn(neatLinkGene.getInnovationId());
out.writeLine();
}
}
out.addSubSection("SPECIES");
for (Species species : pop.getSpecies()) {
out.addColumn(species.getSpeciesID());
out.addColumn(species.getAge());
out.addColumn(species.getBestScore());
out.addColumn(species.getGensNoImprovement());
out.addColumn(species.getNumToSpawn());
out.addColumn(species.getSpawnsRequired());
out.addColumn(species.getLeader().getGenomeID());
out.writeLine();
}
out.flush();
}