final EncogReadHelper in = new EncogReadHelper(is);
EncogFileSection section;
int count = 0;
Species lastSpecies = null;
while ((section = in.readNextSection()) != null) {
if (section.getSectionName().equals("BASIC")
&& section.getSubSectionName().equals("PARAMS")) {
final Map<String, String> params = section.parseParams();
result.getProperties().putAll(params);
} else if (section.getSectionName().equals("BASIC")
&& section.getSubSectionName().equals("EPL-POPULATION")) {
for (final String line : section.getLines()) {
final List<String> cols = EncogFileSection
.splitColumns(line);
if (cols.get(0).equalsIgnoreCase("s")) {
lastSpecies = new BasicSpecies();
lastSpecies.setAge(Integer.parseInt(cols.get(1)));
lastSpecies.setBestScore(CSVFormat.EG_FORMAT.parse(cols
.get(2)));
lastSpecies.setPopulation(result);
lastSpecies.setGensNoImprovement(Integer.parseInt(cols
.get(3)));
result.getSpecies().add(lastSpecies);
} else if (cols.get(0).equalsIgnoreCase("p")) {
double score = 0;
double adjustedScore = 0;
if (cols.get(1).equalsIgnoreCase("nan")
|| cols.get(2).equalsIgnoreCase("nan")) {
score = Double.NaN;
adjustedScore = Double.NaN;
} else {
score = CSVFormat.EG_FORMAT.parse(cols.get(1));
adjustedScore = CSVFormat.EG_FORMAT.parse(cols
.get(2));
}
final String code = cols.get(3);
final EncogProgram prg = new EncogProgram(context);
prg.compileEPL(code);
prg.setScore(score);
prg.setSpecies(lastSpecies);
prg.setAdjustedScore(adjustedScore);
if (lastSpecies == null) {
throw new EncogError(
"Have not defined a species yet");
} else {
lastSpecies.add(prg);
}
count++;
}
}
} else if (section.getSectionName().equals("BASIC")
&& section.getSubSectionName().equals("EPL-OPCODES")) {
for (final String line : section.getLines()) {
final List<String> cols = EncogFileSection
.splitColumns(line);
final String name = cols.get(0);
final int args = Integer.parseInt(cols.get(1));
result.getContext().getFunctions().addExtension(name, args);
}
} else if (section.getSectionName().equals("BASIC")
&& section.getSubSectionName().equals("EPL-SYMBOLIC")) {
boolean first = true;
for (final String line : section.getLines()) {
if (!first) {
final List<String> cols = EncogFileSection
.splitColumns(line);
final String name = cols.get(0);
final String t = cols.get(1);
ValueType vt = null;
if (t.equalsIgnoreCase("f")) {
vt = ValueType.floatingType;
} else if (t.equalsIgnoreCase("b")) {
vt = ValueType.booleanType;
} else if (t.equalsIgnoreCase("i")) {
vt = ValueType.intType;
} else if (t.equalsIgnoreCase("s")) {
vt = ValueType.stringType;
} else if (t.equalsIgnoreCase("e")) {
vt = ValueType.enumType;
}
final int enumType = Integer.parseInt(cols.get(2));
final int enumCount = Integer.parseInt(cols.get(3));
final VariableMapping mapping = new VariableMapping(
name, vt, enumType, enumCount);
if (mapping.getName().length() > 0) {
result.getContext().defineVariable(mapping);
} else {
result.getContext().setResult(mapping);
}
} else {
first = false;
}
}
}
}
result.setPopulationSize(count);
// set the best genome, should be the first genome in the first species
if (result.getSpecies().size() > 0) {
final Species species = result.getSpecies().get(0);
if (species.getMembers().size() > 0) {
result.setBestGenome(species.getMembers().get(0));
}
// set the leaders
for (final Species sp : result.getSpecies()) {
if (sp.getMembers().size() > 0) {